Skip to content

Commit

Permalink
Merge pull request #37 from greenc-FNAL/bugfix/assorted-fixes
Browse files Browse the repository at this point in the history
[build-spack-env.sh] Error-handling and TMPDIR safety
  • Loading branch information
marcmengel authored Apr 3, 2024
2 parents 66b0676 + 7aecdb2 commit 06627a1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions bin/build-spack-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,19 @@ _maybe_cache_binaries() {
# packages in order to avoid writing packages to build cache that were
# already installed from build cache. Do this in one Spack session to
# avoid unnecessary overhead.
cat > "$TMP/location_cmds.py" <<\EOF
{
cat > "$TMP/location_cmds.py" <<\EOF
import spack.cmd
import spack.environment
env = spack.environment.active_environment()
EOF
} ||
_die "I/O error writing to $TMP/location_cmds.py"
for hash in ${hashes_to_cache_tmp[*]:+"${hashes_to_cache_tmp[@]}"}; do
echo 'print("'"$hash"'", spack.cmd.disambiguate_spec("'"${hash//*\///}"'", env, False).prefix)' >> "$TMP/location_cmds.py"
done
done ||
_die "I/O error writing to $TMP/location_cmds.py"
local hashes_to_cache=(
$(
_cmd $DEBUG_1 $PIPE spack python "$TMP/location_cmds.py" |
Expand Down Expand Up @@ -1139,10 +1143,6 @@ SPACK_ROOT=$SPACK_ROOT
$(spack env status)"
fi

# Temporary working area (and cleanup trap).
TMP=`mktemp -d -t build-spack-env.sh.XXXXXX`
trap "[ -d \"$TMP\" ] && rm -rf \"$TMP\" 2>/dev/null" EXIT

########################################################################
# To split bundled single-option arguments in your function or script:
#
Expand Down Expand Up @@ -1272,6 +1272,10 @@ if [ -z "$TMPDIR" ]; then
fi
####################################

# Temporary working area (and cleanup trap).
TMP="$(mktemp -d -t build-spack-env.sh.XXXXXX)"
trap "[ -d \"$TMP\" ] && rm -rf \"$TMP\" 2>/dev/null" EXIT

# Local cache locations are derived from $working_dir.
local_caches=(
"__local_binaries|binary:$working_dir/copyBack/spack-binary-cache"
Expand Down

0 comments on commit 06627a1

Please sign in to comment.