summaryrefslogtreecommitdiff
path: root/lisp/ls-lisp.el
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2012-02-07 19:44:36 +0200
committerEli Zaretskii <eliz@gnu.org>2012-02-07 19:44:36 +0200
commit5e0d957fe021bc921bfa4f7568f5501c43ca7fc5 (patch)
treeb6ae71512ffd4615522638a619445d0d050f9ef2 /lisp/ls-lisp.el
parent98d7371e7a9568f51aa016ec2cbee7d56ff1ad50 (diff)
downloademacs-5e0d957fe021bc921bfa4f7568f5501c43ca7fc5.tar.gz
Fix bug #4673 with Dired when `stat' fails for ".." or other files.
lisp/ls-lisp.el (ls-lisp-sanitize): New function. (ls-lisp-insert-directory): Use it to fix or remove any elements in file-alist with missing attributes.
Diffstat (limited to 'lisp/ls-lisp.el')
-rw-r--r--lisp/ls-lisp.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index 576c746761d..de489871887 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -331,6 +331,7 @@ not contain `d', so that a full listing is expected."
;; do all bindings here for speed
total-line files elt short file-size attr
fuid fgid uid-len gid-len)
+ (setq file-alist (ls-lisp-sanitize file-alist))
(cond ((memq ?A switches)
(setq file-alist
(ls-lisp-delete-matching "^\\.\\.?$" file-alist)))
@@ -437,6 +438,22 @@ not contain `d', so that a full listing is expected."
(message "%s: doesn't exist or is inaccessible" file)
(ding) (sit-for 2))))) ; to show user the message!
+(defun ls-lisp-sanitize (file-alist)
+ "Sanitize the elements in FILE-ALIST.
+Fixes any elements in the alist for directory entries whose file
+attributes are nil (meaning that `file-attributes' failed for
+them). This is known to happen for some network shares, in
+particular for the \"..\" directory entry.
+
+If the \"..\" directory entry has nil attributes, the attributes
+are copied from the \".\" entry, if they are non-nil. Otherwise,
+the offending element is removed from the list, as are any
+elements for other directory entries with nil attributes."
+ (if (and (null (cdr (assoc ".." file-alist)))
+ (cdr (assoc "." file-alist)))
+ (setcdr (assoc ".." file-alist) (cdr (assoc "." file-alist))))
+ (rassq-delete-all nil file-alist))
+
(defun ls-lisp-column-format (file-alist)
"Insert the file names (only) in FILE-ALIST into the current buffer.
Format in columns, sorted vertically, following GNU ls -C.