Skip to content

Commit 6becf06

Browse files
committed
tools: use mktemp to create the workspace directory
On some platforms, the TMPDIR environment variable is not set.
1 parent 47207e5 commit 6becf06

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+
if [ -d "$WORKSPACE" ]; then
20+
rm -rf "$WORKSPACE"
21+
fi
22+
}
2223

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

2526
cd "$WORKSPACE"
2627

@@ -40,11 +41,7 @@ rm -rf npm/
4041

4142
echo "Copying new npm"
4243

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

4946
echo ""
5047
echo "All done!"

0 commit comments

Comments
 (0)