Skip to content

Commit a736517

Browse files
committed
Use a distribution-independent mktemp command [EFForg#1504]
GNU and BSD mktemp have slightly different invocations; using a $MKTEMP command everywhere ensures a safe invocation.
1 parent 63fb656 commit a736517

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

locate-gnu-utils.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ if [ -x "$GREADLINK" ]; then
1111
fi
1212
unset GREADLINK
1313

14-
MKTEMP=$(which mktemp 2>/dev/null || true)
15-
GMKTEMP=$(which gmktemp 2>/dev/null || true)
16-
if [ -x "$GMKTEMP" ]; then
17-
MKTEMP="$GMKTEMP"
18-
fi
19-
unset GMKTEMP
20-
2114
check_for_gnu_version() {
2215
gnu_available=$("$1" --version 2>&1 | grep GNU)
2316
if [ ! "$gnu_available" ]; then
@@ -29,5 +22,4 @@ check_for_gnu_version() {
2922
fi
3023
}
3124

32-
check_for_gnu_version "$MKTEMP" "mktemp"
3325
check_for_gnu_version "$READLINK" "readlink"

run-chromium.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
set -o errexit -o xtrace
66

77
cd $(dirname $0)
8-
source locate-gnu-utils.sh
8+
99
source makecrx.sh
10-
PROFILE_DIRECTORY="$("$MKTEMP" -d)"
10+
source utils/mktemp.sh
11+
12+
PROFILE_DIRECTORY="$(mktemp -d)"
1113
trap 'rm -r "$PROFILE_DIRECTORY"' EXIT
1214
chromium-browser \
1315
--user-data-dir="$PROFILE_DIRECTORY" \

test-ruleset-coverage.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#
66

77
cd $(dirname $0)
8-
source locate-gnu-utils.sh
9-
TMP=`"$MKTEMP"`
8+
9+
source utils/mktemp.sh
10+
11+
TMP="$(mktemp)"
1012
trap 'rm "$TMP"' EXIT
1113
if ! [ -d https-everywhere-checker ] ; then
1214
echo "Submodule https-everywhere-checker is missing. Run"

test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ source locate-gnu-utils.sh
66
# We have to change to the right directory because this is sometimes invoked
77
# through a symlink in .git/hooks/pre-push.
88
cd $(dirname $("$READLINK" -f $0))
9+
source utils/mktemp.sh
910

1011
# dummy Jetpack addon that contains tests
1112
TEST_ADDON_PATH=./https-everywhere-tests/
1213

1314
# We'll create a Firefox profile here and install HTTPS Everywhere into it.
14-
PROFILE_DIRECTORY="$("$MKTEMP" -d)"
15+
PROFILE_DIRECTORY="$(mktemp -d)"
1516
trap 'rm -r "$PROFILE_DIRECTORY"' EXIT
1617
HTTPSE_INSTALL_DIRECTORY=$PROFILE_DIRECTORY/extensions/https-everywhere@eff.org
1718

utils/mktemp.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# BSD and GNU mktemp have slightly different invocation patterns.
4+
# BSD's needs a -t option specifying a "template." 'everywhere' will
5+
# end up in the temp-folder name, so in the event it doesn't get cleaned
6+
# up, there's some indication of where it originated.
7+
8+
MKTEMP=`which mktemp`
9+
function mktemp() {
10+
$MKTEMP $@ 2>/dev/null || $MKTEMP -t everywhere $@
11+
}

0 commit comments

Comments
 (0)