From 3043725a10eae59a71c25ba5e4d424a49326afd7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 12 Dec 2016 12:02:45 +0000 Subject: init: preserve permissions of existing config file This matches git-config(1) behavior, and implied user intent when it comes to programatically editing files. --- script/public-inbox-init | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'script/public-inbox-init') diff --git a/script/public-inbox-init b/script/public-inbox-init index 739ec9e5..e23d1419 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 $/; -- cgit v1.2.3-24-ge0c7