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
1 change: 1 addition & 0 deletions .github/workflows/wasi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
test_ls::test_ls_a_dotdot_no_error_on_wasi \
test_ls::test_ls_al_no_capabilities_insufficient_on_wasi \
test_md5sum:: test_mkdir:: test_mktemp:: test_nl:: test_nproc:: test_numfmt:: test_od:: \
test_mv::test_mv_dir_into_file_where_both_are_files \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be necessary if we merged #15320 as we will run the whole mv command integration tests.

test_paste:: test_pathchk:: test_pr:: test_printenv:: test_printf:: test_ptx:: \
test_pwd:: test_rmdir:: test_sha1sum:: test_sha224sum:: test_sha256sum:: \
test_sha384sum:: test_sha512sum:: test_shred:: test_shuf:: test_sleep:: \
Expand Down
7 changes: 6 additions & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,12 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
)
.into());
}
let Ok(source_metadata) = source.symlink_metadata() else {
// WASI may return file metadata even when a trailing slash requires a directory.
let Some(source_metadata) = source
.symlink_metadata()
.ok()
.filter(|metadata| !metadata.is_file() || !path_ends_with_terminator(source))
else {
return Err(if path_ends_with_terminator(source) {
MvError::CannotStatNotADirectory(source.quote().to_string()).into()
} else {
Expand Down
12 changes: 8 additions & 4 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,14 +1917,18 @@ fn test_mv_seen_multiple_files_to_directory() {
fn test_mv_dir_into_file_where_both_are_files() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("a");
at.touch("b");
at.write("a", "source");
at.write("b", "target");
scene
.ucmd()
.arg("a/")
.arg("b")
.fails()
.stderr_contains("mv: cannot stat 'a/': Not a directory");
.fails_with_code(1)
.no_stdout()
.stderr_is("mv: cannot stat 'a/': Not a directory\n");

assert_eq!(at.read("a"), "source");
assert_eq!(at.read("b"), "target");
}

#[test]
Expand Down
Loading