Skip to content
Open
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ binary-heap-plus = "0.5.0"
bstr = "1.9.1"
bytecount = "0.6.8"
byteorder = "1.5.0"
cfg_aliases = "0.2.1"
clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] }
clap_complete = "4.4"
clap_mangen = "0.2"
Expand Down
1 change: 1 addition & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/uu/cp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ workspace = true
[lib]
path = "src/cp.rs"

[build-dependencies]
cfg_aliases.workspace = true

[dependencies]
clap = { workspace = true }
filetime = { workspace = true }
Expand Down
12 changes: 12 additions & 0 deletions src/uu/cp/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use cfg_aliases::cfg_aliases;

pub fn main() {
cfg_aliases! {
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
}
}
6 changes: 3 additions & 3 deletions src/uu/cp/src/copydir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use uucore::translate;
use uucore::uio_error;
use walkdir::{DirEntry, WalkDir};

#[cfg(all(feature = "selinux", target_os = "linux"))]
#[cfg(selinux)]
use crate::set_selinux_context;
use crate::{
CopyMode, CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes,
Expand Down Expand Up @@ -562,7 +562,7 @@ pub(crate) fn copy_directory(
options.set_selinux_context,
)?;

#[cfg(all(feature = "selinux", target_os = "linux"))]
#[cfg(selinux)]
if options.set_selinux_context {
set_selinux_context(&dir.dest, options.context.as_ref())?;
}
Expand All @@ -582,7 +582,7 @@ pub(crate) fn copy_directory(
options.set_selinux_context,
)?;

#[cfg(all(feature = "selinux", target_os = "linux"))]
#[cfg(selinux)]
if options.set_selinux_context {
set_selinux_context(y, options.context.as_ref())?;
}
Expand Down
12 changes: 6 additions & 6 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,11 +896,11 @@ impl Attributes {
mode: Preserve::Yes { required: true },
timestamps: Preserve::Yes { required: true },
context: {
#[cfg(feature = "feat_selinux")]
#[cfg(selinux)]
{
Preserve::Yes { required: false }
}
#[cfg(not(feature = "feat_selinux"))]
#[cfg(not(selinux))]
{
Preserve::No { explicit: false }
}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ impl Options {
}
}

#[cfg(not(feature = "selinux"))]
#[cfg(not(selinux))]
if let Preserve::Yes { required } = attributes.context {
let selinux_disabled_error = CpError::Error(translate!("cp-error-selinux-not-enabled"));
if required {
Expand Down Expand Up @@ -1692,7 +1692,7 @@ fn handle_preserve<F: Fn() -> CopyResult<()>>(p: Preserve, f: F) -> CopyResult<(
Ok(())
}

#[cfg(all(feature = "selinux", target_os = "linux"))]
#[cfg(selinux)]
pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> CopyResult<()> {
if !uucore::selinux::is_selinux_enabled() {
return Ok(());
Expand Down Expand Up @@ -1846,7 +1846,7 @@ pub(crate) fn copy_attributes(
Ok(())
})?;

#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
#[cfg(selinux)]
handle_preserve(attributes.context, || -> CopyResult<()> {
// Get the source context and apply it to the destination
if let Ok(context) = selinux::SecurityContext::of_path(source, false, false) {
Expand Down Expand Up @@ -2658,7 +2658,7 @@ fn copy_file(
fs::File::create(dest).map(|f| f.set_len(0)).ok();
})?;

#[cfg(all(feature = "selinux", target_os = "linux"))]
#[cfg(selinux)]
if options.set_selinux_context {
set_selinux_context(dest, options.context.as_ref())?;
}
Expand Down
3 changes: 3 additions & 0 deletions src/uu/id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ workspace = true
[lib]
path = "src/id.rs"

[build-dependencies]
cfg_aliases.workspace = true

[dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["entries", "process"] }
Expand Down
13 changes: 13 additions & 0 deletions src/uu/id/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use cfg_aliases::cfg_aliases;

pub fn main() {
cfg_aliases! {
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
smack: { all(feature = "smack", target_os = "linux") },
}
}
20 changes: 10 additions & 10 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ macro_rules! cstr2cow {
}

fn get_context_help_text() -> String {
#[cfg(not(any(feature = "selinux", feature = "smack")))]
#[cfg(not(any(selinux, smack)))]
return translate!("id-context-help-disabled");
#[cfg(any(feature = "selinux", feature = "smack"))]
#[cfg(any(selinux, smack))]
return translate!("id-context-help-enabled");
}

Expand Down Expand Up @@ -99,9 +99,9 @@ struct State {
rflag: bool, // --real
zflag: bool, // --zero
cflag: bool, // --context
#[cfg(feature = "selinux")]
#[cfg(selinux)]
selinux_supported: bool,
#[cfg(feature = "smack")]
#[cfg(smack)]
smack_supported: bool,
ids: Option<Ids>,
// The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different.
Expand Down Expand Up @@ -141,9 +141,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
zflag: matches.get_flag(options::OPT_ZERO),
cflag: matches.get_flag(options::OPT_CONTEXT),

#[cfg(feature = "selinux")]
#[cfg(selinux)]
selinux_supported: uucore::selinux::is_selinux_enabled(),
#[cfg(feature = "smack")]
#[cfg(smack)]
smack_supported: uucore::smack::is_smack_enabled(),
user_specified: !users.is_empty(),
ids: None,
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

if state.cflag {
// SELinux context
#[cfg(feature = "selinux")]
#[cfg(selinux)]
if state.selinux_supported {
if let Ok(context) = selinux::SecurityContext::current(false) {
let bytes = context.as_bytes();
Expand All @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

// SMACK label
#[cfg(feature = "smack")]
#[cfg(smack)]
if state.smack_supported {
match uucore::smack::get_smack_label_for_self() {
Ok(label) => {
Expand Down Expand Up @@ -702,7 +702,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
.join(",")
)?;

#[cfg(feature = "selinux")]
#[cfg(selinux)]
if state.selinux_supported
&& !state.user_specified
&& std::env::var_os("POSIXLY_CORRECT").is_none()
Expand All @@ -714,7 +714,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
}
}

#[cfg(feature = "smack")]
#[cfg(smack)]
if state.smack_supported
&& !state.user_specified
&& std::env::var_os("POSIXLY_CORRECT").is_none()
Expand Down
3 changes: 3 additions & 0 deletions src/uu/install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ workspace = true
[lib]
path = "src/install.rs"

[build-dependencies]
cfg_aliases.workspace = true

[dependencies]
clap = { workspace = true }
filetime = { workspace = true }
Expand Down
12 changes: 12 additions & 0 deletions src/uu/install/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use cfg_aliases::cfg_aliases;

pub fn main() {
cfg_aliases! {
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
}
}
Loading
Loading