RunCommandLogs: identify and access via uuid

Using a sha1 of the command combined with the build ID is not a
particularly good or unique identifier:

* A build could fail, be restarted, and then succeed -- assuming no
configuration changes, the sha1 hash of the command as well as the build
ID will be the same. This would lead to an overwritten log file.

* Allowing user input to influence filenames is not the best of ideas.
This commit is contained in:
Cole Helbling
2022-01-26 10:26:28 -08:00
parent dcb0c1425c
commit fc3cf4ecb2
6 changed files with 10 additions and 47 deletions

View File

@ -175,8 +175,6 @@ __PACKAGE__->belongs_to(
use POSIX qw(WEXITSTATUS WIFEXITED WIFSIGNALED WTERMSIG);
use UUID4::Tiny qw(create_uuid_string);
use Digest::SHA1 qw(sha1_hex);
use Hydra::Model::DB;
=head2 new
@ -366,29 +364,3 @@ sub did_fail_with_exec_error {
}
1;
=head2 log_relative_url
Returns the URL to the log file relative to the build it belongs to.
Return:
* The relative URL if a log file exists
* An empty string otherwise
=cut
sub log_relative_url() {
my ($self) = @_;
# Do not return a URL when there is no build yet
if (not defined($self->start_time)) {
return "";
}
my $sha = sha1_hex($self->command);
# Do not return a URL when there is no log file yet
if (not -f Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($sha, 0, 2) . "/$sha-" . $self->build_id) {
return "";
}
return "runcommand-log/$sha";
}