Skip to content

Commit

Permalink
Ignore invalid symlinks (#179)
Browse files Browse the repository at this point in the history
* swallowing invalid symlink errors to be consistent with packwerk

* bumping version to 0.1.92
  • Loading branch information
perryqh authored Apr 3, 2024
1 parent 0cddf6b commit 192eab1
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "pks"
version = "0.1.91"
version = "0.1.92"
edition = "2021"
description = "Welcome! Please see https://github.com/alexevanczuk/packs for more information!"
license = "MIT"
Expand Down
34 changes: 33 additions & 1 deletion src/packs/walk_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ pub(crate) fn walk_directory(
// .unwrap();
// writeln!(file, "{:?}", entry).unwrap();

let unwrapped_entry = entry?;
let unwrapped_entry = entry;
if let Err(_e) = unwrapped_entry {
// Encountered an invalid symlink. Being consistent with packwerk, which swallows this error and continues
continue;
}
let unwrapped_entry = unwrapped_entry.unwrap();

// Note that we could also get the dir from absolute_path.is_dir()
// However, this data appears to be cached on the FileType struct, so we'll use that instead,
Expand Down Expand Up @@ -228,4 +233,31 @@ mod tests {

Ok(())
}

#[test]
fn test_walk_directory_with_invalid_symlink() -> anyhow::Result<()> {
let absolute_path = PathBuf::from("tests/fixtures/app_with_symlink")
.canonicalize()
.expect("Could not canonicalize path");

let raw_config = RawConfiguration {
include: vec!["**/*".to_string()],
..RawConfiguration::default()
};

// deleting baz
// link-baz -> baz
let baz_path = absolute_path.join("packs/foo/app/services/baz");
let _ignore = std::fs::remove_dir_all(&baz_path);

let walk_directory_result =
walk_directory(absolute_path.clone(), &raw_config);

// Restoring baz
std::fs::create_dir_all(&baz_path)?;

assert!(walk_directory_result.is_ok());

Ok(())
}
}
3 changes: 3 additions & 0 deletions tests/fixtures/app_with_symlink/app/company_data/widget.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Company
class Widget end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class SomeRootClass; end
Empty file.
9 changes: 9 additions & 0 deletions tests/fixtures/app_with_symlink/packs/foo/app/services/foo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Foo
def calls_bar_without_a_stated_dependency
::Bar
end

def calls_baz_with_a_stated_dependency
Baz
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This defines ::Foo::Bar, which is different than ::Bar
module Foo
module Bar
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions tests/fixtures/app_with_symlink/packs/foo/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
enforce_dependencies: true
enforce_privacy: true
3 changes: 3 additions & 0 deletions tests/fixtures/app_with_symlink/packwerk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Whether or not you want the cache enabled (disabled by default)
cache: false

1 change: 1 addition & 0 deletions tests/fixtures/app_with_symlink/script/my_script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# some ruby script

0 comments on commit 192eab1

Please sign in to comment.