Fix mv data loss when changing folder case (step 1) (#6599)

* Fix mv data loss when changing folder case (step 1)

* Use same-file to detect when changing case on Windows
This commit is contained in:
Reilly Wood
2022-09-23 11:09:31 -07:00
committed by GitHub
parent d323ac3edc
commit 848550771a
4 changed files with 65 additions and 1 deletions

View File

@ -253,8 +253,12 @@ fn move_file(
return Err(ShellError::DirectoryNotFound(to_span, None));
}
// This can happen when changing case on a case-insensitive filesystem (ex: changing foo to Foo on Windows)
// When it does, we want to do a plain rename instead of moving `from` into `to`
let from_to_are_same_file = same_file::is_same_file(&from, &to).unwrap_or(false);
let mut to = to;
if to.is_dir() {
if !from_to_are_same_file && to.is_dir() {
let from_file_name = match from.file_name() {
Some(name) => name,
None => return Err(ShellError::DirectoryNotFound(to_span, None)),