mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 02:49:55 +00:00
Merge pull request #47 from hl-archive-node/fix/issue-46
fix: Sort hl-node files correctly
This commit is contained in:
@ -17,12 +17,12 @@ impl FileOperations {
|
|||||||
files.extend(
|
files.extend(
|
||||||
subentries
|
subentries
|
||||||
.filter_map(|f| f.ok().map(|f| f.path()))
|
.filter_map(|f| f.ok().map(|f| f.path()))
|
||||||
.filter(|p| TimeUtils::datetime_from_path(p).is_some()),
|
.filter_map(|p| TimeUtils::datetime_from_path(&p).map(|dt| (dt, p))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files.sort();
|
files.sort();
|
||||||
Some(files)
|
Some(files.into_iter().map(|(_, p)| p).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_latest_hourly_file(root: &Path) -> Option<PathBuf> {
|
pub fn find_latest_hourly_file(root: &Path) -> Option<PathBuf> {
|
||||||
|
|||||||
@ -193,3 +193,22 @@ async fn test_update_last_fetch_fallback() -> eyre::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hourly_files_sort() -> eyre::Result<()> {
|
||||||
|
let temp_dir = tempfile::tempdir()?;
|
||||||
|
// create 20250826/9, 20250826/14
|
||||||
|
let targets = [("20250826", "9"), ("20250826", "14")];
|
||||||
|
for (date, hour) in targets {
|
||||||
|
let hourly_file = temp_dir.path().join(HOURLY_SUBDIR).join(date).join(hour);
|
||||||
|
let parent = hourly_file.parent().unwrap();
|
||||||
|
std::fs::create_dir_all(parent)?;
|
||||||
|
std::fs::File::create(hourly_file)?;
|
||||||
|
}
|
||||||
|
let files = FileOperations::all_hourly_files(temp_dir.path()).unwrap();
|
||||||
|
let file_names: Vec<_> =
|
||||||
|
files.into_iter().map(|p| p.file_name().unwrap().to_string_lossy().into_owned()).collect();
|
||||||
|
|
||||||
|
assert_eq!(file_names, ["9", "14"]);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user