Implement reflink copy with automatic fallback for faster tree copying#557
Conversation
|
@copilot Nice. Also mention this in NEWS.md. |
Added to NEWS.md in commit 7c3b7c7. |
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
…r reflink errors Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
b2e14bf to
362af15
Compare
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements reflink (copy-on-write) support for the tree copying operation to improve performance on filesystems that support it, with automatic fallback to regular copying when not supported.
- Adds
reflinkcrate dependency for copy-on-write file operations - Implements smart reflink detection with fallback mechanism using
AtomicBool - Adds debug logging to indicate reflink support status and usage
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/copy_tree.rs | Implements the core reflink functionality with copy_file helper and reflink support detection |
| NEWS.md | Documents the reflink optimization feature in the changelog |
| Cargo.toml | Adds reflink crate dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| patch = "0.7" | ||
| path-slash = "0.2" | ||
| quote = "1.0.35" | ||
| reflink = "0.1" |
There was a problem hiding this comment.
Consider using a more specific version constraint like reflink = \"0.1.3\" to match the version mentioned in the PR description, ensuring consistent dependency resolution.
| reflink = "0.1" | |
| reflink = "0.1.3" |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/copy_tree.rs
Outdated
|
|
||
| /// Copy a file, attempting to use reflink if supported. | ||
| /// Returns the number of bytes copied. | ||
| fn copy_file(src: &Path, dest: &Path, reflink_supported: &AtomicBool) -> anyhow::Result<u64> { |
There was a problem hiding this comment.
Changed to crate::Result in commit ea4c3f2.
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
src/copy_tree.rs
Outdated
| } | ||
| Err(e) => { | ||
| // Check if this is a "not supported" error | ||
| if e.kind() == ErrorKind::Unsupported { |
There was a problem hiding this comment.
@copilot It looks like on Windows it can fail as unsupported without returning this error. Let's give up on using reflinks the first time we see an error of any kind, still emitting a debug message with the error. Add a comment about this.
There was a problem hiding this comment.
Changed to give up on reflinks after any error in commit a8f7b29. Added comment explaining Windows behavior and removed the now-unused ErrorKind import.
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Plan: Implement Reflink Copy Support
reflinkcrate to Cargo.toml dependenciescopy_tree.rsto use reflink for file copying with fallbackImplementation Summary
Successfully implemented reflink copy support with automatic fallback to regular copying:
Changes Made:
Added
reflinkcrate (v0.1.3) toCargo.tomldependenciesCreated
copy_filehelper function that:reflink::reflink()first for fast copy-on-write operationsErrorKind::Unsupported) to handle Windows behavior where reflink can fail without returning the expected error kinddebug!before falling back (appropriate since users can't do anything about them)fs::copy()when reflinks failAtomicBoolto track support so we don't retry reflink after detecting it's not workingcrate::Resultfor consistency with the rest of the codebaseAdded debug logging:
debug!()with error details when reflink failsreflink_usedboolean fieldCode quality improvements:
Path,fs) instead of fully qualified namesDocumentation:
How It Works:
ErrorKind::Unsupported)Fixes #473
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.