@@ -931,23 +931,33 @@ impl Options {
931931 } ;
932932
933933 // Parse attributes to preserve
934- let attributes = if let Some ( attribute_strs) = matches. get_many :: < String > ( options:: PRESERVE )
935- {
936- if attribute_strs. len ( ) == 0 {
934+ let mut attributes =
935+ if let Some ( attribute_strs) = matches. get_many :: < String > ( options:: PRESERVE ) {
936+ if attribute_strs. len ( ) == 0 {
937+ Attributes :: DEFAULT
938+ } else {
939+ Attributes :: parse_iter ( attribute_strs) ?
940+ }
941+ } else if matches. get_flag ( options:: ARCHIVE ) {
942+ // --archive is used. Same as --preserve=all
943+ Attributes :: ALL
944+ } else if matches. get_flag ( options:: NO_DEREFERENCE_PRESERVE_LINKS ) {
945+ Attributes :: LINKS
946+ } else if matches. get_flag ( options:: PRESERVE_DEFAULT_ATTRIBUTES ) {
937947 Attributes :: DEFAULT
938948 } else {
939- Attributes :: parse_iter ( attribute_strs) ?
949+ Attributes :: NONE
950+ } ;
951+
952+ // handling no-preserve options and adjusting the attributes
953+ if let Some ( attribute_strs) = matches. get_many :: < String > ( options:: NO_PRESERVE ) {
954+ if attribute_strs. len ( ) > 0 {
955+ let no_preserve_attributes = Attributes :: parse_iter ( attribute_strs) ?;
956+ if matches ! ( no_preserve_attributes. links, Preserve :: Yes { .. } ) {
957+ attributes. links = Preserve :: No ;
958+ }
940959 }
941- } else if matches. get_flag ( options:: ARCHIVE ) {
942- // --archive is used. Same as --preserve=all
943- Attributes :: ALL
944- } else if matches. get_flag ( options:: NO_DEREFERENCE_PRESERVE_LINKS ) {
945- Attributes :: LINKS
946- } else if matches. get_flag ( options:: PRESERVE_DEFAULT_ATTRIBUTES ) {
947- Attributes :: DEFAULT
948- } else {
949- Attributes :: NONE
950- } ;
960+ }
951961
952962 #[ cfg( not( feature = "feat_selinux" ) ) ]
953963 if let Preserve :: Yes { required } = attributes. context {
0 commit comments