recreate manifest entries if manifest is recreated due to error fixes #199

This commit is contained in:
Cooper Quintin
2025-06-03 18:18:27 -07:00
committed by Cooper Quintin
parent a72e4b2234
commit 5db24e4b21
2 changed files with 61 additions and 2 deletions

View File

@@ -34,6 +34,8 @@ use diag::{
use log::{error, info};
use qmdl_store::RecordingStoreError;
use rayhunter::diag_device::DiagDevice;
use std::path::Path;
use tokio::fs;
use tokio::net::TcpListener;
use tokio::select;
use tokio::sync::mpsc::{self, Sender};
@@ -109,7 +111,27 @@ async fn init_qmdl_store(config: &config::Config) -> Result<RecordingStore, Rayh
Err(RecordingStoreError::ParseManifestError(err)) => {
error!("failed to parse QMDL manifest: {err}");
info!("creating new empty manifest...");
Ok(RecordingStore::create(&config.qmdl_store_path).await?)
let mut recording_store = RecordingStore::create(&config.qmdl_store_path).await?;
info!("parsing existing qmdl files into recording store...");
let path = Path::new(&config.qmdl_store_path);
let mut entries = fs::read_dir(path).await?;
// We might want to sort these newest to oldest so we don't have entries in manifest.toml in random order
while let Some(entry) = entries.next_entry().await? {
let file_name = entry.file_name();
let file_name_str = match file_name.to_str() {
Some(s) => s,
None => continue, // skip non-UTF-8 names
};
if file_name_str.ends_with(".qmdl") {
let name = file_name_str.trim_end_matches(".qmdl");
info!("making entry for {}", name);
recording_store.new_entry_from_existing(name.to_string()).await?;
}
}
Ok(recording_store)
}
Err(err) => Err(err.into()),
}