From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 301181F9F3 for ; Thu, 23 Sep 2021 05:53:04 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] xcpdb: -R$SHARDS creates new shards with correct perms Date: Thu, 23 Sep 2021 05:53:02 +0000 Message-Id: <20210923055303.6409-3-e@80x24.org> In-Reply-To: <20210923055303.6409-1-e@80x24.org> References: <20210923055303.6409-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: "Correct" meaning the permissions match that of the parent xap15 or ei15 directory. --- lib/PublicInbox/Xapcmd.pm | 15 ++++++++++----- t/extsearch.t | 7 +++++++ 2 files changed, 17 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"; diff --git a/t/extsearch.t b/t/extsearch.t index ad4f2c6d..b2b994f6 100644 --- a/t/extsearch.t +++ b/t/extsearch.t @@ -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"; @@ -436,11 +437,17 @@ for my $j (1, 3, 6) { SKIP: { my $d = "$home/extindex-j1"; + 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"); } for my $i (4..5) { is(grep(m!/ei[0-9]+/$i\z!, @dirs), 0, "no shard [$i]");