@@ -9,10 +9,10 @@ use std::collections::{HashMap, HashSet};
9
9
use std:: ffi:: OsString ;
10
10
use std:: fmt:: Display ;
11
11
use std:: fs:: { self , Metadata , OpenOptions , Permissions } ;
12
- use std:: { fmt, io} ;
13
12
#[ cfg( unix) ]
14
13
use std:: os:: unix:: fs:: { FileTypeExt , PermissionsExt } ;
15
14
use std:: path:: { Path , PathBuf , StripPrefixError } ;
15
+ use std:: { fmt, io} ;
16
16
#[ cfg( all( unix, not( target_os = "android" ) ) ) ]
17
17
use uucore:: fsxattr:: copy_xattrs;
18
18
@@ -1679,7 +1679,8 @@ pub(crate) fn copy_attributes(
1679
1679
attributes : & Attributes ,
1680
1680
) -> CopyResult < ( ) > {
1681
1681
let context = & * format ! ( "{} -> {}" , source. quote( ) , dest. quote( ) ) ;
1682
- let source_metadata = fs:: symlink_metadata ( source) . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?;
1682
+ let source_metadata =
1683
+ fs:: symlink_metadata ( source) . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?;
1683
1684
1684
1685
// Ownership must be changed first to avoid interfering with mode change.
1685
1686
#[ cfg( unix) ]
@@ -1694,7 +1695,9 @@ pub(crate) fn copy_attributes(
1694
1695
// gnu compatibility: cp doesn't report an error if it fails to set the ownership.
1695
1696
let _ = wrap_chown (
1696
1697
dest,
1697
- & dest. symlink_metadata ( ) . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?,
1698
+ & dest
1699
+ . symlink_metadata ( )
1700
+ . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?,
1698
1701
Some ( dest_uid) ,
1699
1702
Some ( dest_gid) ,
1700
1703
false ,
@@ -1713,7 +1716,8 @@ pub(crate) fn copy_attributes(
1713
1716
// do nothing, since every symbolic link has the same
1714
1717
// permissions.
1715
1718
if !dest. is_symlink ( ) {
1716
- fs:: set_permissions ( dest, source_metadata. permissions ( ) ) . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?;
1719
+ fs:: set_permissions ( dest, source_metadata. permissions ( ) )
1720
+ . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?;
1717
1721
// FIXME: Implement this for windows as well
1718
1722
#[ cfg( feature = "feat_acl" ) ]
1719
1723
exacl:: getfacl ( source, None )
@@ -1789,19 +1793,29 @@ fn symlink_file(
1789
1793
) -> CopyResult < ( ) > {
1790
1794
#[ cfg( not( windows) ) ]
1791
1795
{
1792
- std:: os:: unix:: fs:: symlink ( source, dest) . map_err ( |e| CpError :: IoErrContext ( e, format ! (
1793
- "cannot create symlink {} to {}" ,
1794
- get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
1795
- get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
1796
- ) ) ) ?;
1796
+ std:: os:: unix:: fs:: symlink ( source, dest) . map_err ( |e| {
1797
+ CpError :: IoErrContext (
1798
+ e,
1799
+ format ! (
1800
+ "cannot create symlink {} to {}" ,
1801
+ get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
1802
+ get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
1803
+ ) ,
1804
+ )
1805
+ } ) ?;
1797
1806
}
1798
1807
#[ cfg( windows) ]
1799
1808
{
1800
- std:: os:: windows:: fs:: symlink_file ( source, dest) . map_err ( |e| CpError :: IoErrContext ( e, format ! (
1801
- "cannot create symlink {} to {}" ,
1802
- get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
1803
- get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
1804
- ) ) ) ?;
1809
+ std:: os:: windows:: fs:: symlink_file ( source, dest) . map_err ( |e| {
1810
+ CpError :: IoErrContext (
1811
+ e,
1812
+ format ! (
1813
+ "cannot create symlink {} to {}" ,
1814
+ get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
1815
+ get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
1816
+ ) ,
1817
+ )
1818
+ } ) ?;
1805
1819
}
1806
1820
if let Ok ( file_info) = FileInformation :: from_path ( dest, false ) {
1807
1821
symlinked_files. insert ( file_info) ;
@@ -2117,11 +2131,16 @@ fn handle_copy_mode(
2117
2131
} else {
2118
2132
fs:: hard_link ( source, dest)
2119
2133
}
2120
- . map_err ( |e| CpError :: IoErrContext ( e, format ! (
2121
- "cannot create hard link {} to {}" ,
2122
- get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
2123
- get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
2124
- ) ) ) ?;
2134
+ . map_err ( |e| {
2135
+ CpError :: IoErrContext (
2136
+ e,
2137
+ format ! (
2138
+ "cannot create hard link {} to {}" ,
2139
+ get_filename( dest) . unwrap_or( "invalid file name" ) . quote( ) ,
2140
+ get_filename( source) . unwrap_or( "invalid file name" ) . quote( )
2141
+ ) ,
2142
+ )
2143
+ } ) ?;
2125
2144
}
2126
2145
CopyMode :: Copy => {
2127
2146
copy_helper (
@@ -2166,7 +2185,10 @@ fn handle_copy_mode(
2166
2185
return Ok ( PerformedAction :: Skipped ) ;
2167
2186
}
2168
2187
UpdateMode :: NoneFail => {
2169
- return Err ( CpError :: Error ( format ! ( "not replacing '{}'" , dest. display( ) ) ) ) ;
2188
+ return Err ( CpError :: Error ( format ! (
2189
+ "not replacing '{}'" ,
2190
+ dest. display( )
2191
+ ) ) ) ;
2170
2192
}
2171
2193
UpdateMode :: IfOlder => {
2172
2194
let dest_metadata = fs:: symlink_metadata ( dest) ?;
@@ -2238,7 +2260,10 @@ fn calculate_dest_permissions(
2238
2260
context : & str ,
2239
2261
) -> CopyResult < Permissions > {
2240
2262
if dest. exists ( ) {
2241
- Ok ( dest. symlink_metadata ( ) . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?. permissions ( ) )
2263
+ Ok ( dest
2264
+ . symlink_metadata ( )
2265
+ . map_err ( |e| CpError :: IoErrContext ( e, context. to_owned ( ) ) ) ?
2266
+ . permissions ( ) )
2242
2267
} else {
2243
2268
#[ cfg( unix) ]
2244
2269
{
0 commit comments