Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
4 changes: 3 additions & 1 deletion src/uu/cp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ uucore = { workspace = true, features = [
"buf-copy",
"entries",
"fs",
"fsxattr",
"parser",
"perms",
"mode",
Expand All @@ -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 }

Expand Down
40 changes: 35 additions & 5 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/uu/ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ uucore = { workspace = true, features = [
"format",
"fs",
"fsext",
"fsxattr",
"i18n-collator",
"parser-size",
"parser-glob",
Expand All @@ -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 }

Expand Down
7 changes: 6 additions & 1 deletion src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 30 additions & 5 deletions src/uu/ls/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/uu/mv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 49 additions & 7 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)?;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/uucore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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 }
Expand Down
12 changes: 11 additions & 1 deletion src/uucore/src/lib/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/uucore/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
Expand Down
2 changes: 1 addition & 1 deletion tests/uutests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading
Loading