Repository navigation
chmod: preserve metadata errors for overlong paths #15499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,10 @@ use uucore::translate; | |
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| enum ChmodError { | ||
| #[error("{}", translate!("chmod-error-cannot-stat", "file" => _0.quote()))] | ||
| CannotStat(PathBuf), | ||
| #[error("{}", translate!("perms-cannot-access", "file" => _0.quote(), "error" => strip_errno(_1)))] | ||
| CannotStat(PathBuf, std::io::Error), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| #[error("{}", translate!("chmod-error-reference-stat", "file" => _0.quote(), "error" => strip_errno(_1)))] | ||
| ReferenceStat(PathBuf, std::io::Error), | ||
| #[error("{}", translate!("chmod-error-dangling-symlink", "file" => _0.quote()))] | ||
| DanglingSymlink(PathBuf), | ||
| #[error("{}", translate!("chmod-error-no-such-file", "file" => _0.quote()))] | ||
|
|
@@ -150,7 +152,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { | |
| Some(fref) => Some( | ||
| fs::metadata(fref) | ||
| .map(|meta| meta.mode() & 0o7777) | ||
| .map_err(|_| ChmodError::CannotStat(fref.into()))?, | ||
| .map_err(|err| ChmodError::ReferenceStat(fref.into(), err))?, | ||
| ), | ||
| None => None, | ||
| }; | ||
|
|
@@ -817,7 +819,7 @@ impl Chmoder { | |
| } else if err.kind() == std::io::ErrorKind::PermissionDenied { | ||
| Err(ChmodError::PermissionDenied(file.into()).into()) | ||
| } else { | ||
| Err(ChmodError::CannotStat(file.into()).into()) | ||
| Err(ChmodError::CannotStat(file.into(), err).into()) | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1865,3 +1865,35 @@ | |
| .no_output(); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_overlong_path_reports_os_error_and_continues() { | ||
| let ts = TestScenario::new(util_name!()); | ||
| ts.fixtures.touch("valid"); | ||
| // Every component exists, but the unnormalized operand exceeds PATH_MAX. | ||
| let path = "./".repeat(4096); | ||
| let error = uucore::error::strip_errno(&std::io::Error::from_raw_os_error(libc::ENAMETOOLONG)); | ||
| for flags in [vec![], vec!["-R"]] { | ||
| set_permissions(ts.fixtures.plus("valid"), Permissions::from_mode(0o600)).unwrap(); | ||
| let result = ts | ||
| .ucmd() | ||
| .args(&flags) | ||
| .arg("700") | ||
| .arg(&path) | ||
| .arg("valid") | ||
| .fails_with_code(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check the whole message ("cannot access ...: File name too long"), not only the errno |
||
| result.stderr_is(format!("chmod: cannot access '{path}': {error}\n")); | ||
| assert_eq!( | ||
| ts.fixtures.metadata("valid").permissions().mode() & 0o777, | ||
| 0o700 | ||
| ); | ||
| } | ||
| ts.ucmd() | ||
| .arg("--reference") | ||
| .arg(&path) | ||
| .arg("valid") | ||
| .fails_with_code(1) | ||
| .stderr_is(format!( | ||
| "chmod: failed to get attributes of '{path}': {error}\n" | ||
| )); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for --reference GNU says "failed to get attributes of 'x': ...", not "cannot access"
could you please keep a separate variant for the reference file?