diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-27 06:02:59 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-27 06:02:59 +0800 |
| commit | 4eef9ce364bb660421a96052a3fb126a33b22c63 (patch) | |
| tree | a36947411d83205dc743881cd2a30d8c907d4b57 /utils/src/fs.rs | |
| parent | 243d521fd19af169910506529e737a797e9bc583 (diff) | |
Extract CLI utilities into a separate crate
Diffstat (limited to 'utils/src/fs.rs')
| -rw-r--r-- | utils/src/fs.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/utils/src/fs.rs b/utils/src/fs.rs new file mode 100644 index 0000000..0050cf1 --- /dev/null +++ b/utils/src/fs.rs @@ -0,0 +1,40 @@ +pub async fn move_across_partitions( + source_path: impl AsRef<std::path::Path>, + dest_path: impl AsRef<std::path::Path>, +) -> 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<std::path::Path>, + dest_path: impl AsRef<std::path::Path>, +) -> 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(()) +} |
