Fix move file to diffrent partition on Windows

This commit is contained in:
uma0317 2019-11-15 11:52:51 +09:00
parent aa1ef39da3
commit 0756145caf

View file

@ -623,6 +623,8 @@ impl Shell for FilesystemShell {
} }
if entry.is_file() { if entry.is_file() {
#[cfg(not(windows))]
{
match std::fs::rename(&entry, &destination) { match std::fs::rename(&entry, &destination) {
Err(e) => { Err(e) => {
return Err(ShellError::labeled_error( return Err(ShellError::labeled_error(
@ -644,6 +646,49 @@ impl Shell for FilesystemShell {
Ok(o) => o, Ok(o) => o,
}; };
} }
#[cfg(windows)]
{
match std::fs::copy(&entry, &destination) {
Err(e) => {
return Err(ShellError::labeled_error(
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
name_tag,
));
}
Ok(_) => match std::fs::remove_file(&entry) {
Err(e) => {
return Err(ShellError::labeled_error(
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
name_tag,
));
}
Ok(o) => o,
},
};
}
}
if entry.is_dir() { if entry.is_dir() {
match std::fs::create_dir_all(&destination) { match std::fs::create_dir_all(&destination) {
@ -745,7 +790,25 @@ impl Shell for FilesystemShell {
} }
if src.is_file() { if src.is_file() {
match std::fs::rename(src, dst) { match std::fs::copy(&src, &dst) {
Err(e) => {
return Err(ShellError::labeled_error(
format!(
"Rename {:?} to {:?} aborted. {:}",
src,
destination_file_name,
e.to_string(),
),
format!(
"Rename {:?} to {:?} aborted. {:}",
src,
destination_file_name,
e.to_string(),
),
name_tag,
));
}
Ok(_) => match std::fs::remove_file(&src) {
Err(e) => { Err(e) => {
return Err(ShellError::labeled_error( return Err(ShellError::labeled_error(
format!( format!(
@ -764,7 +827,8 @@ impl Shell for FilesystemShell {
)); ));
} }
Ok(o) => o, Ok(o) => o,
} },
};
} }
} }
@ -824,6 +888,8 @@ impl Shell for FilesystemShell {
to.push(entry_file_name); to.push(entry_file_name);
if entry.is_file() { if entry.is_file() {
#[cfg(not(windows))]
{
match std::fs::rename(&entry, &to) { match std::fs::rename(&entry, &to) {
Err(e) => { Err(e) => {
return Err(ShellError::labeled_error( return Err(ShellError::labeled_error(
@ -845,6 +911,49 @@ impl Shell for FilesystemShell {
Ok(o) => o, Ok(o) => o,
}; };
} }
#[cfg(windows)]
{
match std::fs::copy(&entry, &to) {
Err(e) => {
return Err(ShellError::labeled_error(
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
format!(
"Rename {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
name_tag,
));
}
Ok(_) => match std::fs::remove_file(&entry) {
Err(e) => {
return Err(ShellError::labeled_error(
format!(
"Remove {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
format!(
"Remove {:?} to {:?} aborted. {:}",
entry_file_name,
destination_file_name,
e.to_string(),
),
name_tag,
));
}
Ok(o) => o,
},
};
}
}
} }
} }
} else { } else {