Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@
return false;
}
if total_len == 0 {
// POSIX has no empty file name, yet some systems accept one as a way
// of writing the current directory. Rather than decide that here, ask
// the platform: keep the operand when `symlink_metadata` (`lstat`)
// resolves it, reject it when that fails.
if fs::symlink_metadata(&joined_path).is_err() {
// Some systems accept an empty file name as the current directory.
// Preserve that behavior except on WASI, where a preopen makes

Check warning on line 202 in src/uu/pathchk/src/pathchk.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'preopen' (file:'src/uu/pathchk/src/pathchk.rs', line:202)
// symlink_metadata("") succeed for an invalid empty path.
if cfg!(target_os = "wasi") || fs::symlink_metadata(&joined_path).is_err() {
show_error!("{}", translate!("pathchk-error-empty-path-not-found"));
return false;
}
Expand Down
21 changes: 8 additions & 13 deletions tests/by-util/test_pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@ fn test_default_mode() {
new_ucmd!().args(&["dir#/$file"]).succeeds().no_stdout();

// fail on empty path
// WASI's symlink_metadata("") returns Ok instead of ENOENT, so pathchk
// accepts the empty operand there.
#[cfg(not(wasi_runner))]
{
new_ucmd!()
.args(&[""])
.fails()
.stderr_only("pathchk: '': No such file or directory\n");
new_ucmd!()
.args(&[""])
.fails()
.stderr_only("pathchk: '': No such file or directory\n");

new_ucmd!().args(&["", ""]).fails().stderr_only(
"pathchk: '': No such file or directory\n\
pathchk: '': No such file or directory\n",
);
}
new_ucmd!().args(&["", ""]).fails().stderr_only(
"pathchk: '': No such file or directory\n\
pathchk: '': No such file or directory\n",
);

// fail on long path
new_ucmd!()
Expand Down
Loading