File tree Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Expand file tree Collapse file tree 2 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,25 @@ test_tempfile () {
32
32
assertTrue " virtualenvwrapper-hook not in filename." " echo $filename | grep virtualenvwrapper-hook"
33
33
}
34
34
35
+ test_bad_mktemp () {
36
+ # All of the following bogus mktemp programs should cause
37
+ # virtualenvwrapper_tempfile to return non-zero status
38
+ mktemp_nonzero () { return 1; }
39
+ mktemp_empty_string () { return 0; }
40
+ mktemp_missing_executable () { /foo/bar/baz/qux 2> /dev/null; } # returns status 127
41
+ mktemp_missing_result () { echo /foo/bar/baz/qux; }
42
+
43
+ for mktemp_func in mktemp_nonzero mktemp_empty_string \
44
+ mktemp_missing_executable mktemp_missing_result
45
+ do
46
+ mktemp () { $mktemp_func " $@ " ; }
47
+ filename=$( virtualenvwrapper_tempfile hook)
48
+ assertSame " ($mktemp_func ) Unexpected exit code $? " " 1" " $? "
49
+ done
50
+
51
+ unset -f mktemp
52
+ }
53
+
35
54
test_no_such_tmpdir () {
36
55
old_tmpdir=" $TMPDIR "
37
56
export TMPDIR=" $tmplocation /does-not-exist"
Original file line number Diff line number Diff line change @@ -130,8 +130,10 @@ function virtualenvwrapper_verify_workon_home {
130
130
function virtualenvwrapper_tempfile {
131
131
# Note: the 'X's must come last
132
132
typeset suffix=${1:- hook}
133
- typeset file=" ` \m ktemp -t virtualenvwrapper-$suffix -XXXXXXXXXX` "
134
- if [ $? -ne 0 ]
133
+ typeset file
134
+
135
+ file=" ` \m ktemp -t virtualenvwrapper-$suffix -XXXXXXXXXX` "
136
+ if [ $? -ne 0 ] || [ -z " $file " ] || [ ! -f " $file " ]
135
137
then
136
138
echo " ERROR: virtualenvwrapper could not create a temporary file name." 1>&2
137
139
return 1
@@ -142,12 +144,11 @@ function virtualenvwrapper_tempfile {
142
144
143
145
# Run the hooks
144
146
function virtualenvwrapper_run_hook {
145
- typeset hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) "
146
- if [ -z " $hook_script " ]
147
- then
148
- echo " ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2
149
- return 1
150
- fi
147
+ typeset hook_script
148
+ typeset result
149
+
150
+ hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) " || return 1
151
+
151
152
if [ -z " $VIRTUALENVWRAPPER_LOG_DIR " ]
152
153
then
153
154
echo " ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
You can’t perform that action at this time.
0 commit comments