From: Stas Boukarev Date: Tue, 24 Sep 2013 18:04:59 +0000 (+0400) Subject: Fix OPEN with :io and :if-does-not-exist nil. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=b15ec266a38f1dae4e52a46c1980d4b7259686d3;p=sbcl.git Fix OPEN with :io and :if-does-not-exist nil. No need to call unix-stat, truename is already bound to the result of PROBE-FILE. Reported by Eric Marsden. --- diff --git a/src/code/fd-stream.lisp b/src/code/fd-stream.lisp index c583f17..cae969d 100644 --- a/src/code/fd-stream.lisp +++ b/src/code/fd-stream.lisp @@ -2325,7 +2325,8 @@ (native-namestring truename :as-file t)) ((or (not input) (and input (eq if-does-not-exist :create)) - (and (eq direction :io) (not if-does-not-exist-given))) + (and (eq direction :io) + (not if-does-not-exist-given))) (native-namestring physical :as-file t))))) (flet ((open-error (format-control &rest format-arguments) (error 'simple-file-error @@ -2371,7 +2372,7 @@ :if-does-not-exist) (cond ((eq if-does-not-exist :create) (setf mask (logior mask sb!unix:o_creat))) - ((not (member if-exists '(:new-version :error nil)))) + ((not (member if-exists '(:error nil)))) ;; Both if-does-not-exist and if-exists now imply ;; that there will be no opening of files, and either ;; an error would be signalled, or NIL returned @@ -2381,7 +2382,7 @@ (open-error "OPEN :IF-DOES-NOT-EXIST ~s ~ :IF-EXISTS ~s will always signal an error." if-does-not-exist if-exists)) - ((sb!unix:unix-stat namestring) + (truename (if if-exists (open-error "File exists ~s." pathname) (return-from open))) diff --git a/tests/filesys.pure.lisp b/tests/filesys.pure.lisp index 554fa07..0dc72a7 100644 --- a/tests/filesys.pure.lisp +++ b/tests/filesys.pure.lisp @@ -201,11 +201,12 @@ ;;; (:error :error)) ;;; collect (list 'do-open exist if-exists if-does-not-exist))) (with-test (:name :open-never-openning) - (flet ((do-open (existing if-exists if-does-not-exist) + (flet ((do-open (existing if-exists if-does-not-exist + &optional (direction :output)) (open (if existing #.(or *compile-file-truename* *load-truename*) "a-really-non-existing-file") - :direction :output + :direction direction :if-exists if-exists :if-does-not-exist if-does-not-exist))) (assert (raises-error? (do-open nil nil :error))) @@ -221,4 +222,20 @@ (do-open nil :error :error))) (assert (not (do-open t nil nil))) - (assert (raises-error? (do-open t :error :error))))) + (assert (raises-error? (do-open t :error :error))) + + (assert (raises-error? + (do-open nil nil :error :io))) + (assert (not + (do-open nil :error nil :io))) + (assert (not + (do-open t nil :error :io))) + (assert (raises-error? + (do-open t :error nil :io))) + (assert (not + (do-open nil nil nil :io))) + (assert (raises-error? + (do-open nil :error :error :io))) + (assert (not + (do-open t nil nil :io))) + (assert (raises-error? (do-open t :error :error :io)))))