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 667A31FA13 for ; Fri, 16 Apr 2021 23:10:36 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/9] test_common: handle '-C' (chdir) spawn option properly Date: Fri, 16 Apr 2021 16:10:31 -0700 Message-Id: <20210416231035.31807-6-e@80x24.org> In-Reply-To: <20210416231035.31807-1-e@80x24.org> References: <20210416231035.31807-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We use it in t/lei-q-save.t, and were inadvertently writing to the worktree. --- lib/PublicInbox/TestCommon.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index d506e4b5..465d4b9d 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -288,6 +288,7 @@ sub run_script ($;$$) { } if ($run_mode == 0) { # spawn an independent new process, like real-world use cases: + $spawn_opt->{$_} = $opt->{$_} for (qw(-C)); require PublicInbox::Spawn; my $cmd = [ key2script($key), @argv ]; my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt); @@ -302,8 +303,14 @@ sub run_script ($;$$) { local %SIG = %SIG; local $0 = join(' ', @$cmd); my $orig_io = _prepare_redirects($fhref); + my $cwdfh; + if (my $d = $opt->{'-C'}) { + opendir $cwdfh, '.' or die "opendir .: $!"; + chdir $d or die "chdir $d: $!"; + } _run_sub($sub, $key, \@argv); eval { PublicInbox::Inbox::cleanup_task() }; + die "chdir(restore): $!" if $cwdfh && !chdir($cwdfh); _undo_redirects($orig_io); select STDOUT; }