RunCommand: ensure we reset the umask

This commit is contained in:
Cole Helbling 2022-01-31 11:39:16 -08:00
parent 34e4c119f4
commit 8c67e32480

View file

@ -8,6 +8,7 @@ use JSON::MaybeXS;
use File::Basename qw(dirname);
use File::Path qw(make_path);
use IPC::Run3;
use Try::Tiny;
sub isEnabled {
my ($self) = @_;
@ -166,12 +167,14 @@ sub buildFinished {
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog) or die "RunCommandLog not found.";
my $dir = dirname($logPath);
my $oldUmask = umask();
my $f;
try {
# file: 640, dir: 750
umask(0027);
make_path($dir);
open(my $f, '>', $logPath);
open($f, '>', $logPath);
umask($oldUmask);
run3($command, \undef, $f, $f, { return_if_system_error => 1 }) == 1
@ -180,6 +183,12 @@ sub buildFinished {
close($f);
$runlog->completed_with_child_error($?, $!);
1;
} catch {
die "Died while trying to process RunCommand (${\$runlog->uuid}): $_";
} finally {
umask($oldUmask);
};
}
}