user/dev discussion of public-inbox itself
 help / Atom feed
* [PATCH] init: preserve permissions of existing config file
@ 2016-12-12 12:02 Eric Wong
  0 siblings, 0 replies; 1+ messages 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	[flat|threaded] 1+ messages in thread

only message in thread, back to index

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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox