sb-simple-streams: Close files before deleting them on revert
authorDavid Lichteblau <david@lichteblau.com>
Wed, 10 Aug 2011 14:50:29 +0000 (16:50 +0200)
committerDavid Lichteblau <david@lichteblau.com>
Wed, 10 Aug 2011 18:04:54 +0000 (20:04 +0200)
Thanks to Anton Kovalenko.

contrib/sb-simple-streams/file.lisp

index e668269..48d48ad 100644 (file)
 
 (defmethod device-close ((stream file-simple-stream) abort)
   (with-stream-class (file-simple-stream stream)
-    (let ((fd (or (sm input-handle stream) (sm output-handle stream))))
+    (let ((fd (or (sm input-handle stream) (sm output-handle stream)))
+          (closed nil))
       (when (sb-int:fixnump fd)
         (cond (abort
                (when (any-stream-instance-flags stream :output)
+                 #+win32 (progn (sb-unix:unix-close fd) (setf closed t))
                  (revert-file (sm filename stream) (sm original stream))))
               (t
                (when (sm delete-original stream)
                  (delete-original (sm filename stream) (sm original stream)))))
-        (sb-unix:unix-close fd))
+        (unless closed
+          (sb-unix:unix-close fd)))
       (when (sm buffer stream)
         (free-buffer (sm buffer stream))
         (setf (sm buffer stream) nil))))