From 919f821fb296c324eab74d615338e5d9f72d716c Mon Sep 17 00:00:00 2001
From: Karl-Hermann Wieners <karl-hermann.wieners@mpimet.mpg.de>
Date: Wed, 5 Feb 2025 14:47:23 +0100
Subject: [PATCH] Import: amend restart mode (-r true) to create mkexp date
 file

Needs separation of script and work dirs, moved to common temp dir
---
 importexp | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/importexp b/importexp
index 8b54514..9c632d8 100755
--- a/importexp
+++ b/importexp
@@ -47,10 +47,13 @@ then
     TMPDIR=$PWD
     export TMPDIR
 fi
-$DEBUG || trap 'rm -rf $RUN_FILE $LOG_FILE $WORK_DIR' 0
-RUN_FILE=$(mktemp)
-LOG_FILE=$(mktemp)
-WORK_DIR=$(mktemp -d)
+$DEBUG || trap 'rm -rf $MKTEMP_DIR' 0
+MKTEMP_DIR=$(mktemp -d)
+RUN_FILE=$MKTEMP_DIR/run
+LOG_FILE=$MKTEMP_DIR/log
+WORK_DIR=$MKTEMP_DIR/work
+SCRIPT_DIR=$MKTEMP_DIR/scripts
+mkdir $WORK_DIR $SCRIPT_DIR
 
 for RUN_SCRIPT
 do
@@ -129,11 +132,11 @@ done\
     sed -r '
         s@^(\s*)(cat\s+\$thisscript)@\1: \2@
         2 i\
-cd '$WORK_DIR'
+cd '$SCRIPT_DIR'
         /^\s*#.*start\s+experiment/ i'"$SHOW_HERE_DOCS"'
         s:^(\s*)(set\s+\+x\s*$|(set\s+\+\w+)x):\1\3:
         '"${REMOVE_ERROR_FLAG_SH-}"'
-        s:^(\s*)SCRIPT_DIR=.*$:\1SCRIPT_DIR='$WORK_DIR':
+        s:^(\s*)SCRIPT_DIR=.*$:\1SCRIPT_DIR='$SCRIPT_DIR':
         s:^(\s*)experiments_dir=.*$:\1experiments_dir='$WORK_DIR':
         s:^(\s*)BUILD_DIR=.*$:\1BUILD_DIR='$BUILD_DIR':
         s:^(\s*)EXPDIR=.*$:\1EXPDIR='$WORK_DIR':
@@ -164,10 +167,20 @@ cd '$WORK_DIR'
     if [ "x$RESTART" != x ]
     # Try to mimic restart logic
     then
-        restart="$RESTART"
+        restart=".$RESTART."
         export restart
     fi
 
+    if [ "x$RESTART" = xtrue ]
+    # Also, create date file for mkexp based scripts
+    then
+        eval "$(perl -lne '/^\s*(?:export\s)?\s*(
+            EXPNAME |
+            initial_date
+        )(=.*)$/x and print($1, $2)' $RUN_FILE)"
+        echo "$initial_date" > $SCRIPT_DIR/$EXPNAME.date
+    fi
+
     echo "Running '$RUN_SCRIPT'" >&2
 
     ${COMMAND:-/bin/sh} -x $RUN_FILE > $LOG_FILE 2>&1
-- 
GitLab