File tree Expand file tree Collapse file tree 1 file changed +24
-14
lines changed
Expand file tree Collapse file tree 1 file changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -1708,20 +1708,30 @@ pub(crate) fn copy_attributes(
17081708
17091709 let dest_uid = source_metadata. uid ( ) ;
17101710 let dest_gid = source_metadata. gid ( ) ;
1711- // gnu compatibility: cp doesn't report an error if it fails to set the ownership.
1712- let _ = wrap_chown (
1713- dest,
1714- & dest
1715- . symlink_metadata ( )
1716- . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?,
1717- Some ( dest_uid) ,
1718- Some ( dest_gid) ,
1719- false ,
1720- Verbosity {
1721- groups_only : false ,
1722- level : VerbosityLevel :: Silent ,
1723- } ,
1724- ) ;
1711+ let meta = & dest
1712+ . symlink_metadata ( )
1713+ . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?;
1714+
1715+ let try_chown = {
1716+ |uid| {
1717+ wrap_chown (
1718+ dest,
1719+ meta,
1720+ uid,
1721+ Some ( dest_gid) ,
1722+ false ,
1723+ Verbosity {
1724+ groups_only : false ,
1725+ level : VerbosityLevel :: Silent ,
1726+ } ,
1727+ )
1728+ }
1729+ } ;
1730+ // gnu compatibility: cp doesn't report an error if it fails to set the ownership,
1731+ // and will fall back to changing only the gid if possible.
1732+ if try_chown ( Some ( dest_uid) ) . is_err ( ) {
1733+ let _ = try_chown ( None ) ;
1734+ }
17251735 Ok ( ( ) )
17261736 } ) ?;
17271737
You can’t perform that action at this time.
0 commit comments