Skip to content

Commit

Permalink
fix: use Path fro Unix and str for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Oct 20, 2023
1 parent e512be4 commit 6068304
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/lib.rs
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)
}
}

0 comments on commit 6068304

Please sign in to comment.