future proofing against glob order of file

This commit is contained in:
ilgeco
2026-02-26 18:52:08 +01:00
parent 7b2baeacd3
commit 4febdf0c01

View File

@@ -1,4 +1,4 @@
use anyhow::{Context, Result, bail};
use anyhow::{bail, Context, Result};
use clap::Parser;
use glob::glob;
use pimcore::json_to_instruction::json_to_executor;
@@ -55,7 +55,6 @@ fn main() -> Result<()> {
Ok(())
}
fn populate_crossbar(args: &Args, executor: &mut pimcore::Executable) {
let num_cores = executor.cpu_mut().num_core();
@@ -94,12 +93,10 @@ fn populate_crossbar(args: &Args, executor: &mut pimcore::Executable) {
.execute_store(&bytes)
.unwrap();
}
}
}
}
fn dump_memory(mut executor: pimcore::Executable, args: &Args) -> Result<()> {
let dumps: Vec<(i32, i32)> = args
.dump
@@ -171,12 +168,18 @@ fn retrive_cores(args: &Args) -> Result<Vec<Value>, anyhow::Error> {
} else if let Some(folder) = args.folder.as_ref() {
let pattern = folder.join("core*.json");
let pattern_str = pattern.to_str().context("Invalid path encoding")?;
let paths: Vec<_> = glob(pattern_str)?.collect();
let mut paths: Vec<_> = glob(pattern_str)?.map(|x| x.unwrap()).collect();
paths.sort_by_cached_key(|x| {
let mut x = x.file_stem().expect("Extracting the stem").to_str().expect("File not utf-8");
x = &x[5..];
x.parse::<i32>().unwrap()
});
if paths.is_empty() {
bail!("No core*.json files found in {:?}", folder);
}
for entry in paths {
let path = entry?;
let path = entry;
let content = fs::read_to_string(&path)
.with_context(|| format!("Failed to read core file: {:?}", path))?;
let json: Value = serde_json::from_str(&content)