Helper/Nix: constructRunCommandLogPath: take RunCommandLog as input
This way we ensure that it actually exists in the database, rather than blindly trusting user-generated input.
This commit is contained in:
parent
61914d56c6
commit
8eab7b8543
|
@ -537,7 +537,8 @@ sub runcommandlog :Local :Args(1) {
|
|||
|
||||
die if defined $tail && $tail !~ /^[0-9]+$/;
|
||||
|
||||
my $logFile = constructRunCommandLogPath($uuid);
|
||||
my $runlog = $c->model('DB')->resultset('RunCommandLogs')->find({ uuid => $uuid });
|
||||
my $logFile = constructRunCommandLogPath($runlog);
|
||||
if (-f $logFile) {
|
||||
serveLogFile($c, $logFile, $tail);
|
||||
return;
|
||||
|
|
|
@ -591,12 +591,13 @@ sub isLocalStore {
|
|||
|
||||
|
||||
sub constructRunCommandLogPath {
|
||||
my ($filename) = @_;
|
||||
my ($runlog) = @_;
|
||||
|
||||
my $uuid = $runlog->uuid;
|
||||
my $hydra_path = Hydra::Model::DB::getHydraPath;
|
||||
my $bucket = substr($filename, 0, 2);
|
||||
my $bucket = substr($uuid, 0, 2);
|
||||
|
||||
return "$hydra_path/runcommand-logs/$bucket/$filename";
|
||||
return "$hydra_path/runcommand-logs/$bucket/$uuid";
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -163,7 +163,7 @@ sub buildFinished {
|
|||
|
||||
$runlog->started();
|
||||
|
||||
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog->uuid);
|
||||
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog);
|
||||
my $dir = dirname($logPath);
|
||||
my $oldUmask = umask();
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ subtest "Validate a run log was created" => sub {
|
|||
is($runlog->exit_code, 0, "This command should have succeeded.");
|
||||
|
||||
subtest "Validate the run log file exists" => sub {
|
||||
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog->uuid);
|
||||
my $logPath = Hydra::Helper::Nix::constructRunCommandLogPath($runlog);
|
||||
ok(-f $logPath, "The run log was saved to a file.");
|
||||
ok(-z $logPath, "The run log was empty.");
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue