Skip to content

Commit 499da2d

Browse files
lpincatargos
authored andcommitted
tools: use mktemp to create the workspace directory
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]>
1 parent 0e446d6 commit 499da2d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

tools/update-npm.sh

+9-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ if [ "$#" -le 0 ]; then
1111
exit 1
1212
fi
1313

14-
WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/
14+
echo "Making temporary workspace"
1515

16-
if [ -d "$WORKSPACE" ]; then
17-
echo "Cleaning up old workspace"
18-
rm -rf "$WORKSPACE"
19-
fi
16+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
2017

21-
echo "Making temporary workspace"
18+
cleanup () {
19+
EXIT_CODE=$?
20+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
21+
exit $EXIT_CODE
22+
}
2223

23-
mkdir -p "$WORKSPACE"
24+
trap cleanup INT TERM EXIT
2425

2526
cd "$WORKSPACE"
2627

@@ -39,11 +40,7 @@ rm -rf npm/
3940

4041
echo "Copying new npm"
4142

42-
tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz
43-
44-
echo "Deleting temporary workspace"
45-
46-
rm -rf "$WORKSPACE"
43+
tar zxf "$WORKSPACE"/cli/release/npm-"$NPM_VERSION".tgz
4744

4845
echo ""
4946
echo "All done!"

0 commit comments

Comments
 (0)