Skip to content

Fix #252: follow symlinked directories when importing a folder - #253

Open
Huyvux12 wants to merge 2 commits into
66HEX:masterfrom
Huyvux12:fix-252-symlinked-folders
Open

Huyvux12 wants to merge 2 commits into
66HEX:masterfrom
Huyvux12:fix-252-symlinked-folders

Conversation

@Huyvux12

Copy link
Copy Markdown

Fixes #252.

Choosing a folder containing a symlinked subdirectory added nothing from the symlink target. supported_source_paths_in_directory in frame-app/src/file_filters.rs used DirEntry::file_type(), which does not follow symlinks, so a symlinked directory reported neither is_dir() nor is_file() and was silently skipped (same for symlinked files).

The fix switches the traversal to std::fs::metadata(), which follows symlinks, so linked directories are walked and linked files are collected under the path the user actually picked. Cycle protection uses a stack-scoped set of canonical directory paths: a directory whose canonical path is already on the current walk is not re-entered, so symlink loops terminate. A directory reached through a different symlink path is still traversed, so the same files can legitimately appear under each distinct path (matching the existing no-dedupe behaviour of discover_supported_source_paths).

Proof

Base: 8fe5aa17aa86ec8b7326b3b93584491d9d11a14c (master).

Repro (tests only, before the fix) — cargo test -p frame-app file_filters:

  • 14 passed, 2 failed: discover_supported_source_paths_follows_symlinked_directories (got [], expected [<root>/linked/clip.mp4]) and discover_supported_source_paths_skips_symlink_loops_and_duplicate_targets (got only [<root>/target/clip.mp4], expected the linked, also-linked and target paths).

Pass after — same command: 16 passed, 0 failed.

Control case: the existing discover_supported_source_paths_expands_directories_recursively test still passes, as do all other pre-existing file_filters tests.

Regression scope:

  • Full cargo test -p frame-app --lib: 1158 passed, 1 failed. The one failure, app::accessibility_ui_tests::crop_resize_and_scrollbar_drags_start_outside_the_visible_markers (expanded area did not start a drag, accessibility_ui_tests.rs:489), fails identically on the clean base commit, so it is pre-existing and unrelated to this change.
  • Integration tests cargo test -p frame-app --test gpui_queue: 2 passed.
  • cargo fmt --check -p frame-app: clean. cargo clippy -p frame-app --lib --tests: no warnings.
  • Note: the frame bin test targets initially failed to link in this sandbox (unable to find library -lxkbcommon-x11); installing libxkbcommon-x11-dev locally fixed that, and the full cargo test -p frame-app file_filters run above (lib + bin + integration targets) passes.

Diff scope

1 file, frame-app/src/file_filters.rs (+78/−6), in 2 commits: regression tests first, then the fix. The new tests are #[cfg(unix)] (they create symlinks via std::os::unix::fs::symlink); the fix itself only uses std::fs APIs and is platform-independent.

@66HEX

66HEX commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix and the regression tests. I found one blocking issue in the traversal.

Removing directories from visited_directories after recursion prevents ancestor cycles, but allows the same target to be traversed again through other aliases. In a local reproduction against 72c83e2, discovery returned 4,096 paths for one physical file.

Please retain visited directory targets for the entire folder walk and update the duplicate-target test accordingly. We also need a regression test where multiple symlink paths converge on the same directories, asserting that each target is visited once. The current test explicitly accepts duplicate results, so it doesn't catch this case.

Once that's addressed, I can review the updated implementation and run the required checks.

@66HEX 66HEX left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

There is an issue with backtracking visited_directories.remove(&canonical_path): while it prevents direct symlink cycles, it still allows exponential traversal blowup on symlink DAGs (e.g., diamond symlink structures can cause $2^n$ walks and hang the app), and it causes files inside a target directory reached through multiple symlinks to be added to the queue multiple times.

Notice that the new test is even named discover_supported_source_paths_skips_symlink_loops_and_duplicate_targets, yet currently asserts that clip.mp4 is returned three times.

If we keep visited_directories as a traversal-wide visited set (i.e. remove visited_directories.remove(&canonical_path)), it both prevents DAG DoS and avoids duplicate queue entries from symlinked directories. Could you update the traversal and test accordingly?

This branch has not been deployed

No deployments
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.

[Feature]: Support adding files from symlinked directories when choosing to open a folder

2 participants