Skip to content

Commit 538038b

Browse files
committed
cp: add selinux cfg alias
1 parent d55424d commit 538038b

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/cp/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ workspace = true
1818
[lib]
1919
path = "src/cp.rs"
2020

21+
[build-dependencies]
22+
cfg_aliases.workspace = true
23+
2124
[dependencies]
2225
clap = { workspace = true }
2326
filetime = { workspace = true }

src/uu/cp/build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use cfg_aliases::cfg_aliases;
7+
8+
pub fn main() {
9+
cfg_aliases! {
10+
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
11+
}
12+
}

src/uu/cp/src/copydir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use uucore::translate;
2626
use uucore::uio_error;
2727
use walkdir::{DirEntry, WalkDir};
2828

29-
#[cfg(all(feature = "selinux", target_os = "linux"))]
29+
#[cfg(selinux)]
3030
use crate::set_selinux_context;
3131
use crate::{
3232
CopyMode, CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes,
@@ -562,7 +562,7 @@ pub(crate) fn copy_directory(
562562
options.set_selinux_context,
563563
)?;
564564

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

585-
#[cfg(all(feature = "selinux", target_os = "linux"))]
585+
#[cfg(selinux)]
586586
if options.set_selinux_context {
587587
set_selinux_context(y, options.context.as_ref())?;
588588
}

src/uu/cp/src/cp.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -896,11 +896,11 @@ impl Attributes {
896896
mode: Preserve::Yes { required: true },
897897
timestamps: Preserve::Yes { required: true },
898898
context: {
899-
#[cfg(feature = "feat_selinux")]
899+
#[cfg(selinux)]
900900
{
901901
Preserve::Yes { required: false }
902902
}
903-
#[cfg(not(feature = "feat_selinux"))]
903+
#[cfg(not(selinux))]
904904
{
905905
Preserve::No { explicit: false }
906906
}
@@ -1141,7 +1141,7 @@ impl Options {
11411141
}
11421142
}
11431143

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

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

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

2661-
#[cfg(all(feature = "selinux", target_os = "linux"))]
2661+
#[cfg(selinux)]
26622662
if options.set_selinux_context {
26632663
set_selinux_context(dest, options.context.as_ref())?;
26642664
}

0 commit comments

Comments
 (0)