Skip to content

Commit

Permalink
Log infinite symlink offender (#20985)
Browse files Browse the repository at this point in the history
Gave this a stab since I have infinite free time now, ~~but I have no
idea how to see the warning output in tests~~.

Figured out the (seemingly) only way to see log output in tests is by
using the `env_logger` crate and running with the `RUST_LOG=warn` env
var set. The following command spits out the subsequent log messages in
the tests: `RUST_LOG=warn ./cargo test -p fs -- --nocapture`

```
[2024-06-04T17:37:12Z WARN  fs::directory] Exceeded the maximum link depth while traversing link `self` to path ".". Stopping traversal.
[2024-06-04T17:37:12Z WARN  fs::directory] Exceeded the maximum link depth while traversing link `self` to path ".". Stopping traversal.
```

---------

Co-authored-by: Huon Wilson <huon@exoflare.io>
  • Loading branch information
ndellosa95 and huonw authored Jan 10, 2025
1 parent 863b229 commit c4da187
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/engine/fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ workunit_store = { path = "../workunit_store" }
[dev-dependencies]
tempfile = { workspace = true }
tokio = { workspace = true, features = ["rt", "macros"] }
env_logger = { workspace = true }

[lints]
workspace = true
12 changes: 10 additions & 2 deletions src/rust/engine/fs/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,15 @@ impl DigestTrie {
link_depth += 1;
if s.target == Component::CurDir.as_os_str() {
if link_depth >= MAX_LINK_DEPTH {
warn!("Exceeded the maximum link depth while traversing links. Stopping traversal.");
let mut logical_path = PathBuf::new();
for component in path_so_far.components() {
let cs = component.as_os_str();
logical_path.push(cs);
if cs == entry.name().as_str() {
break;
}
}
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
return;
}
self.walk_helper(root, path.clone(), symlink_behavior, link_depth, f);
Expand Down Expand Up @@ -958,7 +966,7 @@ impl DigestTrie {

if let Some(Entry::Symlink(s)) = maybe_matching_entry {
if link_depth >= MAX_LINK_DEPTH {
warn!("Exceeded the maximum link depth while traversing links. Stopping traversal.");
warn!("Exceeded the maximum link depth while traversing link {:#?} to path {:#?}. Stopping traversal.", logical_path, s.target);
return Ok(None);
}

Expand Down

0 comments on commit c4da187

Please sign in to comment.