From c4ec7ba30b816abfbe63f2ef023171025c440508 Mon Sep 17 00:00:00 2001
From: John-Paul Robinson <jpr@uab.edu>
Date: Mon, 28 Feb 2022 13:30:09 -0600
Subject: [PATCH] Fix improper use of external list name as a unique file tag

Update policy rule with a static (still not existing) external
list rule.
Move the file tagging metadata to the policy apply wrapper script.
---
 policy/list-30day-with-excludes |  3 +--
 run-mmpol.sh                    | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/policy/list-30day-with-excludes b/policy/list-30day-with-excludes
index ac3cb5b..670752f 100644
--- a/policy/list-30day-with-excludes
+++ b/policy/list-30day-with-excludes
@@ -8,8 +8,7 @@ define(access_age,
   (DAYS(CURRENT_TIMESTAMP) - DAYS(ACCESS_TIME))
 )
 
-/* note: subtitution via -M for file tag */
-RULE 'old_files' LIST 'FILETAG'
+RULE 'old_files' LIST 'no_extern_list'
   SHOW ('|size='   || varchar(FILE_SIZE) ||
         '|kballoc='|| varchar(KB_ALLOCATED) || 
         '|access=' || varchar(ACCESS_TIME) ||
diff --git a/run-mmpol.sh b/run-mmpol.sh
index e45ba47..81df451 100755
--- a/run-mmpol.sh
+++ b/run-mmpol.sh
@@ -14,13 +14,13 @@ cores="${SLURM_CPUS_PER_TASK}"
 
 DATESTR=`date +'%Y-%m-%d-%H:%M:%S'`
 
-filetag=$policyfile_$DATESTR
+policy=`basename $policyfile`
+filetag="${policy}_slurm-${SLURM_JOBID}_${DATESTR}"
 
 cmd="mmapplypolicy scratch -I prepare \
   -P $policyfile \
   -g $tmpglobal \
   -s $tmpscratch \
-  -M "FILETAG=$filetag"
   -N ${nodes} -n ${cores}"
 
 # report final command in job log
@@ -28,3 +28,15 @@ echo $cmd
 
 # run policy command
 $cmd
+
+rcode=$?
+
+if [ $rcode -ne 0 ]
+then
+  echo error: mmapplypoicy failed: code $rcode
+  exit $rcode
+fi
+
+# tag output file with run metadata
+outfile=`ls -t $tmpglobal | head -1`
+mv -n $tmpglobal/$outfile $tmpglobal/$outfile_$filetag
-- 
GitLab