]> Sergey Matveev's repositories - public-inbox.git/commitdiff
xcpdb: -R$SHARDS creates new shards with correct perms
authorEric Wong <e@80x24.org>
Thu, 23 Sep 2021 05:53:02 +0000 (05:53 +0000)
committerEric Wong <e@80x24.org>
Thu, 23 Sep 2021 06:21:38 +0000 (06:21 +0000)
"Correct" meaning the permissions match that of the parent
xap15 or ei15 directory.

lib/PublicInbox/Xapcmd.pm
t/extsearch.t

index b962fa848c8ada9e0b3b029876cce808deb194a5..daef896c37e9a435639505211d7d68e3f74a531f 100644 (file)
@@ -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";
index 6c074022aa134fa4116863655c02413eaf9ee931..ca586f61c29f5ecab581d56a1dc7a1bdb71e51c5 100644 (file)
@@ -423,6 +423,7 @@ if ('dedupe + dry-run') {
                '--dry-run alone fails');
 }
 
+# chmod 0755, $home or xbail "chmod: $!";
 for my $j (1, 3, 6) {
        my $o = { 2 => \(my $err = '') };
        my $d = "$home/extindex-j$j";
@@ -445,11 +446,17 @@ SKIP: {
        ok($es->cleanup_shards, 'cleanup_shards noop');
        is("$es->{xdb}", $xdb_str, '{xdb} unchanged');
 
+       my @ei_dir = glob("$d/ei*/");
+       chmod 0755, $ei_dir[0] or xbail "chmod: $!";
+       my $mode = sprintf('%04o', 07777 & (stat($ei_dir[0]))[2]);
+       is($mode, '0755', 'mode set on ei*/ dir');
        my $o = { 2 => \(my $err = '') };
        ok(run_script([qw(-xcpdb -R4), $d]), 'xcpdb R4');
        my @dirs = glob("$d/ei*/?");
        for my $i (0..3) {
                is(grep(m!/ei[0-9]+/$i\z!, @dirs), 1, "shard [$i] created");
+               my $m = sprintf('%04o', 07777 & (stat($dirs[$i]))[2]);
+               is($m, $mode, "shard [$i] mode");
        }
        is($es->cleanup_shards, undef, 'cleanup_shards cleaned');
        ok(!defined($es->{xdb}), 'old {xdb} gone');