Skip to content

Don't let a corrupt known projects file take the projects with it - #2135

Merged
bbatsov merged 1 commit into
masterfrom
feature/known-projects-hygiene
Jul 28, 2026
Merged

Don't let a corrupt known projects file take the projects with it#2135
bbatsov merged 1 commit into
masterfrom
feature/known-projects-hygiene

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Reading #1927's thread turned up something more interesting than the feature I
went in for. The reporter's known projects file had been corrupted by another
package writing propertized strings into it, and the visible symptom was that
projects silently stopped being tracked.

The current code reads an unreadable file as an empty list. If the file goes
bad after load, that looks exactly like another Emacs having removed every
project, so the merge drops the session's projects too - and then writes the
result back over the file. A stray byte costs you a list built up over years.

So an unreadable file is now moved aside as <file>.corrupt and reported, and
it no longer contributes a removal list at all. projectile-load-known-projects
and projectile-merge-known-projects both go through one reader that tells
"absent" (legitimately no projects) apart from "unreadable" (we don't know).
Saving also strips text properties, so Projectile can't be the one writing a
file it won't read back.

The spec for the post-load case is what caught a hole in my own first attempt: I
neutralized known-on-last-sync but left removed-in-other-process still
computing against the empty list, so the projects were dropped anyway.

Then the feature I actually came for: projectile-ignored-project-patterns,
regexps sitting between the existing exact-path projectile-ignored-projects
and the projectile-ignored-project-function predicate. Keeping /tmp and
Downloads out of the known projects is a common enough want that it shouldn't
need a lambda.

Fixes #1927

…#1927]

An unreadable known projects file was read as an empty list. When the
file went bad after load - which is what the reporter hit, another
package having written propertized strings into it - that looked exactly
like another Emacs having removed every project, so the merge dropped
the session's projects as well and then overwrote the file with the
remains.

The file is now moved aside with a .corrupt suffix and the fact
reported, and an unreadable file no longer contributes a removal list at
all. Saving strips text properties too, so Projectile can't be the one
writing a file it won't be able to read back.

Also adds projectile-ignored-project-patterns, so keeping /tmp or
Downloads out of the known projects is a list of regexps rather than a
lambda. It sits between the existing exact-path list and the predicate.
@bbatsov
bbatsov merged commit fad435c into master Jul 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

projectile-switch-project does not show known projects outside search path

1 participant