Skip to content

Commit

Permalink
Try to fix non-linux targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Yorav-Raphael committed Jun 26, 2024
1 parent bf3e0e1 commit a241d32
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions fuc_engine/src/ops/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -616,6 +620,8 @@ mod compat {
&from,
to,
#[cfg(unix)]
self.dereference,
#[cfg(unix)]
None,
)
.map_io_err(|| format!("Failed to copy directory: {from:?}"))
Expand All @@ -629,6 +635,7 @@ mod compat {
fn copy_dir<P: AsRef<Path>, Q: AsRef<Path>>(
from: P,
to: Q,
#[cfg(unix)] dereference: bool,
#[cfg(unix)] root_to_inode: Option<u64>,
) -> Result<(), io::Error> {
let to = to.as_ref();
Expand All @@ -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 {
Expand Down

0 comments on commit a241d32

Please sign in to comment.