@@ -200,21 +200,59 @@ impl<'a> FindContext<'a> {
200
200
}
201
201
}
202
202
203
+ fn output_symlink_info < ' a > (
204
+ mut ctx : FindContext < ' a > ,
205
+ path : & std:: path:: Path ,
206
+ link_target : & str ,
207
+ symlink_meta : & std:: fs:: Metadata ,
208
+ target_meta : Option < std:: fs:: Metadata >
209
+ ) -> Result < ( FindContext < ' a > , u64 ) > {
210
+ if !check_include_exclude_path ( path, & ctx. include , & ctx. exclude , & ctx. match_option ) {
211
+ return Ok ( ( ctx, 0 ) ) ;
212
+ }
213
+ let parent = ctx. path . clone ( ) ;
214
+ if !ctx
215
+ . include
216
+ . iter ( )
217
+ . any ( |x| x. matches_with ( path. to_string_lossy ( ) . as_ref ( ) , ctx. match_option . clone ( ) ) )
218
+ {
219
+ return Ok ( ( ctx, 0 ) ) ;
220
+ }
221
+ let len = if let Some ( target_meta) = target_meta {
222
+ target_meta. len ( )
223
+ } else {
224
+ 0
225
+ } ;
226
+ let modified = match symlink_meta. modified ( ) {
227
+ Ok ( v) => Some ( v) ,
228
+ Err ( _) => None
229
+ } ;
230
+ write_record (
231
+ & mut ctx. output_stream ,
232
+ path. to_string_lossy ( ) . as_ref ( ) ,
233
+ Some ( link_target) ,
234
+ "file" ,
235
+ Some ( len) ,
236
+ modified,
237
+ ) ?;
238
+ Ok ( ( ctx, len) )
239
+ }
240
+
203
241
fn output_file_info < ' a > (
204
242
mut ctx : FindContext < ' a > ,
205
243
path : & std:: path:: Path ,
206
244
meta : Option < std:: fs:: Metadata > ,
207
245
) -> Result < ( FindContext < ' a > , u64 ) > {
208
246
if !check_include_exclude_path ( path, & ctx. include , & ctx. exclude , & ctx. match_option ) {
209
- return Ok ( ctx) ;
247
+ return Ok ( ( ctx, 0 ) ) ;
210
248
}
211
249
let parent = ctx. path . clone ( ) ;
212
250
if !ctx
213
251
. include
214
252
. iter ( )
215
253
. any ( |x| x. matches_with ( path. to_string_lossy ( ) . as_ref ( ) , ctx. match_option . clone ( ) ) )
216
254
{
217
- return Ok ( ctx) ;
255
+ return Ok ( ( ctx, 0 ) ) ;
218
256
}
219
257
let ( len, modified) = if let Some ( meta) = meta {
220
258
( Some ( meta. len ( ) ) , Some ( meta. modified ( ) ) )
@@ -386,7 +424,7 @@ fn retrieve_symlink<'a>(
386
424
. iter ( )
387
425
. any ( |x| x. matches_with ( path. to_string_lossy ( ) . as_ref ( ) , ctx. match_option . clone ( ) ) )
388
426
{
389
- return Ok ( ctx. with_path ( parent) ) ;
427
+ return Ok ( ( ctx. with_path ( parent) , 0 ) ) ;
390
428
}
391
429
let modified = meta
392
430
. map ( |meta| match meta. modified ( ) {
@@ -402,6 +440,7 @@ fn retrieve_symlink<'a>(
402
440
} )
403
441
. unwrap_or ( None ) ;
404
442
if check_include_exclude_path ( path. as_path ( ) , & ctx. include , & ctx. exclude , & ctx. match_option ) {
443
+ output_symlink_info ( ctx, path. as_path ( ) , link_target. to_string_lossy ( ) . as_ref ( ) , std:: fs:: metadata ( path) , std:: fs:: metadata ( link_target) ) ?;
405
444
write_record (
406
445
& mut ctx. output_stream ,
407
446
path. to_string_lossy ( ) . as_ref ( ) ,
@@ -411,7 +450,7 @@ fn retrieve_symlink<'a>(
411
450
modified,
412
451
) ?;
413
452
}
414
- Ok ( ctx. with_path ( parent) )
453
+ Ok ( ( ctx. with_path ( parent) , 0 ) )
415
454
}
416
455
417
456
fn enum_files_recursive < ' a > (
@@ -434,7 +473,7 @@ fn enum_files_recursive<'a>(
434
473
}
435
474
} ;
436
475
let current_path = ctx. path . clone ( ) ;
437
- let dir_total = 0 ;
476
+ let mut dir_total = 0 ;
438
477
for dentry in readiter {
439
478
let mut current_total = 0 ;
440
479
let dentry = match dentry {
@@ -478,7 +517,9 @@ fn enum_files_recursive<'a>(
478
517
}
479
518
} ;
480
519
ctx = ctx. with_path ( fpath. as_path ( ) ) ;
481
- ctx = retrieve_symlink ( ctx, current_path. as_path ( ) , meta, depth + 1 ) ?;
520
+ let retval = retrieve_symlink ( ctx, current_path. as_path ( ) , meta, depth + 1 ) ?;
521
+ ctx = retval. 0 ;
522
+ current_total += retval. 1 ;
482
523
} else if file_type. is_dir ( ) {
483
524
let last_write = match dentry. metadata ( ) {
484
525
Ok ( v) => match v. modified ( ) {
@@ -487,6 +528,9 @@ fn enum_files_recursive<'a>(
487
528
} ,
488
529
Err ( _) => None ,
489
530
} ;
531
+ let new_ctx = ctx. with_path ( fpath. as_path ( ) ) ;
532
+ let retval = enum_files_recursive ( new_ctx, current_path. as_path ( ) , depth + 1 ) ?;
533
+ ctx = retval. 0 ;
490
534
if !ctx. leaf_only
491
535
&& check_include_exclude_path ( fpath. as_path ( ) , & ctx. include , & ctx. exclude , & ctx. match_option )
492
536
{
@@ -495,13 +539,10 @@ fn enum_files_recursive<'a>(
495
539
fpath. as_path ( ) . to_string_lossy ( ) . as_ref ( ) ,
496
540
None ,
497
541
"dir" ,
498
- None ,
542
+ Some ( retval . 1 ) ,
499
543
last_write,
500
544
) ?;
501
545
}
502
- let new_ctx = ctx. with_path ( fpath. as_path ( ) ) ;
503
- let retval = enum_files_recursive ( new_ctx, current_path. as_path ( ) , depth + 1 , current_total) ?;
504
- ctx = retval. 0 ;
505
546
current_total += retval. 1 ;
506
547
} else if file_type. is_file ( ) {
507
548
let rtval = output_file_info_dentry ( ctx, & dentry) ?;
0 commit comments