about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-23 05:53:02 +0000
committerEric Wong <e@80x24.org>2021-09-23 06:21:38 +0000
commit76f5361d8b8d2bea828ac66dc98a0de24b761b3d (patch)
tree3468cc5dd396b7f36bb5f2867082d60b133feeb9 /lib
parentdb98dfa6869f813220759e42b6de035abe40b10c (diff)
downloadpublic-inbox-76f5361d8b8d2bea828ac66dc98a0de24b761b3d.tar.gz
"Correct" meaning the permissions match that of the parent
xap15 or ei15 directory.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Xapcmd.pm15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index b962fa84..daef896c 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -22,11 +22,16 @@ sub commit_changes ($$$$) {
         $SIG{INT} or die 'BUG: $SIG{INT} not handled';
         my @old_shard;
         my $over_chg;
+        my $mode;
 
         while (my ($old, $newdir) = each %$tmp) {
                 next if $old eq ''; # no invalid paths
-                my @st = stat($old);
-                if (!@st && !defined($opt->{reshard})) {
+                $mode //= do {
+                        my ($dname) = ($old =~ m!(.*/)[^/]+/*\z!);
+                        (stat($dname))[2];
+                };
+                my $have_old = -e $old;
+                if (!$have_old && !defined($opt->{reshard})) {
                         die "failed to stat($old): $!";
                 }
 
@@ -46,13 +51,13 @@ sub commit_changes ($$$$) {
                         next;
                 }
 
-                if (@st) {
-                        chmod($st[2] & 07777, $new) or die "chmod $old: $!\n";
+                chmod($mode & 07777, $new) or die "chmod($new): $!\n";
+                if ($have_old) {
                         rename($old, "$new/old") or
                                         die "rename $old => $new/old: $!\n";
                 }
                 rename($new, $old) or die "rename $new => $old: $!\n";
-                if (@st) {
+                if ($have_old) {
                         my $prev = "$old/old";
                         remove_tree($prev) or
                                 die "failed to remove $prev: $!\n";