@@ -10,7 +10,7 @@ mod mode;
1010use clap:: { Arg , ArgAction , ArgMatches , Command } ;
1111use file_diff:: diff;
1212use filetime:: { FileTime , set_file_times} ;
13- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
13+ #[ cfg( selinux) ]
1414use selinux:: SecurityContext ;
1515use std:: ffi:: OsString ;
1616use std:: fmt:: Debug ;
@@ -30,7 +30,7 @@ use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown};
3030use uucore:: process:: { getegid, geteuid} ;
3131#[ cfg( unix) ]
3232use uucore:: safe_traversal:: { DirFd , SymlinkBehavior , create_dir_all_safe} ;
33- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
33+ #[ cfg( selinux) ]
3434use uucore:: selinux:: {
3535 SeLinuxError , contexts_differ, get_selinux_security_context, is_selinux_enabled,
3636 selinux_error_description, set_selinux_security_context,
@@ -121,7 +121,7 @@ enum InstallError {
121121 #[ error( "{}" , translate!( "install-error-extra-operand" , "operand" => . 0 . quote( ) , "usage" => . 1 . clone( ) ) ) ]
122122 ExtraOperand ( OsString , String ) ,
123123
124- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
124+ #[ cfg( selinux) ]
125125 #[ error( "{}" , . 0 ) ]
126126 SelinuxContextFailed ( String ) ,
127127}
@@ -489,7 +489,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> {
489489 }
490490
491491 // Set SELinux context for all created directories if needed
492- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
492+ #[ cfg( selinux) ]
493493 if should_set_selinux_context ( b) {
494494 let context = get_context_for_selinux ( b) ;
495495 set_selinux_context_for_directories_install ( path_to_create. as_path ( ) , context) ;
@@ -514,7 +514,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> {
514514 show_if_err ! ( chown_optional_user_group( path, b) ) ;
515515
516516 // Set SELinux context for directory if needed
517- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
517+ #[ cfg( selinux) ]
518518 if b. default_context {
519519 show_if_err ! ( set_selinux_default_context( path) ) ;
520520 } else if b. context . is_some ( ) {
@@ -683,7 +683,7 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
683683 }
684684
685685 // Set SELinux context for all created directories if needed
686- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
686+ #[ cfg( selinux) ]
687687 if should_set_selinux_context ( b) {
688688 let context = get_context_for_selinux ( b) ;
689689 set_selinux_context_for_directories_install ( to_create, context) ;
@@ -717,7 +717,7 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
717717 }
718718
719719 // Set SELinux context for all created directories if needed
720- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
720+ #[ cfg( selinux) ]
721721 if should_set_selinux_context ( b) {
722722 let context = get_context_for_selinux ( b) ;
723723 set_selinux_context_for_directories_install ( to_create, context) ;
@@ -1090,7 +1090,7 @@ fn finalize_installed_file(
10901090 preserve_timestamps ( from, to) ?;
10911091 }
10921092
1093- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1093+ #[ cfg( selinux) ]
10941094 if b. privileged {
10951095 if b. preserve_context {
10961096 uucore:: selinux:: preserve_security_context ( from, to)
@@ -1145,7 +1145,7 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
11451145 finalize_installed_file ( from, to, b, backup_path)
11461146}
11471147
1148- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1148+ #[ cfg( selinux) ]
11491149fn get_context_for_selinux ( b : & Behavior ) -> Option < & String > {
11501150 if b. default_context {
11511151 None
@@ -1154,7 +1154,7 @@ fn get_context_for_selinux(b: &Behavior) -> Option<&String> {
11541154 }
11551155}
11561156
1157- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1157+ #[ cfg( selinux) ]
11581158fn should_set_selinux_context ( b : & Behavior ) -> bool {
11591159 b. privileged && ( b. context . is_some ( ) || b. default_context )
11601160}
@@ -1250,7 +1250,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
12501250 }
12511251
12521252 if b. privileged {
1253- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1253+ #[ cfg( selinux) ]
12541254 if b. preserve_context && contexts_differ ( from, to) {
12551255 return true ;
12561256 }
@@ -1279,7 +1279,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
12791279 false
12801280}
12811281
1282- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1282+ #[ cfg( selinux) ]
12831283/// Sets the `SELinux` security context for install's -Z flag behavior.
12841284///
12851285/// This function implements the specific behavior needed for install's -Z flag,
@@ -1313,7 +1313,7 @@ pub fn set_selinux_default_context(path: &Path) -> Result<(), SeLinuxError> {
13131313 }
13141314}
13151315
1316- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1316+ #[ cfg( selinux) ]
13171317/// Gets the default `SELinux` context for a path based on the system's security policy.
13181318///
13191319/// This function attempts to determine what the "correct" `SELinux` context should be
@@ -1369,7 +1369,7 @@ fn get_default_context_for_path(path: &Path) -> Result<Option<String>, SeLinuxEr
13691369 Ok ( None )
13701370}
13711371
1372- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1372+ #[ cfg( selinux) ]
13731373/// Derives an appropriate `SELinux` context based on a parent directory context.
13741374///
13751375/// This is a heuristic function that attempts to generate an appropriate
@@ -1407,7 +1407,7 @@ fn derive_context_from_parent(parent_context: &str) -> String {
14071407 }
14081408}
14091409
1410- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1410+ #[ cfg( selinux) ]
14111411/// Helper function to collect paths that need `SELinux` context setting.
14121412///
14131413/// Traverses from the given starting path up to existing parent directories.
@@ -1421,7 +1421,7 @@ fn collect_paths_for_context_setting(starting_path: &Path) -> Vec<&Path> {
14211421 paths
14221422}
14231423
1424- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1424+ #[ cfg( selinux) ]
14251425/// Sets the `SELinux` security context for a directory hierarchy.
14261426///
14271427/// This function traverses from the given starting path up to existing parent directories
@@ -1461,7 +1461,7 @@ fn set_selinux_context_for_directories(target_path: &Path, context: Option<&Stri
14611461 }
14621462}
14631463
1464- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1464+ #[ cfg( selinux) ]
14651465/// Sets `SELinux` context for created directories using install's -Z default behavior.
14661466///
14671467/// Similar to `set_selinux_context_for_directories` but uses install's
@@ -1485,10 +1485,10 @@ pub fn set_selinux_context_for_directories_install(target_path: &Path, context:
14851485
14861486#[ cfg( test) ]
14871487mod tests {
1488- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1488+ #[ cfg( selinux) ]
14891489 use super :: derive_context_from_parent;
14901490
1491- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1491+ #[ cfg( selinux) ]
14921492 #[ test]
14931493 fn test_derive_context_from_parent ( ) {
14941494 // Test cases: (input_context, file_type, expected_output, description)
0 commit comments