Skip to content

Commit 5560f08

Browse files
committed
Skip unreadable directories in projectile-index-directory (#1873)
Wrap the directory-files call in ignore-errors so that unreadable directories (e.g. .Spotlight-V100 on macOS) are silently skipped instead of aborting the entire native indexing operation.
1 parent ac37c2c commit 5560f08

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Bugs fixed
1010

11+
* [#1873](https://github.com/bbatsov/projectile/issues/1873): Skip unreadable directories during native indexing instead of aborting with a permission error.
1112
* [#1961](https://github.com/bbatsov/projectile/issues/1961): Prevent directories from matching file-type project root markers (e.g., a `workspace` directory no longer matches the `WORKSPACE` Bazel marker on case-insensitive filesystems).
1213
* [#1749](https://github.com/bbatsov/projectile/issues/1749): Strip `./` prefix from `fd` output in `projectile-files-via-ext-command`, fixing compatibility with older `fd` versions that don't support `--strip-cwd-prefix`.
1314

projectile.el

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,10 @@ IGNORED-DIRECTORIES may optionally be provided."
15241524
(projectile-index-directory f patterns progress-reporter ignored-files ignored-directories globally-ignored-directories))
15251525
(unless (projectile-ignored-file-p f ignored-files)
15261526
(list f))))))
1527-
(directory-files directory t)))))
1527+
;; Use ignore-errors to skip unreadable directories (e.g.
1528+
;; .Spotlight-V100 on macOS) instead of aborting the entire
1529+
;; indexing operation.
1530+
(ignore-errors (directory-files directory t))))))
15281531

15291532
;;; Alien Project Indexing
15301533
;;

test/projectile-test.el

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,25 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
532532
(let ((projectile-indexing-method 'hybrid))
533533
(expect (projectile-dir-files "/my/root/") :to-equal '("a/b/c" "a/d/e")))))
534534

535+
(describe "projectile-index-directory"
536+
(it "skips unreadable directories"
537+
(unless (eq system-type 'windows-nt)
538+
(projectile-test-with-sandbox
539+
(projectile-test-with-files
540+
("project/"
541+
"project/.projectile"
542+
"project/readable-file.el"
543+
"project/unreadable-dir/")
544+
(let* ((project-dir (file-name-as-directory (expand-file-name "project")))
545+
(unreadable-dir (expand-file-name "unreadable-dir" project-dir))
546+
(progress-reporter (make-progress-reporter "Indexing...")))
547+
(set-file-modes unreadable-dir #o000)
548+
(unwind-protect
549+
(let ((files (projectile-index-directory project-dir nil progress-reporter)))
550+
(expect (cl-some (lambda (f) (string-match-p "readable-file" f)) files) :to-be-truthy)
551+
(expect (cl-some (lambda (f) (string-match-p "unreadable-dir" f)) files) :not :to-be-truthy))
552+
(set-file-modes unreadable-dir #o755))))))))
553+
535554
(describe "projectile-get-sub-projects-command"
536555
(it "gets sub projects command for git"
537556
(expect (string-prefix-p "git" (projectile-get-sub-projects-command 'git)) :to-be-truthy))

0 commit comments

Comments
 (0)