3235: Merge branch 'master' into 3235-top-nav-site-search
[arvados.git] / sdk / cli / bin / crunch-job
index a4951e7321513eab54e1d37e79bc42697a4e932d..30f06b8cab92bbd17689cd951d64d3f3abf0c148 100755 (executable)
@@ -82,6 +82,7 @@ use IPC::Open2;
 use IO::Select;
 use File::Temp;
 use Fcntl ':flock';
+use File::Path qw( make_path );
 
 $ENV{"TMPDIR"} ||= "/tmp";
 unless (defined $ENV{"CRUNCH_TMP"}) {
@@ -91,6 +92,12 @@ unless (defined $ENV{"CRUNCH_TMP"}) {
     $ENV{"CRUNCH_TMP"} .= "-$<";
   }
 }
+
+# Create the tmp directory if it does not exist
+if ( ! -d $ENV{"CRUNCH_TMP"} ) {
+  make_path $ENV{"CRUNCH_TMP"} or die "Failed to create temporary working directory: " . $ENV{"CRUNCH_TMP"};
+}
+
 $ENV{"JOB_WORK"} = $ENV{"CRUNCH_TMP"} . "/work";
 $ENV{"CRUNCH_INSTALL"} = "$ENV{CRUNCH_TMP}/opt";
 $ENV{"CRUNCH_WORK"} = $ENV{"JOB_WORK"}; # deprecated
@@ -661,15 +668,13 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
           elsif ($env_key eq "TASK_KEEPMOUNT") {
             $command .= "--env=\QTASK_KEEPMOUNT=/keep\E ";
           }
-          elsif ($env_key eq "CRUNCH_SRC") {
-            $command .= "--env=\QCRUNCH_SRC=/tmp/crunch-src\E ";
-          }
           else {
             $command .= "--env=\Q$env_key=$env_val\E ";
           }
         }
       }
       $command .= "--env=\QCRUNCH_NODE_SLOTS=$ENV{CRUNCH_NODE_SLOTS}\E ";
+      $command .= "--env=\QCRUNCH_SRC=/tmp/crunch-src\E ";
       $command .= "\Q$docker_hash\E ";
       $command .= "stdbuf --output=0 --error=0 ";
       $command .= "/tmp/crunch-src/crunch_scripts/" . $Job->{"script"};