RunCommand: use helper functions to ensure filenames and paths are the same
Otherwise, it's possible someone updates the format in one place but not the others, leading to broken or incorrect functionality.
This commit is contained in:
@ -7,6 +7,8 @@ use experimental 'smartmatch';
|
||||
use JSON::MaybeXS;
|
||||
use Digest::SHA1 qw(sha1_hex);
|
||||
use Hydra::Model::DB;
|
||||
use Hydra::Helper::Nix;
|
||||
use File::Basename qw(dirname);
|
||||
|
||||
sub isEnabled {
|
||||
my ($self) = @_;
|
||||
@ -162,15 +164,15 @@ sub buildFinished {
|
||||
|
||||
$runlog->started();
|
||||
|
||||
# Prepare log collection
|
||||
my $filename = sha1_hex($command) . "-" . $build->get_column('id');
|
||||
my $dir = Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($filename, 0, 2);
|
||||
my $logpath = "$dir/$filename";
|
||||
my $filename = constructRunCommandLogFilename(sha1_hex($command), $build->get_column('id'));
|
||||
my $logPath = constructRunCommandLogPath($filename);
|
||||
my $dir = dirname($logPath);
|
||||
|
||||
mkdir($dir, oct(755));
|
||||
# This creates the file with the correct permissions
|
||||
open(my $f, '>', $logpath);
|
||||
|
||||
open(my $f, '>', $logPath);
|
||||
close($f);
|
||||
chmod(oct(644), $logpath);
|
||||
chmod(oct(644), $logPath);
|
||||
|
||||
# Run the command
|
||||
system("$command 1>$logpath 2>&1") == 0
|
||||
|
Reference in New Issue
Block a user