run-program: Don't use /tmp unconditionally.
authorStas Boukarev <stassats@gmail.com>
Tue, 22 May 2012 18:39:07 +0000 (22:39 +0400)
committerStas Boukarev <stassats@gmail.com>
Tue, 22 May 2012 18:39:07 +0000 (22:39 +0400)
* Use TEMP on win32 and TMPDIR on non-win32.
* Don't delete just opened temporary files on windows, because opened
  files cannot be unlinked on windows.

Fixes lp#968837.

NEWS
src/code/run-program.lisp

diff --git a/NEWS b/NEWS
index c4c6ce0..8833fe0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ changes relative to sbcl-1.0.57:
   * bug fix: ENSURE-GENERIC-METHOD-COMBINATION accepts method combination
     objects as its :METHOD-COMBINATION argument, not just lists designating
     method combinations. (lp#936513)
+  * bug fix: run-program no longer unconditionally uses /tmp/ for temporary files.
+    (lp#968837).
 
 changes in sbcl-1.0.57 relative to sbcl-1.0.56:
   * RANDOM enhancements and bug fixes:
index d9e00f2..3cc2e85 100644 (file)
@@ -939,6 +939,12 @@ Users Manual for details about the PROCESS structure."#-win32"
         (get-stream-fd-and-external-format
          (two-way-stream-output-stream stream) direction))))))
 
+(defun get-temporary-directory ()
+  #-win32 (or (sb-ext:posix-getenv "TMPDIR")
+              "/tmp")
+  #+win32 (or (sb-ext:posix-getenv "TEMP")
+              "C:/Temp"))
+
 \f
 ;;; Find a file descriptor to use for object given the direction.
 ;;; Returns the descriptor. If object is :STREAM, returns the created
@@ -957,10 +963,14 @@ Users Manual for details about the PROCESS structure."#-win32"
   ;; run afoul of disk quotas or to choke on small /tmp file systems.
   (flet ((make-temp-fd ()
            (multiple-value-bind (fd name/errno)
-               (sb-unix:sb-mkstemp "/tmp/.run-program-XXXXXX" #o0600)
+               (sb-unix:sb-mkstemp (format nil "~a/.run-program-XXXXXX"
+                                           (get-temporary-directory))
+                                   #o0600)
              (unless fd
                (error "could not open a temporary file: ~A"
                       (strerror name/errno)))
+             ;; Can't unlink an opened file on Windows
+             #-win32
              (unless (sb-unix:unix-unlink name/errno)
                (sb-unix:unix-close fd)
                (error "failed to unlink ~A" name/errno))