From a241d32991d5f393ae0d93d0ed589afcf3ebfd49 Mon Sep 17 00:00:00 2001 From: Noam Yorav-Raphael Date: Wed, 26 Jun 2024 15:55:02 +0300 Subject: [PATCH] Try to fix non-linux targets --- fuc_engine/src/ops/copy.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fuc_engine/src/ops/copy.rs b/fuc_engine/src/ops/copy.rs index e231b99..565d9df 100644 --- a/fuc_engine/src/ops/copy.rs +++ b/fuc_engine/src/ops/copy.rs @@ -604,10 +604,14 @@ mod compat { Error, }; - struct Impl; + struct Impl { + dereference: bool, + } - pub fn copy_impl<'a, 'b>() -> impl DirectoryOp<(Cow<'a, Path>, Cow<'b, Path>)> { - Impl + pub fn copy_impl<'a, 'b>( + dereference: bool, + ) -> impl DirectoryOp<(Cow<'a, Path>, Cow<'b, Path>)> { + Impl { dereference } } impl DirectoryOp<(Cow<'_, Path>, Cow<'_, Path>)> for Impl { @@ -616,6 +620,8 @@ mod compat { &from, to, #[cfg(unix)] + self.dereference, + #[cfg(unix)] None, ) .map_io_err(|| format!("Failed to copy directory: {from:?}")) @@ -629,6 +635,7 @@ mod compat { fn copy_dir, Q: AsRef>( from: P, to: Q, + #[cfg(unix)] dereference: bool, #[cfg(unix)] root_to_inode: Option, ) -> Result<(), io::Error> { let to = to.as_ref(); @@ -654,11 +661,16 @@ mod compat { } let to = to.join(dir_entry.file_name()); - let file_type = dir_entry.file_type()?; + let mut file_type = dir_entry.file_type()?; + #[cfg(unix)] + if dereference && file_type.is_symlink() { + file_type = fs::metadata(dir_entry.file_name())?.file_type(); + } + let file_type = file_type; #[cfg(unix)] if file_type.is_dir() { - copy_dir(dir_entry.path(), to, root_to_inode)?; + copy_dir(dir_entry.path(), to, dereference, root_to_inode)?; } else if file_type.is_symlink() { std::os::unix::fs::symlink(fs::read_link(dir_entry.path())?, to)?; } else {