diff --git a/src/main.rs b/src/main.rs index 3e83f49..a32799a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -102,14 +102,18 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { // renew pending index files on items crawl completed if let Some(ref index_argument) = argument.index { for path in index { - let subject = format!("{path}{index_argument}"); + let index_filename = format!("{path}{index_argument}"); + + // scan dir files, sort by name desc + let mut files: Vec<_> = read_dir(&path)?.filter_map(Result::ok).collect(); + files.sort_by_key(|f| f.file_name()); - let mut index = File::create(&subject)?; let mut data = Vec::with_capacity(argument.limit); - + let mut index = File::create(&index_filename)?; let mut total = 0; - for file in read_dir(&path)? { - let name = file?.file_name().into_string().unwrap(); + + for file in files { + let name = file.file_name().into_string().unwrap(); if &name == index_argument { continue; @@ -124,7 +128,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box> { index.write_all(data.join("\n\n").as_bytes())?; - output.debug(&format!("renew `{subject}` (total: {total})")); + output.debug(&format!("renew `{index_filename}` (total: {total})")); } }