Skip to content

Commit

Permalink
readlink: symlink loop handling (uutils#3717)
Browse files Browse the repository at this point in the history
readlink: fix symlink loop handling
  • Loading branch information
niyaznigmatullin authored Jul 14, 2022
1 parent 882cd52 commit 0ea3a73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/uu/readlink/src/readlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if verbose {
return Err(USimpleError::new(
1,
format!("{}: errno {}", f.maybe_quote(), err.raw_os_error().unwrap()),
err.map_err_context(move || f.maybe_quote().to_string())
.to_string(),
));
} else {
return Err(1.into());
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_readlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ fn test_long_redirection_to_root() {
println!("expect: {:?}", expect);
assert_eq!(actual, expect);
}

#[test]
fn test_symlink_to_itself_verbose() {
let (at, mut ucmd) = at_and_ucmd!();
at.relative_symlink_file("a", "a");
ucmd.args(&["-ev", "a"])
.fails()
.code_is(1)
.stderr_contains("Too many levels of symbolic links");
}

0 comments on commit 0ea3a73

Please sign in to comment.