1use std::fs::File;
7use std::io::{self, copy};
8use std::path::Path;
9
10pub fn copy_file_cifs_safe(source: &Path, destination: &Path) -> io::Result<u64> {
20 let mut src = File::open(source)?;
21 let mut dst = File::create(destination)?;
22 copy(&mut src, &mut dst)
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28 use std::fs;
29 use tempfile::TempDir;
30
31 #[test]
32 fn test_copy_file_cifs_safe() -> io::Result<()> {
33 let temp = TempDir::new()?;
34 let src_path = temp.path().join("src.txt");
35 let dst_path = temp.path().join("dst.txt");
36 let content = b"hello cifs safe copy";
37 fs::write(&src_path, content)?;
38 let bytes = copy_file_cifs_safe(&src_path, &dst_path)?;
39 assert_eq!(bytes as usize, content.len());
40 let copied = fs::read(&dst_path)?;
41 assert_eq!(copied, content);
42 Ok(())
43 }
44}