Skip to content

Commit 111c5b2

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 111c5b2

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

tools/update-npm.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ 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+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
20+
}
2221

23-
mkdir -p "$WORKSPACE"
22+
trap cleanup INT TERM EXIT
2423

2524
cd "$WORKSPACE"
2625

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

4140
echo "Copying new npm"
4241

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

4944
echo ""
5045
echo "All done!"

0 commit comments

Comments
 (0)