-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use Path fro Unix and str for Windows
- Loading branch information
1 parent
e512be4
commit 6068304
Showing
1 changed file
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
mod common; | ||
mod platform; | ||
|
||
use std::path::PathBuf; | ||
use common::utils::absolute; | ||
|
||
#[cfg(target_os = "windows")] | ||
use platform::windows::reflink_sync; | ||
|
||
#[cfg(target_os = "linux")] | ||
use reflink_copy::reflink as reflink_sync; | ||
|
||
#[cfg(target_os = "macos")] | ||
#[cfg(not(target_os = "windows"))] | ||
use reflink_copy::reflink as reflink_sync; | ||
|
||
pub fn reflink_file_sync(src: &str, dest: &str) -> std::io::Result<()> { | ||
reflink_sync( | ||
absolute(src)?.to_str().unwrap_or_default(), | ||
absolute(dest)?.to_str().unwrap_or_default(), | ||
) | ||
// Convert to absolute paths | ||
let src_abs: PathBuf = absolute(src)?; | ||
let dest_abs: PathBuf = absolute(dest)?; | ||
|
||
#[cfg(target_os = "windows")] | ||
{ | ||
let src_str = src_abs.to_str().unwrap_or_default(); | ||
let dest_str = dest_abs.to_str().unwrap_or_default(); | ||
reflink_sync(src_str, dest_str) | ||
} | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
{ | ||
reflink_sync(&src_abs, &dest_abs) | ||
} | ||
} |