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,25 +83,27 @@ 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?
;; From Osicat's `file-permissions': (let ((stat (ignore-errors (osicat-posix:stat native-path))))
(flet ((stat-permissions (stat) (when stat
(let ((mode (osicat-posix:stat-mode stat))) ;; From Osicat's `file-permissions':
(loop for (name . value) in osicat::+permissions+ (flet ((stat-permissions (stat)
when (plusp (logand mode value)) (let ((mode (osicat-posix:stat-mode stat)))
collect name)))) (loop for (name . value) in osicat::+permissions+
(make-instance 'file when (plusp (logand mode value))
:path (uiop:unix-namestring native-path) collect name))))
:inode (osicat-posix:stat-ino stat) (make-instance 'file
:link-count (osicat-posix:stat-nlink stat) :path (uiop:unix-namestring native-path)
:kind (osicat:file-kind native-path) ; TODO: Don't recall `stat'. :inode (osicat-posix:stat-ino stat)
:size (osicat-posix:stat-size stat) :link-count (osicat-posix:stat-nlink stat)
:user-id (osicat-posix:stat-uid stat) :kind (osicat:file-kind native-path) ; TODO: Don't recall `stat'.
:group-id (osicat-posix:stat-gid stat) :size (osicat-posix:stat-size stat)
:creation-date (local-time:unix-to-timestamp (osicat-posix:stat-ctime stat)) :user-id (osicat-posix:stat-uid stat)
:modification-date (local-time:unix-to-timestamp (osicat-posix:stat-mtime stat)) :group-id (osicat-posix:stat-gid stat)
:access-date (local-time:unix-to-timestamp (osicat-posix:stat-atime stat)) :creation-date (local-time:unix-to-timestamp (osicat-posix:stat-ctime stat))
:permissions (stat-permissions 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))
:permissions (stat-permissions stat)))))))
(export-always '*finder-include-directories*) (export-always '*finder-include-directories*)
(defvar *finder-include-directories* t (defvar *finder-include-directories* t