Skip to content

Commit

Permalink
Fix persistent runner, dir was being delete
Browse files Browse the repository at this point in the history
  • Loading branch information
exodist committed Jun 21, 2024
1 parent cde5f97 commit eb054f5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/App/Yath.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use App::Yath::ConfigFile;
use Carp qw/croak/;
use Time::HiRes qw/time/;
use Scalar::Util qw/blessed/;
use File::Path qw/remove_tree/;
use File::Spec;
use Term::Table;

Expand Down Expand Up @@ -532,6 +533,13 @@ sub run_command {
die "Command '" . $cmd->name() . "' did not return an exit value.\n"
unless defined $exit;

my $settings = $self->settings;

unless ($settings->harness->keep_dirs) {
remove_tree($settings->harness->workdir, {safe => 1, keep_root => 0});
remove_tree($settings->harness->tmpdir, {safe => 1, keep_root => 0});
}

return $exit;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/App/Yath/Command/start.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ sub become_daemon {
if ($pid) {
sleep 2;
kill('HUP', $pid);
exit(0);
POSIX::_exit(0);
}
}

Expand Down Expand Up @@ -189,6 +189,9 @@ sub become_collector {
remove_tree($settings->harness->workdir, {safe => 1, keep_root => 0})
unless $settings->harness->keep_dirs;

remove_tree($settings->harness->tmpdir, {safe => 1, keep_root => 0})
unless $settings->harness->keep_dirs;

return $exit;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/App/Yath/Options/Harness.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ option_group {group => 'harness', category => 'Harness Options'} => sub {
my $tmpdir = File::Spec->tmpdir;
return $tmpdir if $tmpdir =~ m/yath/ && $ENV{YATH_SHELL};

my $dir = tempdir("yath-$ENV{USER}-$$-XXXXXX", CLEANUP => 1, TMPDIR => 1);
my $dir = tempdir("yath-$ENV{USER}-$$-XXXXXX", CLEANUP => 0, TMPDIR => 1);
return $dir;
},
);
Expand Down
8 changes: 4 additions & 4 deletions lib/Test2/Harness/Util/LogFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;

our $VERSION = '2.000000';

use Carp qw/croak/;
use Carp qw/confess/;

use Test2::Harness::Util::JSON qw/decode_json/;

Expand All @@ -25,10 +25,10 @@ sub init {
$self->{+NAME} //= $client->send_and_get('log_file');
}

my $file = $self->{+NAME} // croak "'name' is a required attribute unless 'client' is specified";
croak "'$file' is not a valid log file" unless -f $file;
my $file = $self->{+NAME} // confess "'name' is a required attribute unless 'client' is specified";
confess "'$file' is not a valid log file" unless -f $file;

open(my $fh, '<', $file) or croak "Could not open log file '$file' for reading: $!";
open(my $fh, '<', $file) or confess "Could not open log file '$file' for reading: $!";
$fh->blocking(0);
$self->{+FH} = $fh;

Expand Down

0 comments on commit eb054f5

Please sign in to comment.