When signalling a file open error, read channel type before closing.
authorTaylor R Campbell <campbell@mumble.net>
Wed, 23 Mar 2011 04:34:00 +0000 (04:34 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Wed, 23 Mar 2011 04:34:00 +0000 (04:34 +0000)
src/runtime/io.scm

index 1bca8e7adbadea0b53c3cdb651a94368516dbf0c..f922990340fc22c9787d1cfdb8cdea2c08bb7c7a 100644 (file)
@@ -288,18 +288,15 @@ USA.
   (let ((channel (open-channel (lambda (p) (primitive filename p)))))
     (if (or (channel-type=directory? channel)
            (channel-type=unknown? channel))
-       (begin
+       (let ((reason
+              (if (channel-type=directory? channel)
+                  "Is a directory"
+                  "Unknown file type")))
          (channel-close channel)
          (file-open primitive
                     operator
-                    (error:file-operation filename
-                                          "open"
-                                          "file"
-                                          (if (channel-type=directory? channel)
-                                              "Is a directory"
-                                              "Unknown file type")
-                                          operator
-                                          (list filename))))
+                    (error:file-operation filename "open" "file" reason
+                                          operator (list filename))))
        channel)))
 
 (define (file-open-input-channel filename)