Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions rust_port/crates/flow_common/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,21 +1110,30 @@ pub fn make_next_files(
if prunes(path) {
children.clear();
}
// Don't follow a symlink to a directory the crawl reads anyway, which also ends
// cycles, e.g. between packages linked into each other's node_modules.
// Don't follow a symlink to a directory the crawl reads anyway, or to one the walk
// is already in. Either can close a cycle, e.g. between packages linked into each
// other's node_modules.
for entry in children.iter_mut().flatten() {
if entry.read_children.is_some()
&& entry.path_is_symlink()
// Only under the root does the crawl report what's under a symlink by its
// real path.
&& entry.parent_path().starts_with(&root_buf)
&& let Ok(target) = cached_canonicalize(&entry.path())
if entry.read_children.is_none() || !entry.path_is_symlink() {
continue;
}
let Ok(target) = cached_canonicalize(&entry.path()) else {
continue;
};
// Only under the root does the crawl report what's under a symlink by its real
// path.
let crawled_directly = entry.parent_path().starts_with(&root_buf)
&& target.starts_with(&crawl_root)
// The crawl reports everything under the target itself.
&& (duped_options.implicitly_include_root
|| duped_options.includes.matches_subtree(&target.to_string_lossy()))
// A pruned target is still followed, so the symlinks inside it resolve.
&& !prunes(&target)
&& !prunes(&target);
if crawled_directly
|| path
.ancestors()
.take(entry.depth)
.any(|dir| cached_canonicalize(dir).is_ok_and(|dir| dir == target))
{
entry.read_children = None;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/symlinks_out_of_root/root/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Outside the root, the crawl reports what's under a symlink by the path it reached it by, so it
# still follows these: one to a directory outside the root with a symlink inside it, and one from
# outside the root to a directory under it.
# outside the root to a directory under it. It stops at one to a directory it's already in.

export LC_ALL=C

Expand All @@ -21,5 +21,6 @@ mkdir -p ../other/sub
link ../other/sub other_sub
link ../../third ../other/sub/nested
link ../root/pkg ../other/to_root
link .. ../other/sub/up

assert_ok "$FLOW" ls --strip-root | sort
Loading