From 1180905b5e8746cc480638be4929aa524fcf725b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 26 Dec 2024 16:43:53 +0100 Subject: [PATCH 1/2] cp: use the function from uucore --- src/uu/cp/Cargo.toml | 1 + src/uu/cp/src/cp.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 6801e6a0960..3912f3308a5 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -30,6 +30,7 @@ uucore = { workspace = true, features = [ "backup-control", "entries", "fs", + "fsxattr", "perms", "mode", "update-control", diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 32168b09009..2f1f1ef1e07 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -17,6 +17,8 @@ use std::os::unix::ffi::OsStrExt; #[cfg(unix)] use std::os::unix::fs::{FileTypeExt, PermissionsExt}; use std::path::{Path, PathBuf, StripPrefixError}; +#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] +use uucore::fsxattr::copy_xattrs; use clap::{builder::ValueParser, crate_version, Arg, ArgAction, ArgMatches, Command}; use filetime::FileTime; @@ -1603,16 +1605,11 @@ pub(crate) fn copy_attributes( })?; handle_preserve(&attributes.xattr, || -> CopyResult<()> { - #[cfg(all(unix, not(target_os = "android")))] + #[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] { - let xattrs = xattr::list(source)?; - for attr in xattrs { - if let Some(attr_value) = xattr::get(source, attr.clone())? { - xattr::set(dest, attr, &attr_value[..])?; - } - } + copy_xattrs(source, dest)?; } - #[cfg(not(all(unix, not(target_os = "android"))))] + #[cfg(not(all(unix, not(any(target_os = "android", target_os = "macos")))))] { // The documentation for GNU cp states: // From 2deeb7882c58f6ed457bd40bd93f93ab70341b11 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 26 Dec 2024 17:10:01 +0100 Subject: [PATCH 2/2] xattr feature: enable it on mac too --- src/uu/cp/src/cp.rs | 6 +++--- src/uucore/src/lib/features.rs | 2 +- src/uucore/src/lib/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 2f1f1ef1e07..b7469404757 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -17,7 +17,7 @@ use std::os::unix::ffi::OsStrExt; #[cfg(unix)] use std::os::unix::fs::{FileTypeExt, PermissionsExt}; use std::path::{Path, PathBuf, StripPrefixError}; -#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] +#[cfg(all(unix, not(target_os = "android")))] use uucore::fsxattr::copy_xattrs; use clap::{builder::ValueParser, crate_version, Arg, ArgAction, ArgMatches, Command}; @@ -1605,11 +1605,11 @@ pub(crate) fn copy_attributes( })?; handle_preserve(&attributes.xattr, || -> CopyResult<()> { - #[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] + #[cfg(all(unix, not(target_os = "android")))] { copy_xattrs(source, dest)?; } - #[cfg(not(all(unix, not(any(target_os = "android", target_os = "macos")))))] + #[cfg(not(all(unix, not(target_os = "android"))))] { // The documentation for GNU cp states: // diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index dfe5b773312..cde1cf264a3 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -54,7 +54,7 @@ pub mod process; #[cfg(all(target_os = "linux", feature = "tty"))] pub mod tty; -#[cfg(all(unix, not(target_os = "macos"), feature = "fsxattr"))] +#[cfg(all(unix, feature = "fsxattr"))] pub mod fsxattr; #[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))] pub mod signals; diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 3200145bd73..3a6a537ad49 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -99,7 +99,7 @@ pub use crate::features::wide; #[cfg(feature = "fsext")] pub use crate::features::fsext; -#[cfg(all(unix, not(target_os = "macos"), feature = "fsxattr"))] +#[cfg(all(unix, feature = "fsxattr"))] pub use crate::features::fsxattr; //## core functions