Doug Hellmann avatar Doug Hellmann committed e7c0534

fix #29 by checking TMPDIR and using a default if no value is found

Comments (0)

Files changed (2)

tests/test_tmpdir.sh

+#!/bin/sh
+
+#set -x
+
+test_dir=$(dirname $0)
+#source "$test_dir/../virtualenvwrapper.sh"
+
+export SCRATCH_DIR="${TMPDIR:-/tmp}/test_scratch_dir"
+
+oneTimeSetUp() {
+    rm -rf "$SCRATCH_DIR"
+    mkdir -p "$SCRATCH_DIR"
+}
+
+oneTimeTearDown() {
+    rm -rf "$SCRATCH_DIR"
+}
+
+setUp () {
+    echo
+    unset VIRTUALENVWRAPPER_TMPDIR
+}
+
+test_unset_tmpdir () {
+    old_tmpdir="$TMPDIR"
+    unset TMPDIR
+    source "$test_dir/../virtualenvwrapper.sh"
+    export TMPDIR="$old_tmpdir"
+    assertSame "$VIRTUALENVWRAPPER_TMPDIR" "/tmp"
+}
+
+test_set_tmpdir () {
+    old_tmpdir="$TMPDIR"
+    export TMPDIR="$SCRATCH_DIR"
+    source "$test_dir/../virtualenvwrapper.sh"
+    export TMPDIR="$old_tmpdir"
+    assertSame "$VIRTUALENVWRAPPER_TMPDIR" "$SCRATCH_DIR"
+}
+
+test_set_virtualenvwrapper_tmpdir () {
+    VIRTUALENVWRAPPER_TMPDIR="$SCRATCH_DIR"
+    source "$test_dir/../virtualenvwrapper.sh"
+    assertSame "$VIRTUALENVWRAPPER_TMPDIR" "$SCRATCH_DIR"
+}
+
+. "$test_dir/shunit2"

virtualenvwrapper.sh

 WORKON_HOME=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.abspath(os.path.expandvars(os.path.expanduser(\"$WORKON_HOME\")))")
 export WORKON_HOME
 
+# Make sure we have a location for temporary files
+if [ "$VIRTUALENVWRAPPER_TMPDIR" = "" ]
+then
+    VIRTUALENVWRAPPER_TMPDIR="$TMPDIR"
+    if [ "$VIRTUALENVWRAPPER_TMPDIR" = "" ]
+    then
+        VIRTUALENVWRAPPER_TMPDIR="/tmp"
+    fi
+fi
+
 # Verify that the WORKON_HOME directory exists
 function virtualenvwrapper_verify_workon_home () {
     if [ ! -d "$WORKON_HOME" ]
     "$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION "$@"
     # Now anything that wants to run inside this shell
     "$VIRTUALENVWRAPPER_PYTHON" -m virtualenvwrapper.hook_loader $HOOK_VERBOSE_OPTION \
-        --source "$@" >>$TMPDIR/$$.hook
-    source $TMPDIR/$$.hook
-    rm -f $TMPDIR/$$.hook
+        --source "$@" >>$VIRTUALENVWRAPPER_TMPDIR/$$.hook
+    source $VIRTUALENVWRAPPER_TMPDIR/$$.hook
+    rm -f $VIRTUALENVWRAPPER_TMPDIR/$$.hook
 }
 
 # Set up virtualenvwrapper properly
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.