diff --git a/Cargo.toml b/Cargo.toml index 621d038d17c..bc7f0abd0d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -412,7 +412,7 @@ uutils_term_grid = "0.8" walkdir = "2.5" wild = "2.2.1" windows-sys = { version = "0.61.0", default-features = false } -xattr = "1.3.1" +xattr = { version = "1.3.1", default-features = false } z85 = "3.0.5" zip = { version = "8.0.0", default-features = false, features = ["deflate"] } diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index dc44151290c..8dad49ac17e 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -24,7 +24,6 @@ uucore = { workspace = true, features = [ "buf-copy", "entries", "fs", - "fsxattr", "parser", "perms", "mode", @@ -36,6 +35,9 @@ indicatif = { workspace = true } thiserror = { workspace = true } fluent = { workspace = true } +[target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "macos", target_os = "netbsd"))'.dependencies] +uucore = { workspace = true, features = ["fsxattr"] } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] selinux = { workspace = true, optional = true } diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 1aea1711349..321dc3c8b56 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -17,7 +17,13 @@ use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt}; use std::os::unix::net::UnixListener; use std::path::{Path, PathBuf, StripPrefixError}; use std::{fmt, io}; -#[cfg(all(unix, not(target_os = "android")))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "macos", + target_os = "netbsd" +))] use uucore::fsxattr::{copy_acls, copy_xattrs_fd, copy_xattrs_skip_selinux}; use uucore::translate; @@ -1802,7 +1808,13 @@ pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> Copy /// or if xattr copying fails. /// /// Uses file descriptor-based operations to avoid TOCTOU races during xattr copying. -#[cfg(all(unix, not(target_os = "android")))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "macos", + target_os = "netbsd" +))] fn copy_extended_attrs(source: &Path, dest: &Path, skip_selinux: bool) -> CopyResult<()> { use std::fs::File; use uucore::fsxattr::copy_xattrs; @@ -1957,7 +1969,13 @@ pub(crate) fn copy_attributes( // (which are intentionally excluded from the default -p set per // issue #9704). Best-effort: ignore failures on filesystems that // do not support ACL xattrs. - #[cfg(all(unix, not(target_os = "android")))] // todo: support acl for other targets + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "macos", + target_os = "netbsd" + ))] copy_acls(source, dest); } @@ -2020,11 +2038,23 @@ pub(crate) fn copy_attributes( })?; handle_preserve(attributes.xattr, || -> CopyResult<()> { - #[cfg(all(unix, not(target_os = "android")))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "macos", + target_os = "netbsd" + ))] { copy_extended_attrs(source, dest, skip_selinux_xattr)?; } - #[cfg(not(all(unix, not(target_os = "android"))))] + #[cfg(not(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "macos", + target_os = "netbsd" + )))] #[allow(unused_variables)] { // The documentation for GNU cp states: diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index 388639fbbf0..c71ac50e3d5 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -31,7 +31,6 @@ uucore = { workspace = true, features = [ "format", "fs", "fsext", - "fsxattr", "i18n-collator", "parser-size", "parser-glob", @@ -42,6 +41,9 @@ uucore = { workspace = true, features = [ uutils_term_grid = { workspace = true } fluent = { workspace = true } +[target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "netbsd"))'.dependencies] +uucore = { workspace = true, features = ["fsxattr"] } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] selinux = { workspace = true, optional = true } diff --git a/src/uu/ls/src/colors.rs b/src/uu/ls/src/colors.rs index 2db405c1b0f..cd0b7cccd24 100644 --- a/src/uu/ls/src/colors.rs +++ b/src/uu/ls/src/colors.rs @@ -535,7 +535,12 @@ pub(crate) fn color_name( wrap: bool, ) -> OsString { // Check if the file has capabilities - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" + ))] { // Skip checking capabilities if LS_COLORS=ca=: let has_capabilities = style_manager diff --git a/src/uu/ls/src/display.rs b/src/uu/ls/src/display.rs index f1378fccda1..4d17562b614 100644 --- a/src/uu/ls/src/display.rs +++ b/src/uu/ls/src/display.rs @@ -33,7 +33,12 @@ use term_grid::{DEFAULT_SEPARATOR_SIZE, Direction, Filling, Grid, GridOptions}; #[cfg(unix)] use uucore::entries; -#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" +))] use uucore::fsxattr::has_acl; #[cfg(unix)] use uucore::libc::{dev_t, major, minor}; @@ -978,10 +983,20 @@ fn display_item_long( } if let Some(md) = item.metadata() { - #[cfg(any(not(unix), target_vendor = "apple", target_os = "android"))] + #[cfg(not(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" + )))] // TODO: See how Mac should work here let is_acl_set = false; - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" + ))] let is_acl_set = has_acl(item.path(), item.must_dereference); state .display_buf @@ -1375,10 +1390,20 @@ fn calculate_padding_collection( // the permissions column by one to reserve space for the `+`/`.` // indicator. { - #[cfg(any(not(unix), target_vendor = "apple", target_os = "android"))] + #[cfg(not(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" + )))] // TODO: See how Mac should work here let is_acl_set = false; - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "android"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "netbsd" + ))] let is_acl_set = has_acl(item.path(), item.must_dereference); if context_len > 1 || is_acl_set { padding_collections.permissions = PERMISSIONS_WIDTH + 1; diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index 4060cf7bbb5..576d3a99a4e 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -26,13 +26,15 @@ uucore = { workspace = true, features = [ "backup-control", "buf-copy", "fs", - "fsxattr", "perms", "safe-copy", "update-control", ] } fluent = { workspace = true } +[target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "android", target_os = "netbsd"))'.dependencies] +uucore = { workspace = true, features = ["fsxattr"] } + [target.'cfg(windows)'.dependencies] windows-sys = { workspace = true, features = [ "Win32_Foundation", diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index f17a06ccf5e..3536c54a737 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -16,7 +16,13 @@ use clap::error::ErrorKind; use clap::{Arg, ArgAction, ArgMatches, Command}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; -#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "redox"))))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" +))] use rustc_hash::FxHashMap; use rustc_hash::FxHashSet; use std::env; @@ -45,7 +51,13 @@ use uucore::fs::{ MissingHandling, ResolveMode, are_hardlinks_or_one_way_symlink_to_same_file, are_hardlinks_to_same_file, canonicalize, path_ends_with_terminator, }; -#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "redox"))))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" +))] use uucore::fsxattr; #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] use uucore::selinux::set_selinux_security_context; @@ -1038,7 +1050,13 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> { } Err(e) => return Err(e), } - #[cfg(not(any(target_vendor = "apple", target_os = "redox")))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] { let _ = fsxattr::copy_xattrs_ignore_unsupported(from, to); } @@ -1101,7 +1119,13 @@ fn rename_dir_fallback( // Retrieve xattrs through a file descriptor so a concurrent renamer cannot // redirect the list/get calls to a different inode. - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "redox"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] let xattrs = { use std::fs::File; File::open(from) @@ -1128,7 +1152,13 @@ fn rename_dir_fallback( // // The fd is opened read-only: a directory cannot be opened for writing, and // fsetxattr checks write permission on the inode, not the open mode. - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "redox"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] { use std::fs::File; let dest = File::open(to)?; @@ -1353,7 +1383,13 @@ fn copy_file_with_hardlinks_helper( // Copy a regular file. fs::copy(from, to)?; // Copy xattrs, ignoring ENOTSUP errors (filesystem doesn't support xattrs) - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "redox"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] { let _ = fsxattr::copy_xattrs_ignore_unsupported(from, to); } @@ -1418,7 +1454,13 @@ fn rename_file_fallback( uucore::buf_copy::copy_fast(&mut &src_file, &mut dst_file) .map_err(|err| io::Error::new(err.kind(), translate!("mv-error-permission-denied")))?; - #[cfg(not(any(target_vendor = "apple", target_os = "redox")))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] { let _ = fsxattr::copy_xattrs_fd_ignore_unsupported(&src_file, &dst_file); } diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index cf6c28f06b8..3f8841b6555 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -88,6 +88,9 @@ thiserror = { workspace = true } [dev-dependencies] tempfile = { workspace = true } +[target.'cfg(any(target_os = "freebsd", target_os = "hurd", target_os = "linux", target_os = "android", target_os = "macos", target_os = "netbsd"))'.dependencies] +xattr = { version = "1.3.1", optional = true } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] selinux = { workspace = true, optional = true } @@ -107,7 +110,6 @@ time = { workspace = true, optional = true, features = [ ] } nix = { workspace = true, optional = true } walkdir = { workspace = true, optional = true } -xattr = { workspace = true, optional = true } [target.'cfg(target_os = "linux")'.dependencies] procfs = { workspace = true, optional = true } diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 8462ac804be..e8b82567ad5 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -95,7 +95,17 @@ pub mod safe_traversal; #[cfg(all(target_os = "linux", feature = "tty"))] pub mod tty; -#[cfg(all(unix, feature = "fsxattr"))] +#[cfg(all( + feature = "fsxattr", + any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "macos", + target_os = "netbsd" + ) +))] pub mod fsxattr; #[cfg(feature = "hardware")] pub mod hardware; diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 8ba7636c551..53781b7f92a 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -147,7 +147,17 @@ pub use crate::features::wide; #[cfg(feature = "fsext")] pub use crate::features::fsext; -#[cfg(all(unix, feature = "fsxattr"))] +#[cfg(all( + feature = "fsxattr", + any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "macos", + target_os = "netbsd" + ) +))] pub use crate::features::fsxattr; #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] diff --git a/tests/uutests/Cargo.toml b/tests/uutests/Cargo.toml index 7a8f65ddab0..7c04aa1edb8 100644 --- a/tests/uutests/Cargo.toml +++ b/tests/uutests/Cargo.toml @@ -39,7 +39,7 @@ uucore = { workspace = true, features = [ nix = { workspace = true, features = ["fs", "term"] } rlimit = { workspace = true } -[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "openbsd"))))'.dependencies] +[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "openbsd"))))'.dependencies] xattr = { workspace = true } [lints] diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index a8152cbba8a..06377a77fc7 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -998,7 +998,13 @@ pub fn get_root_path() -> &'static str { /// # Returns /// /// `true` if both paths have the same set of extended attributes, `false` otherwise. -#[cfg(all(unix, not(any(target_vendor = "apple", target_os = "openbsd"))))] +#[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" +))] pub fn compare_xattrs>(path1: P, path2: P) -> bool { let get_sorted_xattrs = |path: P| { xattr::list(path) @@ -3614,7 +3620,13 @@ mod tests { } } - #[cfg(all(unix, not(any(target_vendor = "apple", target_os = "openbsd"))))] + #[cfg(any( + target_os = "freebsd", + target_os = "hurd", + target_os = "linux", + target_os = "android", + target_os = "netbsd" + ))] #[test] fn test_compare_xattrs() { use tempfile::tempdir;