Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Big files copy to a network share at full speed again (938)

denfrya07fa88cc9eb
diff --git a/crates/rf-win/src/fastcopy.rs b/crates/rf-win/src/fastcopy.rs
index 41dbe892..4ca27ebf 100644
--- a/crates/rf-win/src/fastcopy.rs
+++ b/crates/rf-win/src/fastcopy.rs
@@ -499,6 +499,14 @@ fn hold_source(src: &Path) -> Option<std::fs::File> {
/// Sources at least this big are held while they are copied ([`hold_source`]).
const HOLD_MIN: u64 = 1 << 20;
+/// Whether a file is copied restartably ([`RESTARTABLE_MIN`]): with a journal, big enough, and not onto the network. On an SMB share
+/// Windows writes a restartable copy in 64 KB pieces instead of 1 MB ones, and a 2.5 GB file went at 35 MB/s instead of 100 (issue
+/// 938). A network copy cut off by a crash starts that one file over, as every file under 2 GB does; the journal still skips the
+/// files that were done.
+fn copies_restartably(journal: bool, size: u64, dst: &Path) -> bool {
+ journal && size >= RESTARTABLE_MIN && !crate::drives::is_network_path(dst)
+}
+
/// `restart`: carry on a restartable copy into an existing partial `dst`.
fn copy_file(src: &Path, dst: &Path, size: u64, run: &Run, restart: bool) -> windows::core::Result<()> {
// (let go when this returns: a move deletes the source after it). Only a file big enough to take a while is held: the second
@@ -510,7 +518,7 @@ fn copy_file(src: &Path, dst: &Path, size: u64, run: &Run, restart: bool) -> win
// Buffered, like Explorer: unbuffered writes of big files measured twice as slow
// (1 GB: 755 ms against Windows' 348 ms; buffered 285 against 265).
let mut flags = if restart { 0 } else { COPY_FILE_FAIL_IF_EXISTS.0 };
- if run.restartable && size >= RESTARTABLE_MIN {
+ if copies_restartably(run.restartable, size, dst) {
flags |= COPY_FILE_RESTARTABLE.0;
}
let ctx = FileCtx { run, name: src, sent: Cell::new(0) };
@@ -1366,6 +1374,20 @@ fn local_fs(p: &Path) -> bool {
#[cfg(test)]
mod tests {
+ /// Issue 938: a big file goes restartably to a local disk only; onto a share (by its name, long form or a mapped letter's kind)
+ /// it is copied plainly, in Windows' 1 MB pieces.
+ #[test]
+ fn only_big_files_to_a_local_disk_are_copied_restartably() {
+ use std::path::Path;
+ let big = super::RESTARTABLE_MIN;
+ let local = std::env::temp_dir().join("big.bin");
+ assert!(super::copies_restartably(true, big, &local));
+ assert!(!super::copies_restartably(true, big - 1, &local), "under 2 GB: plain");
+ assert!(!super::copies_restartably(false, big, &local), "no journal: plain");
+ assert!(!super::copies_restartably(true, big, Path::new(r"\\server\share\big.bin")));
+ assert!(!super::copies_restartably(true, big, Path::new(r"\\?\UNC\server\share\big.bin")));
+ }
+
/// Issue 608: while a file is copied it can't be deleted or renamed away, and can still be read and copied.
#[test]
fn a_file_being_copied_cannot_be_deleted() {