@@ -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}
@@ -492,7 +492,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> {
492492 }
493493
494494 // Set SELinux context for all created directories if needed
495- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
495+ #[ cfg( selinux) ]
496496 if should_set_selinux_context ( b) {
497497 let context = get_context_for_selinux ( b) ;
498498 set_selinux_context_for_directories_install ( path_to_create. as_path ( ) , context) ;
@@ -517,7 +517,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> {
517517 show_if_err ! ( chown_optional_user_group( path, b) ) ;
518518
519519 // Set SELinux context for directory if needed
520- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
520+ #[ cfg( selinux) ]
521521 if b. default_context {
522522 show_if_err ! ( set_selinux_default_context( path) ) ;
523523 } else if b. context . is_some ( ) {
@@ -689,7 +689,7 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
689689 }
690690
691691 // Set SELinux context for all created directories if needed
692- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
692+ #[ cfg( selinux) ]
693693 if should_set_selinux_context ( b) {
694694 let context = get_context_for_selinux ( b) ;
695695 set_selinux_context_for_directories_install ( to_create, context) ;
@@ -723,7 +723,7 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
723723 }
724724
725725 // Set SELinux context for all created directories if needed
726- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
726+ #[ cfg( selinux) ]
727727 if should_set_selinux_context ( b) {
728728 let context = get_context_for_selinux ( b) ;
729729 set_selinux_context_for_directories_install ( to_create, context) ;
@@ -1096,7 +1096,7 @@ fn finalize_installed_file(
10961096 preserve_timestamps ( from, to) ?;
10971097 }
10981098
1099- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1099+ #[ cfg( selinux) ]
11001100 if !b. unprivileged {
11011101 if b. preserve_context {
11021102 uucore:: selinux:: preserve_security_context ( from, to)
@@ -1155,7 +1155,7 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
11551155 finalize_installed_file ( from, to, b, backup_path)
11561156}
11571157
1158- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1158+ #[ cfg( selinux) ]
11591159fn get_context_for_selinux ( b : & Behavior ) -> Option < & String > {
11601160 if b. default_context {
11611161 None
@@ -1164,7 +1164,7 @@ fn get_context_for_selinux(b: &Behavior) -> Option<&String> {
11641164 }
11651165}
11661166
1167- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1167+ #[ cfg( selinux) ]
11681168fn should_set_selinux_context ( b : & Behavior ) -> bool {
11691169 !b. unprivileged && ( b. context . is_some ( ) || b. default_context )
11701170}
@@ -1259,7 +1259,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
12591259 return true ;
12601260 }
12611261
1262- #[ cfg( all ( feature = " selinux" , target_os = "linux" ) ) ]
1262+ #[ cfg( selinux) ]
12631263 if !b. unprivileged && b. preserve_context && contexts_differ ( from, to) {
12641264 return true ;
12651265 }
@@ -1290,7 +1290,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
12901290 false
12911291}
12921292
1293- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1293+ #[ cfg( selinux) ]
12941294/// Sets the `SELinux` security context for install's -Z flag behavior.
12951295///
12961296/// This function implements the specific behavior needed for install's -Z flag,
@@ -1324,7 +1324,7 @@ pub fn set_selinux_default_context(path: &Path) -> Result<(), SeLinuxError> {
13241324 }
13251325}
13261326
1327- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1327+ #[ cfg( selinux) ]
13281328/// Gets the default `SELinux` context for a path based on the system's security policy.
13291329///
13301330/// This function attempts to determine what the "correct" `SELinux` context should be
@@ -1380,7 +1380,7 @@ fn get_default_context_for_path(path: &Path) -> Result<Option<String>, SeLinuxEr
13801380 Ok ( None )
13811381}
13821382
1383- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1383+ #[ cfg( selinux) ]
13841384/// Derives an appropriate `SELinux` context based on a parent directory context.
13851385///
13861386/// This is a heuristic function that attempts to generate an appropriate
@@ -1418,7 +1418,7 @@ fn derive_context_from_parent(parent_context: &str) -> String {
14181418 }
14191419}
14201420
1421- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1421+ #[ cfg( selinux) ]
14221422/// Helper function to collect paths that need `SELinux` context setting.
14231423///
14241424/// Traverses from the given starting path up to existing parent directories.
@@ -1432,7 +1432,7 @@ fn collect_paths_for_context_setting(starting_path: &Path) -> Vec<&Path> {
14321432 paths
14331433}
14341434
1435- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1435+ #[ cfg( selinux) ]
14361436/// Sets the `SELinux` security context for a directory hierarchy.
14371437///
14381438/// This function traverses from the given starting path up to existing parent directories
@@ -1472,7 +1472,7 @@ fn set_selinux_context_for_directories(target_path: &Path, context: Option<&Stri
14721472 }
14731473}
14741474
1475- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1475+ #[ cfg( selinux) ]
14761476/// Sets `SELinux` context for created directories using install's -Z default behavior.
14771477///
14781478/// Similar to `set_selinux_context_for_directories` but uses install's
@@ -1496,10 +1496,10 @@ pub fn set_selinux_context_for_directories_install(target_path: &Path, context:
14961496
14971497#[ cfg( test) ]
14981498mod tests {
1499- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1499+ #[ cfg( selinux) ]
15001500 use super :: derive_context_from_parent;
15011501
1502- #[ cfg( all ( feature = " selinux" , any ( target_os = "linux" , target_os = "android" ) ) ) ]
1502+ #[ cfg( selinux) ]
15031503 #[ test]
15041504 fn test_derive_context_from_parent ( ) {
15051505 // Test cases: (input_context, file_type, expected_output, description)
0 commit comments