1.0.17.5: alter PROBE-FILE so that no signal is raised during its execution.
authorRichard M Kreuter <kreuter@users.sourceforge.net>
Thu, 29 May 2008 00:53:35 +0000 (00:53 +0000)
committerRichard M Kreuter <kreuter@users.sourceforge.net>
Thu, 29 May 2008 00:53:35 +0000 (00:53 +0000)
src/code/filesys.lisp
version.lisp-expr

index 1d2e11b..20a0c1e 100644 (file)
 ;;;   As realpath(3) is not atomic anyway, we only ever call it when
 ;;;   we think a file exists, so just be careful when rewriting this
 ;;;   routine.
-(defun query-file-system (pathspec query-for)
+(defun query-file-system (pathspec query-for &optional (errorp t))
   (let ((pathname (translate-logical-pathname
                    (merge-pathnames
                     (pathname pathspec)
              :format-control "~@<can't find the ~A of wild pathname ~A~
                               (physicalized from ~A).~:>"
              :format-arguments (list query-for pathname pathspec)))
-    (let ((filename (native-namestring pathname :as-file t)))
-      (multiple-value-bind (existsp errno ino mode nlink uid gid rdev size
-                                    atime mtime)
-          (sb!unix:unix-stat filename)
-        (declare (ignore ino nlink gid rdev size atime))
-        (if existsp
-            (case query-for
-              (:truename (nth-value
-                          0
-                          (parse-native-namestring
-                           ;; Note: in case the file is stat'able, POSIX
-                           ;; realpath(3) gets us a canonical absolute
-                           ;; filename, even if the post-merge PATHNAME
-                           ;; is not absolute...
-                           (multiple-value-bind (realpath errno)
-                               (sb!unix:unix-realpath filename)
-                             (if realpath
-                                 realpath
-                                 (simple-file-perror "couldn't resolve ~A"
-                                                     filename errno)))
-                           (pathname-host pathname)
-                           (sane-default-pathname-defaults)
-                           ;; ... but without any trailing slash.
-                           :as-directory (eql (logand  mode sb!unix:s-ifmt)
-                                              sb!unix:s-ifdir))))
-              (:author (sb!unix:uid-username uid))
-              (:write-date (+ unix-to-universal-time mtime)))
-            (progn
-              ;; SBCL has for many years had a policy that a pathname
-              ;; that names an existing, dangling or self-referential
-              ;; symlink denotes the symlink itself.  stat(2) fails
-              ;; and sets errno to ELOOP in this case, but we must
-              ;; distinguish cases where the symlink exists from ones
-              ;; where there's a loop in the apparent containing
-              ;; directory.
-              #!-win32
-              (multiple-value-bind (linkp ignore ino mode nlink uid gid rdev
-                                          size atime mtime)
-                  (sb!unix:unix-lstat filename)
-                (declare (ignore ignore ino mode nlink gid rdev size atime))
-                (when (and (or (= errno sb!unix:enoent)
-                               (= errno sb!unix:eloop))
-                           linkp)
-                  (return-from query-file-system
-                    (case query-for
-                      (:truename
-                       ;; So here's a trick: since lstat succeded,
-                       ;; FILENAME exists, so its directory exists and
-                       ;; only the non-directory part is loopy.  So
-                       ;; let's resolve FILENAME's directory part with
-                       ;; realpath(3), in order to get a canonical
-                       ;; absolute name for the directory, and then
-                       ;; return a pathname having PATHNAME's name,
-                       ;; type, and version, but the rest from the
-                       ;; truename of the directory.  Since we turned
-                       ;; PATHNAME into FILENAME "as a file", FILENAME
-                       ;; does not end in a slash, and so we get the
-                       ;; directory part of FILENAME by reparsing
-                       ;; FILENAME and masking off its name, type, and
-                       ;; version bits.  But note not to call ourselves
-                       ;; recursively, because we don't want to
-                       ;; re-merge against *DEFAULT-PATHNAME-DEFAULTS*,
-                       ;; since PATHNAME may be a relative pathname.
-                       (merge-pathnames
-                        (nth-value
-                         0
-                         (parse-native-namestring
-                          (multiple-value-bind (realpath errno)
-                              (sb!unix:unix-realpath
-                               (native-namestring
-                                (make-pathname
-                                 :name :unspecific
-                                 :type :unspecific
-                                 :version :unspecific
-                                 :defaults (parse-native-namestring
-                                            filename
-                                            (pathname-host pathname)
-                                            (sane-default-pathname-defaults)))))
-                            (if realpath
-                                realpath
-                                (simple-file-perror "couldn't resolve ~A"
-                                                    filename errno)))
-                          (pathname-host pathname)
-                          (sane-default-pathname-defaults)
-                          :as-directory t))
-                        pathname))
-                      (:author (sb!unix:uid-username uid))
-                      (:write-date (+ unix-to-universal-time mtime))))))
-              ;; If we're still here, the file doesn't exist; error.
-              (simple-file-perror
-               (format nil "failed to find the ~A of ~~A" query-for)
-               pathspec errno)))))))
+    (flet ((fail (note-format pathname errno)
+             (if errorp
+                 (simple-file-perror note-format pathname errno)
+                 (return-from query-file-system nil))))
+      (let ((filename (native-namestring pathname :as-file t)))
+        (multiple-value-bind (existsp errno ino mode nlink uid gid rdev size
+                                      atime mtime)
+            (sb!unix:unix-stat filename)
+          (declare (ignore ino nlink gid rdev size atime))
+          (if existsp
+              (case query-for
+                (:truename (nth-value
+                            0
+                            (parse-native-namestring
+                             ;; Note: in case the file is stat'able, POSIX
+                             ;; realpath(3) gets us a canonical absolute
+                             ;; filename, even if the post-merge PATHNAME
+                             ;; is not absolute...
+                             (multiple-value-bind (realpath errno)
+                                 (sb!unix:unix-realpath filename)
+                               (if realpath
+                                   realpath
+                                   (fail "couldn't resolve ~A" filename errno)))
+                             (pathname-host pathname)
+                             (sane-default-pathname-defaults)
+                             ;; ... but without any trailing slash.
+                             :as-directory (eql (logand  mode sb!unix:s-ifmt)
+                                                sb!unix:s-ifdir))))
+                (:author (sb!unix:uid-username uid))
+                (:write-date (+ unix-to-universal-time mtime)))
+              (progn
+                ;; SBCL has for many years had a policy that a pathname
+                ;; that names an existing, dangling or self-referential
+                ;; symlink denotes the symlink itself.  stat(2) fails
+                ;; and sets errno to ENOENT or ELOOP respectively, but
+                ;; we must distinguish cases where the symlink exists
+                ;; from ones where there's a loop in the apparent
+                ;; containing directory.
+                #!-win32
+                (multiple-value-bind (linkp ignore ino mode nlink uid gid rdev
+                                            size atime mtime)
+                    (sb!unix:unix-lstat filename)
+                  (declare (ignore ignore ino mode nlink gid rdev size atime))
+                  (when (and (or (= errno sb!unix:enoent)
+                                 (= errno sb!unix:eloop))
+                             linkp)
+                    (return-from query-file-system
+                      (case query-for
+                        (:truename
+                         ;; So here's a trick: since lstat succeded,
+                         ;; FILENAME exists, so its directory exists and
+                         ;; only the non-directory part is loopy.  So
+                         ;; let's resolve FILENAME's directory part with
+                         ;; realpath(3), in order to get a canonical
+                         ;; absolute name for the directory, and then
+                         ;; return a pathname having PATHNAME's name,
+                         ;; type, and version, but the rest from the
+                         ;; truename of the directory.  Since we turned
+                         ;; PATHNAME into FILENAME "as a file", FILENAME
+                         ;; does not end in a slash, and so we get the
+                         ;; directory part of FILENAME by reparsing
+                         ;; FILENAME and masking off its name, type, and
+                         ;; version bits.  But note not to call ourselves
+                         ;; recursively, because we don't want to
+                         ;; re-merge against *DEFAULT-PATHNAME-DEFAULTS*,
+                         ;; since PATHNAME may be a relative pathname.
+                         (merge-pathnames
+                          (nth-value
+                           0
+                           (parse-native-namestring
+                            (multiple-value-bind (realpath errno)
+                                (sb!unix:unix-realpath
+                                 (native-namestring
+                                  (make-pathname
+                                   :name :unspecific
+                                   :type :unspecific
+                                   :version :unspecific
+                                   :defaults (parse-native-namestring
+                                              filename
+                                              (pathname-host pathname)
+                                              (sane-default-pathname-defaults)))))
+                              (if realpath
+                                  realpath
+                                  (fail "couldn't resolve ~A" filename errno)))
+                            (pathname-host pathname)
+                            (sane-default-pathname-defaults)
+                            :as-directory t))
+                          pathname))
+                        (:author (sb!unix:uid-username uid))
+                        (:write-date (+ unix-to-universal-time mtime))))))
+                ;; If we're still here, the file doesn't exist; error.
+                (fail
+                 (format nil "failed to find the ~A of ~~A" query-for)
+                 pathspec errno))))))))
 
 
 (defun probe-file (pathspec)
   #!+sb-doc
   "Return the truename of PATHSPEC if the truename can be found,
 or NIL otherwise.  See TRUENAME for more information."
-  (handler-case (truename pathspec) (file-error () nil)))
+  (query-file-system pathspec :truename nil))
 
 (defun truename (pathspec)
   #!+sb-doc
index 7a76638..918adb0 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.17.4"
+"1.0.17.5"