We use it in t/lei-q-save.t, and were inadvertently writing
to the worktree.
v2: fix -C $DIR with TEST_RUN_MODE=0
# spawn an independent new process, like real-world use cases:
require PublicInbox::Spawn;
my $cmd = [ key2script($key), @argv ];
# spawn an independent new process, like real-world use cases:
require PublicInbox::Spawn;
my $cmd = [ key2script($key), @argv ];
+ if (my $d = $opt->{'-C'}) {
+ $cmd->[0] = File::Spec->rel2abs($cmd->[0]);
+ $spawn_opt->{'-C'} = $d;
+ }
my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
if (defined $pid) {
my $r = waitpid($pid, 0) // die "waitpid: $!";
my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
if (defined $pid) {
my $r = waitpid($pid, 0) // die "waitpid: $!";
local %SIG = %SIG;
local $0 = join(' ', @$cmd);
my $orig_io = _prepare_redirects($fhref);
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() };
_run_sub($sub, $key, \@argv);
eval { PublicInbox::Inbox::cleanup_task() };
+ die "chdir(restore): $!" if $cwdfh && !chdir($cwdfh);
_undo_redirects($orig_io);
select STDOUT;
}
_undo_redirects($orig_io);
select STDOUT;
}