Skip to content

Commit da59839

Browse files
committed
cp: add selinux cfg alias
1 parent c949742 commit da59839

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

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,
@@ -563,7 +563,7 @@ pub(crate) fn copy_directory(
563563
options.set_selinux_context,
564564
)?;
565565

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

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

src/uu/cp/src/cp.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,11 @@ impl Attributes {
898898
mode: Preserve::Yes { required: true },
899899
timestamps: Preserve::Yes { required: true },
900900
context: {
901-
#[cfg(feature = "feat_selinux")]
901+
#[cfg(selinux)]
902902
{
903903
Preserve::Yes { required: false }
904904
}
905-
#[cfg(not(feature = "feat_selinux"))]
905+
#[cfg(not(selinux))]
906906
{
907907
Preserve::No { explicit: false }
908908
}
@@ -1143,7 +1143,7 @@ impl Options {
11431143
}
11441144
}
11451145

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

1697-
#[cfg(all(feature = "selinux", target_os = "linux"))]
1697+
#[cfg(selinux)]
16981698
pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> CopyResult<()> {
16991699
if !uucore::selinux::is_selinux_enabled() {
17001700
return Ok(());
@@ -1848,7 +1848,7 @@ pub(crate) fn copy_attributes(
18481848
Ok(())
18491849
})?;
18501850

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

2642-
#[cfg(all(feature = "selinux", target_os = "linux"))]
2642+
#[cfg(selinux)]
26432643
if options.set_selinux_context {
26442644
set_selinux_context(dest, options.context.as_ref())?;
26452645
}

0 commit comments

Comments
 (0)