fix: set file times after writing to preserve source mtime

This commit is contained in:
jujuforce
2026-04-20 14:28:12 +02:00
parent 558c0ecec0
commit d719125ea3
+9 -6
View File
@@ -112,6 +112,15 @@ fn extract_exfat_elements(
let dest_path = output_dir.join(file.name());
let mut dest = File::create(&dest_path)?;
{
let mut writer = BufWriter::with_capacity(256 * 1024, &mut dest);
std::io::copy(file, &mut writer)?;
writer.flush()?;
}
pb.inc(file.len());
// set_times must run after writes — otherwise the kernel
// updates mtime/atime back to "now" when bytes are flushed.
let accessed = exfat_timestamp_to_system_time(file.timestamps().accessed());
let modified = exfat_timestamp_to_system_time(file.timestamps().modified());
if let (Ok(accessed), Ok(modified)) = (accessed, modified) {
@@ -126,12 +135,6 @@ fn extract_exfat_elements(
);
}
}
let mut writer = BufWriter::with_capacity(256 * 1024, &mut dest);
std::io::copy(file, &mut writer)?;
writer.flush()?;
pb.inc(file.len());
}
FsElement::D(directory) => {
let dest_path = output_dir.join(directory.name());