diff options
| author | Bozhidar Batsov <bozhidar@batsov.dev> | 2026-02-13 13:35:13 +0200 |
|---|---|---|
| committer | Bozhidar Batsov <bozhidar@batsov.dev> | 2026-02-13 13:35:13 +0200 |
| commit | 5560f083b69d40eb1a0e359fdd4ba9712f8a1bd8 (patch) | |
| tree | a01d10fe4fec5c2034478549fbeea41a8d05dd6d | |
| parent | ac37c2c96b1296b147aed021273efdd20e3b4938 (diff) | |
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.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | projectile.el | 5 | ||||
| -rw-r--r-- | test/projectile-test.el | 19 |
3 files changed, 24 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af852c..014544a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Bugs fixed +* [#1873](https://github.com/bbatsov/projectile/issues/1873): Skip unreadable directories during native indexing instead of aborting with a permission error. * [#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). * [#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`. diff --git a/projectile.el b/projectile.el index 90e2d48..0acc7f4 100644 --- a/projectile.el +++ b/projectile.el @@ -1524,7 +1524,10 @@ IGNORED-DIRECTORIES may optionally be provided." (projectile-index-directory f patterns progress-reporter ignored-files ignored-directories globally-ignored-directories)) (unless (projectile-ignored-file-p f ignored-files) (list f)))))) - (directory-files directory t))))) + ;; Use ignore-errors to skip unreadable directories (e.g. + ;; .Spotlight-V100 on macOS) instead of aborting the entire + ;; indexing operation. + (ignore-errors (directory-files directory t)))))) ;;; Alien Project Indexing ;; diff --git a/test/projectile-test.el b/test/projectile-test.el index 0880d6d..c658dcd 100644 --- a/test/projectile-test.el +++ b/test/projectile-test.el @@ -532,6 +532,25 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. (let ((projectile-indexing-method 'hybrid)) (expect (projectile-dir-files "/my/root/") :to-equal '("a/b/c" "a/d/e"))))) +(describe "projectile-index-directory" + (it "skips unreadable directories" + (unless (eq system-type 'windows-nt) + (projectile-test-with-sandbox + (projectile-test-with-files + ("project/" + "project/.projectile" + "project/readable-file.el" + "project/unreadable-dir/") + (let* ((project-dir (file-name-as-directory (expand-file-name "project"))) + (unreadable-dir (expand-file-name "unreadable-dir" project-dir)) + (progress-reporter (make-progress-reporter "Indexing..."))) + (set-file-modes unreadable-dir #o000) + (unwind-protect + (let ((files (projectile-index-directory project-dir nil progress-reporter))) + (expect (cl-some (lambda (f) (string-match-p "readable-file" f)) files) :to-be-truthy) + (expect (cl-some (lambda (f) (string-match-p "unreadable-dir" f)) files) :not :to-be-truthy)) + (set-file-modes unreadable-dir #o755)))))))) + (describe "projectile-get-sub-projects-command" (it "gets sub projects command for git" (expect (string-prefix-p "git" (projectile-get-sub-projects-command 'git)) :to-be-truthy)) |
