Skip to content

Commit

Permalink
Using lstat instead of stat in -fstype
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdroychan committed Jul 12, 2024
1 parent d69d51e commit 4ae5e27
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/find/matchers/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub fn get_file_system_type(
) -> Result<String, Box<dyn Error>> {
use std::os::unix::fs::MetadataExt;

let metadata = match path.metadata() {
// use symlink_metadata (lstat under the hood) instead of metadata (stat) to make sure that it
// does not return an error when there is a (broken) symlink; this is aligned with GNU find.
let metadata = match path.symlink_metadata() {
Ok(metadata) => metadata,
Err(err) => Err(err)?,
};
Expand Down
13 changes: 13 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,19 @@ fn find_fs() {
.success()
.stdout(predicate::str::is_empty())
.stderr(predicate::str::is_empty());

let path = Path::new("./test_data/links");
let empty_cache = RefCell::new(None);
let target_fs_type = get_file_system_type(path, &empty_cache).unwrap();

// working with broken links
Command::cargo_bin("find")
.expect("found binary")
.args(["./test_data/links", "-fstype", &target_fs_type])
.assert()
.success()
.stdout(predicate::str::contains("./test_data/links/link-missing"))
.stderr(predicate::str::is_empty());
}

#[test]
Expand Down

0 comments on commit 4ae5e27

Please sign in to comment.