Skip to content

Commit bc7e525

Browse files
committed
temporary commit
1 parent 0ce394f commit bc7e525

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

src/main.rs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,59 @@ impl<'a> FindContext<'a> {
200200
}
201201
}
202202

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+
203241
fn output_file_info<'a>(
204242
mut ctx: FindContext<'a>,
205243
path: &std::path::Path,
206244
meta: Option<std::fs::Metadata>,
207245
) -> Result<(FindContext<'a>, u64)> {
208246
if !check_include_exclude_path(path, &ctx.include, &ctx.exclude, &ctx.match_option) {
209-
return Ok(ctx);
247+
return Ok((ctx, 0));
210248
}
211249
let parent = ctx.path.clone();
212250
if !ctx
213251
.include
214252
.iter()
215253
.any(|x| x.matches_with(path.to_string_lossy().as_ref(), ctx.match_option.clone()))
216254
{
217-
return Ok(ctx);
255+
return Ok((ctx, 0));
218256
}
219257
let (len, modified) = if let Some(meta) = meta {
220258
(Some(meta.len()), Some(meta.modified()))
@@ -386,7 +424,7 @@ fn retrieve_symlink<'a>(
386424
.iter()
387425
.any(|x| x.matches_with(path.to_string_lossy().as_ref(), ctx.match_option.clone()))
388426
{
389-
return Ok(ctx.with_path(parent));
427+
return Ok((ctx.with_path(parent), 0));
390428
}
391429
let modified = meta
392430
.map(|meta| match meta.modified() {
@@ -402,6 +440,7 @@ fn retrieve_symlink<'a>(
402440
})
403441
.unwrap_or(None);
404442
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))?;
405444
write_record(
406445
&mut ctx.output_stream,
407446
path.to_string_lossy().as_ref(),
@@ -411,7 +450,7 @@ fn retrieve_symlink<'a>(
411450
modified,
412451
)?;
413452
}
414-
Ok(ctx.with_path(parent))
453+
Ok((ctx.with_path(parent), 0))
415454
}
416455

417456
fn enum_files_recursive<'a>(
@@ -434,7 +473,7 @@ fn enum_files_recursive<'a>(
434473
}
435474
};
436475
let current_path = ctx.path.clone();
437-
let dir_total = 0;
476+
let mut dir_total = 0;
438477
for dentry in readiter {
439478
let mut current_total = 0;
440479
let dentry = match dentry {
@@ -478,7 +517,9 @@ fn enum_files_recursive<'a>(
478517
}
479518
};
480519
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;
482523
} else if file_type.is_dir() {
483524
let last_write = match dentry.metadata() {
484525
Ok(v) => match v.modified() {
@@ -487,6 +528,9 @@ fn enum_files_recursive<'a>(
487528
},
488529
Err(_) => None,
489530
};
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;
490534
if !ctx.leaf_only
491535
&& check_include_exclude_path(fpath.as_path(), &ctx.include, &ctx.exclude, &ctx.match_option)
492536
{
@@ -495,13 +539,10 @@ fn enum_files_recursive<'a>(
495539
fpath.as_path().to_string_lossy().as_ref(),
496540
None,
497541
"dir",
498-
None,
542+
Some(retval.1),
499543
last_write,
500544
)?;
501545
}
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;
505546
current_total += retval.1;
506547
} else if file_type.is_file() {
507548
let rtval = output_file_info_dentry(ctx, &dentry)?;

0 commit comments

Comments
 (0)