* [PATCH] init: preserve permissions of existing config file
@ 2016-12-12 12:02 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-12-12 12:02 UTC (permalink / raw)
To: meta
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-12-12 12:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-12 12:02 [PATCH] init: preserve permissions of existing config file Eric Wong
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).