From d3bc665b2e3fcf56513a4bdd29da8a51436ae662 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Oriol=20Tint=C3=B3?= <oriol.tinto@lmu.de>
Date: Mon, 9 Oct 2023 16:12:09 +0200
Subject: [PATCH] Add upstream file only if it doesn't exist yet

---
 platforms/common/spack_utils.sh | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/platforms/common/spack_utils.sh b/platforms/common/spack_utils.sh
index fd32c0d..81fe4f0 100644
--- a/platforms/common/spack_utils.sh
+++ b/platforms/common/spack_utils.sh
@@ -14,17 +14,21 @@ function _install_spack() {
 
   if [ ! -z "${SPACK_UPSTREAMS}" ]; then
     UPSTREAMS_CONFIG=${SPACK_ROOT}/etc/spack/upstreams.yaml
-    tmpfile=$(mktemp)
-
-    echo "upstreams:" > $tmpfile
-    i=0
-    for UP in ${SPACK_UPSTREAMS}; do
-      echo "Adding upstream repo to config $UPSTREAMS_CONFIG <= $UP"
-      i=$((i+1))
-      echo "  spack-instance-$i:" >> $tmpfile
-      echo "    install_tree: $UP" >> $tmpfile
-    done
-    mv $tmpfile $UPSTREAMS_CONFIG
+    # If the upstream file already exists, just skip it.
+    if [ ! -f ${UPSTREAMS_CONFIG} ]; then
+      tmpfile=$(mktemp)
+      echo "upstreams:" > $tmpfile
+      i=0
+      for UP in ${SPACK_UPSTREAMS}; do
+        echo "Adding upstream repo to config $UPSTREAMS_CONFIG <= $UP"
+        i=$((i+1))
+        echo "  spack-instance-$i:" >> $tmpfile
+        echo "    install_tree: $UP" >> $tmpfile
+      done
+      mv $tmpfile $UPSTREAMS_CONFIG
+    else
+          echo "upstreams was already present: ${UPSTREAMS_CONFIG}" 
+    fi
   fi
 
   if [ ! -z "${SPACK_EXTERNALS}" ] ; then
-- 
GitLab