Files
zed/crates/fs
Karthik Chiluveru dc1a4bfd05 trusted_worktrees: Fix case-sensitive path comparison on Windows (#67078)
Closes #66915

## Summary

Zed canonicalizes a folder's path when it opens it, so a worktree root
always has its on-disk spelling. Persisted trusted paths don't. They
keep the casing they had when they were saved. On Windows the two can
drift apart, for example after renaming `Project` to `project`. The
trust check then compares `C:\dev\project` with `C:\dev\Project`, fails,
and the worktree's `.zed/debug.json`, tasks, and settings never load.

The fix happens while a local worktree is created. In
`create_local_worktree`, before `Worktree::local` starts scanning and
before the worktree is added to its store, Zed looks for persisted local
trusted paths that match the worktree path only when case is ignored. It
resolves those through the project's `Fs`, with `Fs::canonicalize` like
the worktree path itself, so mapped drive letters are kept, and trusts
their on-disk spelling in that store. Nothing can check the worktree's
trust before it's added, so the first check already sees the corrected
grant.

What it does and doesn't touch:

- The filesystem decides whether two spellings are the same directory.
In a case-sensitive directory, `safe` and `SAFE` stay separate.
- Path components are checked from the root down, and the lookup stops
at the first symlink or junction, so nothing under a link is looked up.
The check uses a new `Fs::is_symlink`, which neither follows a path nor
needs read access to it, so a parent that can be traversed but not
listed doesn't block the correction. Only local drive paths are
resolved, `C:\` and the extended-length `\\?\C:\` form kept by paths
longer than `MAX_PATH` alike; UNC paths (network shares,
`\\wsl.localhost`) are skipped.
- Only case variants of the new worktree's own ancestors are looked up.
Unrelated saved paths aren't touched, and startup does no extra work.
- It only runs on Windows, only for local stores tracked for trust, and
not when the store's own grants already cover the worktree path.
- Nothing restricted gets lifted, no events are sent, and `can_trust`,
`trust`, and remote hosts are unchanged.

Known limits:

- Only ASCII casing differences are handled. Other paths stay
restricted, the same as today.
- A worktree root that moves after it's opened isn't resolved again,
also the same as today.
- There's a small window between the link check and the lookup. Winning
it requires permission to replace the trusted folder, and with that
permission someone can already put their own folder at the trusted path,
which is trusted today anyway.

## Testing

Windows tests in `crates/project`:

- `test_debug_scenarios_load_with_differently_cased_db_trusted_path`:
the reported symptom. A test-only hook holds the casing resolution while
everything else runs, then releases it: the worktree is never restricted
and its `debug.json` scenario loads. With the lookup placed after
`Worktree::local`, the scan finishes during the hold and the test fails.
- `test_differently_cased_db_trusted_parent_path`: a saved `DEV` parent
trusts `Dev\one` and `Dev\two` opened one after the other in two tracked
stores registered beforehand, but not in a worktree store that isn't
tracked for trust.
- `test_db_trusted_path_in_case_sensitive_directory`: uses `fsutil file
setCaseSensitiveInfo` to make a real case-sensitive directory. Trusting
`safe` doesn't trust `SAFE`, and the junctions `link` -> `LINK` and
`parent` -> `PARENT` (with `project` inside) don't extend trust to their
targets. If the machine can't enable case sensitivity, the test prints a
message and returns early.
- `test_differently_cased_db_trusted_path_longer_than_max_path`: a
project path over 260 characters trusted directly, and a short `\\?\`
parent grant over one, both kept in their `\\?\` form.
- `test_differently_cased_db_trusted_path_under_unlistable_parent`:
denies listing a parent directory with `icacls` and checks that a
differently cased grant still trusts the project below it. It skips if
the deny doesn't apply, e.g. on an admin account.
- `test_db_trusted_paths_on_case_sensitive_fake_fs`: the same cases on a
case-sensitive `FakeFs`, so they run everywhere: distinct `safe`/`SAFE`
directories, a nonexistent `ONLY` spelling, and links to targets
differing only by case, in the leaf and in a parent directory.
- `test_differently_cased_db_trusted_path_on_mapped_drive`: maps a free
drive letter to the temp directory through `\\localhost\C$` (`net use
/persistent:no`) and checks that a differently cased grant on that drive
trusts the worktree. It skips if no drive can be mapped.

Each test fails if I remove the part of the fix it covers: the
respelling, the link check, checking only the last component, or the
tracked-store check. `cargo test -p project` passes on Windows. I
couldn't run Linux or macOS locally, but the new code returns right away
there.

Video: to follow.

Release Notes:

- Fixed project settings, tasks, and debug scenarios not loading on
Windows when a trusted folder's saved path casing differed from the
folder on disk.
2026-11-25 20:09:38 +00:00
..