Skip to content

Commit

Permalink
tools: use mktemp to create the workspace directory
Browse files Browse the repository at this point in the history
On some platforms, the TMPDIR environment variable is not set.

PR-URL: #38432
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
lpinca authored and targos committed Jun 11, 2021
1 parent a18b1ff commit 7021c31
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tools/update-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -39,11 +40,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!"
Expand Down

0 comments on commit 7021c31

Please sign in to comment.