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
10 changes: 10 additions & 0 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
move_files_into_dir(&[source.clone()], target, b)
}
} else if target.exists() && source.is_dir() {
match b.overwrite {
OverwriteMode::NoClobber => return Ok(()),
OverwriteMode::Interactive => {
println!("{}: overwrite {}? ", uucore::util_name(), target.quote());
if !read_yes() {
return Ok(());
}
}
OverwriteMode::Force => {}
};
Err(MvError::NonDirectoryToDirectory(
source.quote().to_string(),
target.quote().to_string(),
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,19 @@ fn test_mv_errors() {
.fails()
.stderr_str()
.is_empty());

// $ at.mkdir dir && at.touch file
// $ mv -i dir file
// err == mv: cannot overwrite non-directory 'file' with directory 'dir'
assert!(!scene
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.

can you please create a separate new test for this?
easier to debug / identify regression

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.

I will do it instead :)

.ucmd()
.arg("-i")
.arg(dir)
.arg(file_a)
.pipe_in("y")
.fails()
.stderr_str()
.is_empty());
}

#[test]
Expand Down