Commit fe8bef7c authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Really cleans-up the temp directory if it has been created by a previous worker

parent 01bc9d89
...@@ -537,21 +537,37 @@ sub worker_temp_directory { ...@@ -537,21 +537,37 @@ sub worker_temp_directory {
my $self = shift @_; my $self = shift @_;
unless(defined($self->{'_tmp_dir'}) and (-e $self->{'_tmp_dir'})) { unless(defined($self->{'_tmp_dir'}) and (-e $self->{'_tmp_dir'})) {
my $username = $ENV{'USER'}; $self->{'_tmp_dir'} = $self->worker_temp_directory_name();
my $worker_id = $self->worker ? $self->worker->dbID : 'standalone';
$self->{'_tmp_dir'} = "/tmp/worker_${username}.${worker_id}/";
mkdir($self->{'_tmp_dir'}, 0777); mkdir($self->{'_tmp_dir'}, 0777);
throw("unable to create a writable directory ".$self->{'_tmp_dir'}) unless(-w $self->{'_tmp_dir'}); throw("unable to create a writable directory ".$self->{'_tmp_dir'}) unless(-w $self->{'_tmp_dir'});
} }
return $self->{'_tmp_dir'}; return $self->{'_tmp_dir'};
} }
sub worker_temp_directory_name {
my $self = shift @_;
my $username = $ENV{'USER'};
my $worker_id = $self->worker ? $self->worker->dbID : 'standalone';
return "/tmp/worker_${username}.${worker_id}/";
}
=head2 cleanup_worker_temp_directory
Title : cleanup_worker_temp_directory
Function: Cleans up the directory on the local /tmp disk that is used for the
worker. It can be used to remove files left there by previous jobs.
Usage : $self->cleanup_worker_temp_directory;
=cut
sub cleanup_worker_temp_directory { sub cleanup_worker_temp_directory {
my $self = shift @_; my $self = shift @_;
if($self->{'_tmp_dir'} and (-e $self->{'_tmp_dir'}) ) { my $tmp_dir = $self->worker_temp_directory_name();
my $cmd = "rm -r ". $self->{'_tmp_dir'}; if(-e $tmp_dir) {
my $cmd = "rm -r $tmp_dir";
system($cmd); system($cmd);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment