ambrevar/file: Return NIL for files that cannot be stat'ed.

For instance, Emacs unsaved buffer locks.
master
Pierre Neidhardt 2021-01-15 13:54:00 +01:00
parent 42335e2759
commit 31a4fffa30
1 changed files with 21 additions and 19 deletions

View File

@ -83,7 +83,9 @@ This returns the directory name for directories."
(uiop:parse-native-namestring path))))) (uiop:parse-native-namestring path)))))
(assert (or (uiop:file-exists-p native-path) (assert (or (uiop:file-exists-p native-path)
(uiop:directory-exists-p native-path))) (uiop:directory-exists-p native-path)))
(let ((stat (osicat-posix:stat native-path))) ;; TODO: What do we do with non-existent files (e.g. unsaved emacs buffers)? Just return nil?
(let ((stat (ignore-errors (osicat-posix:stat native-path))))
(when stat
;; From Osicat's `file-permissions': ;; From Osicat's `file-permissions':
(flet ((stat-permissions (stat) (flet ((stat-permissions (stat)
(let ((mode (osicat-posix:stat-mode stat))) (let ((mode (osicat-posix:stat-mode stat)))
@ -101,7 +103,7 @@ This returns the directory name for directories."
:creation-date (local-time:unix-to-timestamp (osicat-posix:stat-ctime stat)) :creation-date (local-time:unix-to-timestamp (osicat-posix:stat-ctime stat))
:modification-date (local-time:unix-to-timestamp (osicat-posix:stat-mtime stat)) :modification-date (local-time:unix-to-timestamp (osicat-posix:stat-mtime stat))
:access-date (local-time:unix-to-timestamp (osicat-posix:stat-atime stat)) :access-date (local-time:unix-to-timestamp (osicat-posix:stat-atime stat))
:permissions (stat-permissions stat)))))) :permissions (stat-permissions stat)))))))
(export-always '*finder-include-directories*) (export-always '*finder-include-directories*)
(defvar *finder-include-directories* t (defvar *finder-include-directories* t