Fuco1 / dired-hacks

Collection of useful dired additions
GNU General Public License v3.0
877 stars 77 forks source link

`wrong-type-argument stringp nil' in dired-collapse with dangling mounts #203

Closed cpitclaudel closed 1 year ago

cpitclaudel commented 1 year ago

When I run dired-collapse in my home directory, I get the following errror:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-directory-p(nil)
  (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files)))
  (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files))) (setq path (car files)))
  (let ((path (dired-utils-get-filename)) files) (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files))) (setq path (car files))) (if (and (not files) (equal path (dired-utils-get-filename))) (dired-collapse--create-ov 'to-eol) (setq path (s-chop-prefix (dired-current-directory) path)) (if (string-match-p "/" path) (progn (let ((default-directory (dired-current-directory))) (dired-collapse--replace-file path)) (dired-insert-set-properties (line-beginning-position) (line-end-position)) (dired-collapse--create-ov (= 0 (length files)))))))
  (progn (let ((path (dired-utils-get-filename)) files) (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files))) (setq path (car files))) (if (and (not files) (equal path (dired-utils-get-filename))) (dired-collapse--create-ov 'to-eol) (setq path (s-chop-prefix (dired-current-directory) path)) (if (string-match-p "/" path) (progn (let ((default-directory ...)) (dired-collapse--replace-file path)) (dired-insert-set-properties (line-beginning-position) (line-end-position)) (dired-collapse--create-ov (= 0 (length files))))))))
  (if (and (looking-at-p dired-re-dir) (not (member (dired-utils-get-filename 'no-dir) (list "." ".."))) (not (eolp))) (progn (let ((path (dired-utils-get-filename)) files) (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files))) (setq path (car files))) (if (and (not files) (equal path (dired-utils-get-filename))) (dired-collapse--create-ov 'to-eol) (setq path (s-chop-prefix (dired-current-directory) path)) (if (string-match-p "/" path) (progn (let (...) (dired-collapse--replace-file path)) (dired-insert-set-properties (line-beginning-position) (line-end-position)) (dired-collapse--create-ov (= 0 ...))))))))
  (while (not (eobp)) (if (and (looking-at-p dired-re-dir) (not (member (dired-utils-get-filename 'no-dir) (list "." ".."))) (not (eolp))) (progn (let ((path (dired-utils-get-filename)) files) (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files (f-entries path)) (= 1 (length files))) (setq path (car files))) (if (and (not files) (equal path (dired-utils-get-filename))) (dired-collapse--create-ov 'to-eol) (setq path (s-chop-prefix (dired-current-directory) path)) (if (string-match-p "/" path) (progn (let ... ...) (dired-insert-set-properties ... ...) (dired-collapse--create-ov ...))))))) (forward-line 1))
  (save-excursion (goto-char (point-min)) (while (not (eobp)) (if (and (looking-at-p dired-re-dir) (not (member (dired-utils-get-filename 'no-dir) (list "." ".."))) (not (eolp))) (progn (let ((path (dired-utils-get-filename)) files) (while (and (file-directory-p path) (file-accessible-directory-p path) (setq files ...) (= 1 ...)) (setq path (car files))) (if (and (not files) (equal path ...)) (dired-collapse--create-ov 'to-eol) (setq path (s-chop-prefix ... path)) (if (string-match-p "/" path) (progn ... ... ...)))))) (forward-line 1)))
  (let* ((buffer-invisibility-spec nil) (inhibit-read-only t)) (save-excursion (goto-char (point-min)) (while (not (eobp)) (if (and (looking-at-p dired-re-dir) (not (member (dired-utils-get-filename ...) (list "." ".."))) (not (eolp))) (progn (let ((path ...) files) (while (and ... ... ... ...) (setq path ...)) (if (and ... ...) (dired-collapse--create-ov ...) (setq path ...) (if ... ...))))) (forward-line 1))))
  (progn (let* ((buffer-invisibility-spec nil) (inhibit-read-only t)) (save-excursion (goto-char (point-min)) (while (not (eobp)) (if (and (looking-at-p dired-re-dir) (not (member ... ...)) (not (eolp))) (progn (let (... files) (while ... ...) (if ... ... ... ...)))) (forward-line 1)))))
  (if (or (not (file-remote-p default-directory)) dired-collapse-remote) (progn (let* ((buffer-invisibility-spec nil) (inhibit-read-only t)) (save-excursion (goto-char (point-min)) (while (not (eobp)) (if (and (looking-at-p dired-re-dir) (not ...) (not ...)) (progn (let ... ... ...))) (forward-line 1))))))
  dired-collapse()

This seems to be due to a line that dired-collapse doesn't expect; here's an example buffer:

  /home/foo:
  /usr/bin/ls: cannot access '/home/foo/media': Transport endpoint is not connected
    total used in directory 4.1M available 596.9 GiB
    drwxr-x--- 68 foo  foo  4.0K Jun 16 17:07 .
    drwxr-xr-x  3 root root 4.0K Nov 17  2022 ..
    -rw-rw-r--  1 foo  foo    39 May 30 00:06 .aspell.en.prepl
    -rw-rw-r--  1 foo  foo  7.6K May 30 00:06 .aspell.en.pws
    d?????????  ? ?    ?       ?            ? media
    drwx------  4 foo  foo  4.0K May 11 16:48 .mozilla

The crash happens because dired-utils-get-filename returns nil on the media line (that line is there because media is a dangling mount).

Fuco1 commented 1 year ago

Thanks, your analysis seems correct. I've wrapped the code with a when-let binding for the filename, so this should prevent the issue. If you have some time to test it and confirm it would be great :) MELPA will take couple hours to rebuild though.