Skip to content

Commit bb01651

Browse files
Copilotsourcefrog
andcommitted
Address code review feedback: use short type names and add warning for reflink errors
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
1 parent cc98829 commit bb01651

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/copy_tree.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
//! Copy a source tree, with some exclusions, to a new temporary directory.
44
5+
use std::fs;
6+
use std::io::ErrorKind;
7+
use std::path::Path;
58
use std::sync::atomic::{AtomicBool, Ordering};
69

710
use anyhow::Context;
@@ -27,30 +30,32 @@ static VCS_DIRS: &[&str] = &[".git", ".hg", ".bzr", ".svn", "_darcs", ".jj", ".p
2730

2831
/// Copy a file, attempting to use reflink if supported.
2932
/// Returns the number of bytes copied.
30-
fn copy_file(src: &std::path::Path, dest: &std::path::Path, reflink_supported: &AtomicBool) -> anyhow::Result<u64> {
33+
fn copy_file(src: &Path, dest: &Path, reflink_supported: &AtomicBool) -> anyhow::Result<u64> {
3134
// Try reflink first if we haven't determined it's not supported
3235
if reflink_supported.load(Ordering::Relaxed) {
3336
match reflink::reflink(src, dest) {
3437
Ok(()) => {
3538
// Reflink succeeded, get file size for progress tracking
36-
let metadata = std::fs::metadata(dest)
39+
let metadata = fs::metadata(dest)
3740
.with_context(|| format!("Failed to get metadata for {}", dest.display()))?;
3841
return Ok(metadata.len());
3942
}
4043
Err(e) => {
4144
// Check if this is a "not supported" error
42-
if e.kind() == std::io::ErrorKind::Unsupported {
45+
if e.kind() == ErrorKind::Unsupported {
4346
// Mark reflink as not supported so we don't try again
4447
reflink_supported.store(false, Ordering::Relaxed);
4548
debug!("Reflinks not supported on this filesystem, falling back to regular copy");
49+
} else {
50+
// Log other errors
51+
warn!("Reflink failed: {}, falling back to regular copy", e);
4652
}
47-
// For other errors, also fall back to regular copy
4853
}
4954
}
5055
}
5156

5257
// Fall back to regular copy
53-
std::fs::copy(src, dest)
58+
fs::copy(src, dest)
5459
.with_context(|| format!("Failed to copy {} to {}", src.display(), dest.display()))
5560
}
5661

0 commit comments

Comments
 (0)