@@ -198,7 +198,7 @@ impl FolderChanges {
198198 }
199199}
200200
201- pub fn copy_content_recursive ( from : & Path , to : & Path ) -> std:: io:: Result < ( ) > {
201+ pub fn copy_content_recursive ( from : & Path , to : & Path , strict : bool , progress : & dyn Fn ( u64 , u64 ) ) -> std:: io:: Result < ( ) > {
202202 let from = from. canonicalize ( ) ?;
203203 if !from. is_dir ( ) {
204204 return Err ( ErrorKind :: NotADirectory . into ( ) ) ;
@@ -262,38 +262,53 @@ pub fn copy_content_recursive(from: &Path, to: &Path) -> std::io::Result<()> {
262262 }
263263 }
264264 }
265+ ( progress) ( 0 , total_bytes) ;
265266
266267 for directory in directories {
267268 _ = std:: fs:: create_dir ( to. join ( directory) ) ;
268269 }
269270 let mut copied_bytes = 0 ;
270271 for ( relative, copy_from) in files {
271272 let dest = to. join ( relative) ;
272- copied_bytes += std:: fs:: copy ( copy_from, dest) ?;
273+ match std:: fs:: copy ( copy_from, dest) {
274+ Ok ( bytes) => copied_bytes += bytes,
275+ Err ( err) => if strict {
276+ return Err ( err) ;
277+ } ,
278+ }
279+ ( progress) ( copied_bytes, total_bytes) ;
273280 }
274- if copied_bytes != total_bytes {
281+ if strict && copied_bytes != total_bytes {
275282 return Err ( Error :: new ( ErrorKind :: Other ,
276283 format ! ( "Expected copy size did not match. Expected to copy {total_bytes} bytes, copied {copied_bytes} instead" ) ) ) ;
277284 }
278285 for ( relative, internal) in internal_symlinks {
279286 let dest = to. join ( relative) ;
280287 let target = to. join ( internal) ;
281- symlink_dir_or_file ( & target, & dest) ?;
288+ if let Err ( err) = symlink_dir_or_file ( & target, & dest) && strict {
289+ return Err ( err) ;
290+ }
282291 }
283292 for ( relative, target) in external_symlinks {
284293 let dest = to. join ( relative) ;
285- symlink_dir_or_file ( & target, & dest) ?;
294+ if let Err ( err) = symlink_dir_or_file ( & target, & dest) && strict {
295+ return Err ( err) ;
296+ }
286297 }
287298 #[ cfg( windows) ]
288299 for ( relative, internal) in internal_junctions {
289300 let dest = to. join ( relative) ;
290301 let target = to. join ( internal) ;
291- junction:: create ( & target, & dest) ?;
302+ if let Err ( err) = junction:: create ( & target, & dest) && strict {
303+ return Err ( err) ;
304+ }
292305 }
293306 #[ cfg( windows) ]
294307 for ( relative, target) in external_junctions {
295308 let dest = to. join ( relative) ;
296- junction:: create ( & target, & dest) ?;
309+ if let Err ( err) = junction:: create ( & target, & dest) && strict {
310+ return Err ( err) ;
311+ }
297312 }
298313 Ok ( ( ) )
299314}
@@ -335,7 +350,7 @@ pub fn rename_with_fallback_across_devices(from: &Path, to: &Path) -> std::io::R
335350 _ = std:: fs:: remove_file ( from) ;
336351 } else if from. is_dir ( ) {
337352 std:: fs:: create_dir ( to) ?;
338- if let Err ( err) = copy_content_recursive ( from, to) {
353+ if let Err ( err) = copy_content_recursive ( from, to, true , & |_ , _| { } ) {
339354 _ = std:: fs:: remove_dir_all ( to) ;
340355 return Err ( err) ;
341356 } else {
0 commit comments