Skip to content

Commit 0d9bc2f

Browse files
committed
Improve error messages in copy_content_recursive/rename_with_fallback_across_devices
1 parent 9365cf0 commit 0d9bc2f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

crates/backend/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![deny(unused_must_use)]
22

33
mod backend;
4-
use std::{ffi::{OsStr, OsString}, io::{ErrorKind, Write}, path::{Path, PathBuf}, sync::Arc};
4+
use std::{ffi::{OsStr, OsString}, io::{Error, ErrorKind, Write}, path::{Path, PathBuf}, sync::Arc};
55

66
pub use backend::*;
77
use bridge::instance::InstanceContentSummary;
@@ -228,7 +228,7 @@ pub fn copy_content_recursive(from: &Path, to: &Path) -> std::io::Result<()> {
228228
let path = entry.path();
229229
let file_type = entry.file_type()?;
230230
let Ok(relative) = path.strip_prefix(&from) else {
231-
return Err(ErrorKind::Other.into());
231+
return Err(Error::new(ErrorKind::Other, format!("{path:?} is not a child of {from:?}")));
232232
};
233233
if file_type.is_symlink() {
234234
let target = std::fs::read_link(&path)?;
@@ -272,7 +272,8 @@ pub fn copy_content_recursive(from: &Path, to: &Path) -> std::io::Result<()> {
272272
copied_bytes += std::fs::copy(copy_from, dest)?;
273273
}
274274
if copied_bytes != total_bytes {
275-
return Err(ErrorKind::Interrupted.into());
275+
return Err(Error::new(ErrorKind::Other,
276+
format!("Expected copy size did not match. Expected to copy {total_bytes} bytes, copied {copied_bytes} instead")));
276277
}
277278
for (relative, internal) in internal_symlinks {
278279
let dest = to.join(relative);
@@ -345,7 +346,7 @@ pub fn rename_with_fallback_across_devices(from: &Path, to: &Path) -> std::io::R
345346
std::fs::copy(from, to)?;
346347
_ = std::fs::remove_file(from);
347348
} else {
348-
return Err(ErrorKind::InvalidInput.into());
349+
return Err(Error::new(ErrorKind::Other, format!("{from} is not a symlink, file or folder")));
349350
}
350351
return Ok(());
351352
}

0 commit comments

Comments
 (0)