fix error lua & firmware peek

This commit is contained in:
Pakin 2025-09-08 11:07:13 +07:00
parent 95c57a6333
commit 95fd7f8e03
2 changed files with 26 additions and 18 deletions

View file

@ -6,7 +6,7 @@ edition = "2024"
[dependencies]
chrono = "0.4.41"
log = "0.4.27"
mlua = "0.11.3"
mlua = { version = "0.11.3", features = ["lua54"] }
rand = "0.9.2"
rayon = "1.10.0"
serde = { version = "1.0.219", features = ["derive", "serde_derive"] }

View file

@ -27,12 +27,20 @@ impl Peekable for LastBuildFirmware {
fn peek(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
let mut peeked = Vec::new();
let file = File::open(self.path).unwrap();
let file = File::open(self.path.clone()).unwrap();
let mut ar = Archive::new(file);
for file2 in ar.entries().unwrap() {
let mut f = file2.unwrap();
peeked.push(f.path().unwrap().file_name().unwrap().to_str().unwrap());
let f = file2.unwrap();
peeked.push(
f.path()
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string(),
);
}
Ok(peeked)
@ -40,8 +48,6 @@ impl Peekable for LastBuildFirmware {
}
pub fn read_last_build_firmwares() -> Result<Vec<LastBuildFirmware>, Box<dyn std::error::Error>> {
let mut result = Vec::new();
// get config
let ucfg = common::get_config();
let firmware_dir = ucfg
@ -49,30 +55,32 @@ pub fn read_last_build_firmwares() -> Result<Vec<LastBuildFirmware>, Box<dyn std
.expect("Unknown firmware directory, check .tbcfg");
// parallel walk to dir
walkdir::WalkDir::new(firmware_dir)
let result = walkdir::WalkDir::new(firmware_dir)
.max_depth(2)
.into_iter()
.par_bridge()
.filter(|w| {
let filename = w.ok().unwrap().file_name().to_str().unwrap();
filename.ends_with(".tar") || filename.ends_with(".zip")
let filename = &w.as_ref().unwrap().clone();
let file_clone = filename.file_name().to_str().unwrap();
file_clone.ends_with(".tar") || file_clone.ends_with(".zip")
})
.for_each(|entry| {
let dir = entry?;
let meta = dir.clone().metadata()?;
.map(|entry| {
let dir = entry.unwrap();
let meta = dir.clone().metadata().unwrap();
let filename = dir.clone().file_name().to_str().unwrap();
let mod_time: DateTime<Utc> = meta.modified()?.into();
let filename = dir.clone().file_name().to_str().unwrap().to_string();
let mod_time: DateTime<Utc> = meta.modified().unwrap().into();
let full_firmware = filename.clone().contains("full");
result.push(LastBuildFirmware {
path: filename.clone(),
LastBuildFirmware {
path: filename,
date: mod_time,
is_full: full_firmware,
entries: Vec::new(),
tags: None,
});
});
}
})
.collect();
Ok(result)
}