mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
(file-expand-wildcards): Handle patterns ending in "/"
The bug was encountered via the ls-lisp advice on Dired but
it actually affects all uses of `file-expand-wildcards`,
so better fix it there.
* lisp/files.el (file-expand-wildcards): Fix bug#60819.
* lisp/ls-lisp.el (ls-lisp--dired): Undo commit b365a7cc32.
* test/lisp/files-tests.el (files-tests--expand-wildcards): New test.
This commit is contained in:
parent
1da0fccc64
commit
6cc1418fc3
3 changed files with 34 additions and 37 deletions
|
|
@ -7547,27 +7547,34 @@ default directory. However, if FULL is non-nil, they are absolute."
|
|||
(dolist (dir (nreverse dirs))
|
||||
(when (or (null dir) ; Possible if DIRPART is not wild.
|
||||
(file-accessible-directory-p dir))
|
||||
(let ((this-dir-contents
|
||||
;; Filter out "." and ".."
|
||||
(delq nil
|
||||
(mapcar (lambda (name)
|
||||
(unless (string-match "\\`\\.\\.?\\'"
|
||||
(file-name-nondirectory name))
|
||||
name))
|
||||
(directory-files
|
||||
(or dir ".") full
|
||||
(if regexp
|
||||
;; We're matching each file name
|
||||
;; element separately.
|
||||
(concat "\\`" nondir "\\'")
|
||||
(wildcard-to-regexp nondir)))))))
|
||||
(setq contents
|
||||
(nconc
|
||||
(if (and dir (not full))
|
||||
(mapcar (lambda (name) (concat dir name))
|
||||
this-dir-contents)
|
||||
this-dir-contents)
|
||||
contents)))))
|
||||
(if (equal "" nondir)
|
||||
;; `nondir' is "" when the pattern ends in "/". Basically ""
|
||||
;; refers to the directory itself, like ".", but it's not
|
||||
;; among the names returned by `directory-files', so we have
|
||||
;; to special-case it.
|
||||
(push (or dir nondir) contents)
|
||||
(let ((this-dir-contents
|
||||
;; Filter out "." and ".."
|
||||
(delq nil
|
||||
(mapcar (lambda (name)
|
||||
(unless (string-match "\\`\\.\\.?\\'"
|
||||
(file-name-nondirectory
|
||||
name))
|
||||
name))
|
||||
(directory-files
|
||||
(or dir ".") full
|
||||
(if regexp
|
||||
;; We're matching each file name
|
||||
;; element separately.
|
||||
(concat "\\`" nondir "\\'")
|
||||
(wildcard-to-regexp nondir)))))))
|
||||
(setq contents
|
||||
(nconc
|
||||
(if (and dir (not full))
|
||||
(mapcar (lambda (name) (concat dir name))
|
||||
this-dir-contents)
|
||||
this-dir-contents)
|
||||
contents))))))
|
||||
contents)))
|
||||
|
||||
(defcustom find-sibling-rules nil
|
||||
|
|
@ -7757,7 +7764,7 @@ need to be passed verbatim to shell commands."
|
|||
(purecopy "ls"))
|
||||
"Absolute or relative name of the `ls'-like program.
|
||||
This is used by `insert-directory' and `dired-insert-directory'
|
||||
(thus, also by `dired'). For Dired, this should ideally point to
|
||||
\(thus, also by `dired'). For Dired, this should ideally point to
|
||||
GNU ls, or another version of ls that supports the \"--dired\"
|
||||
flag. See `dired-use-ls-dired'.
|
||||
|
||||
|
|
|
|||
|
|
@ -483,22 +483,8 @@ not contain `d', so that a full listing is expected."
|
|||
(if (not dir-wildcard)
|
||||
(funcall orig-fun dir-or-list switches)
|
||||
(let* ((default-directory (car dir-wildcard))
|
||||
(wildcard (cdr dir-wildcard))
|
||||
(files (file-expand-wildcards wildcard))
|
||||
(files (file-expand-wildcards (cdr dir-wildcard)))
|
||||
(dir (car dir-wildcard)))
|
||||
;; When the wildcard ends in a slash, file-expand-wildcards
|
||||
;; returns nil; fix that by treating the wildcards as
|
||||
;; specifying only directories whose names match the
|
||||
;; widlcard.
|
||||
(if (and (null files)
|
||||
(directory-name-p wildcard))
|
||||
(setq files
|
||||
(delq nil
|
||||
(mapcar (lambda (fname)
|
||||
(if (file-accessible-directory-p fname)
|
||||
fname))
|
||||
(file-expand-wildcards
|
||||
(directory-file-name wildcard))))))
|
||||
(if files
|
||||
(let ((inhibit-read-only t)
|
||||
(buf
|
||||
|
|
|
|||
|
|
@ -2101,5 +2101,9 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil."
|
|||
(should (documentation 'bar))
|
||||
(should (documentation 'zot)))))
|
||||
|
||||
(ert-deftest files-tests--expand-wildcards ()
|
||||
(should (file-expand-wildcards
|
||||
(concat (directory-file-name default-directory) "*/"))))
|
||||
|
||||
(provide 'files-tests)
|
||||
;;; files-tests.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue