From e7e1f0a52a3ad27dfe48c3e09ece652cf5982328 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Tue, 27 Apr 2021 10:52:02 +0200 Subject: [PATCH] tools: use mktemp to create the workspace directory On some platforms, the TMPDIR environment variable is not set. --- tools/update-npm.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tools/update-npm.sh b/tools/update-npm.sh index c106570d0b33dd..6c071d5b428db0 100755 --- a/tools/update-npm.sh +++ b/tools/update-npm.sh @@ -11,16 +11,17 @@ if [ "$#" -le 0 ]; then exit 1 fi -WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/ +echo "Making temporary workspace" -if [ -d "$WORKSPACE" ]; then - echo "Cleaning up old workspace" - rm -rf "$WORKSPACE" -fi +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') -echo "Making temporary workspace" +cleanup () { + EXIT_CODE=$? + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" + exit $EXIT_CODE +} -mkdir -p "$WORKSPACE" +trap cleanup INT TERM EXIT cd "$WORKSPACE" @@ -40,11 +41,7 @@ rm -rf npm/ echo "Copying new npm" -tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz - -echo "Deleting temporary workspace" - -rm -rf "$WORKSPACE" +tar zxf "$WORKSPACE"/cli/release/npm-"$NPM_VERSION".tgz echo "" echo "All done!"