From 0a95bae451c1847f4f0b9601e60959f4e8e6b669 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 12 Mar 2026 14:28:08 +0800 Subject: Refactor display utilities --- utils/src/legacy/fs.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 utils/src/legacy/fs.rs (limited to 'utils/src/legacy/fs.rs') diff --git a/utils/src/legacy/fs.rs b/utils/src/legacy/fs.rs new file mode 100644 index 0000000..0050cf1 --- /dev/null +++ b/utils/src/legacy/fs.rs @@ -0,0 +1,40 @@ +pub async fn move_across_partitions( + source_path: impl AsRef, + dest_path: impl AsRef, +) -> Result<(), std::io::Error> { + let source_path = source_path.as_ref(); + let dest_path = dest_path.as_ref(); + if !source_path.exists() { + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Source file does not exist", + )); + } + + if let Ok(()) = std::fs::rename(source_path, dest_path) { + return Ok(()); + } + + std::fs::copy(source_path, dest_path)?; + std::fs::remove_file(source_path)?; + + Ok(()) +} + +pub async fn copy_across_partitions( + source_path: impl AsRef, + dest_path: impl AsRef, +) -> Result<(), std::io::Error> { + let source_path = source_path.as_ref(); + let dest_path = dest_path.as_ref(); + if !source_path.exists() { + return Err(std::io::Error::new( + std::io::ErrorKind::NotFound, + "Source file does not exist", + )); + } + + std::fs::copy(source_path, dest_path)?; + + Ok(()) +} -- cgit