diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index c7813c08c71..02005f81b09 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -198,11 +198,10 @@ fn check_default(path: &[String]) -> bool { 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 + // 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; } diff --git a/tests/by-util/test_pathchk.rs b/tests/by-util/test_pathchk.rs index ceae18d87d8..8370ad5bc51 100644 --- a/tests/by-util/test_pathchk.rs +++ b/tests/by-util/test_pathchk.rs @@ -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!()