From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] init: preserve permissions of existing config file
Date: Mon, 12 Dec 2016 12:02:45 +0000 [thread overview]
Message-ID: <20161212120245.5185-1-e@80x24.org> (raw)
This matches git-config(1) behavior, and implied user
intent when it comes to programatically editing files.
---
script/public-inbox-init | 5 +++++
t/init.t | 10 ++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 739ec9e..e23d141 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -28,6 +28,11 @@ mkpath($dir); # will croak on fatal errors
my ($fh, $filename) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
if (-e $pi_config) {
open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
+ my @st = stat($oh);
+ my $perm = $st[2];
+ defined $perm or die "(f)stat failed on $pi_config: $!\n";
+ chmod($perm & 07777, $fh) or
+ die "(f)chmod failed on future $pi_config: $!\n";
my $old;
{
local $/;
diff --git a/t/init.t b/t/init.t
index b78fbaf..f87dc22 100644
--- a/t/init.t
+++ b/t/init.t
@@ -13,10 +13,16 @@ use constant pi_init => 'blib/script/public-inbox-init';
my $cfgfile = "$ENV{PI_DIR}/config";
my @cmd = (pi_init, 'blist', "$tmpdir/blist",
qw(http://example.com/blist blist@example.com));
- is(system(@cmd), 0, 'public-inbox-init failed');
+ is(system(@cmd), 0, 'public-inbox-init OK');
ok(-e $cfgfile, "config exists, now");
- is(system(@cmd), 0, 'public-inbox-init failed (idempotent)');
+ is(system(@cmd), 0, 'public-inbox-init OK (idempotent)');
+
+ chmod 0666, $cfgfile or die "chmod failed: $!";
+ @cmd = (pi_init, 'clist', "$tmpdir/clist",
+ qw(http://example.com/clist clist@example.com));
+ is(system(@cmd), 0, 'public-inbox-init clist OK');
+ is((stat($cfgfile))[2] & 07777, 0666, "permissions preserved");
}
done_testing();
--
EW
reply other threads:[~2016-12-12 12:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161212120245.5185-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).