Remove redundant helper functions

This commit is contained in:
Markus Unterwaditzer
2026-05-19 23:41:55 +02:00
committed by Markus Unterwaditzer
parent 4bad8356ac
commit 754faf10d9
5 changed files with 25 additions and 53 deletions

View File

@@ -18,7 +18,7 @@ use tokio::sync::mpsc::Receiver;
use tokio::sync::{RwLock, RwLockWriteGuard};
use tokio_util::task::TaskTracker;
use crate::qmdl_store::RecordingStore;
use crate::qmdl_store::{FileKind, RecordingStore};
use crate::server::ServerState;
pub struct AnalysisWriter {
@@ -145,9 +145,10 @@ async fn perform_analysis(
.await
.map_err(|e| format!("{e:?}"))?;
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
.open_file(entry_index, FileKind::Qmdl)
.await
.map_err(|e| format!("{e:?}"))?;
.map_err(|e| format!("{e:?}"))?
.ok_or("QMDL file not found")?;
(analysis_file, qmdl_file)
};

View File

@@ -31,7 +31,7 @@ use crate::analysis::{AnalysisCtrlMessage, AnalysisWriter};
use crate::config::GpsMode;
use crate::display;
use crate::notifications::{Notification, NotificationType};
use crate::qmdl_store::{RecordingStore, RecordingStoreError};
use crate::qmdl_store::{FileKind, RecordingStore, RecordingStoreError};
use crate::server::ServerState;
use crate::stats::DiskStats;
@@ -747,9 +747,10 @@ pub async fn get_analysis_report(
))?
};
let analysis_file = qmdl_store
.open_entry_analysis(entry_index)
.open_file(entry_index, FileKind::Analysis)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?;
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?
.ok_or((StatusCode::NOT_FOUND, "Analysis file not found".to_string()))?;
// Read and normalize the NDJSON file
let reader = BufReader::new(analysis_file);

View File

@@ -1,4 +1,5 @@
use crate::gps::{GpsRecord, load_gps_records};
use crate::qmdl_store::FileKind;
use crate::server::ServerState;
use crate::config::GpsMode;
@@ -52,9 +53,10 @@ pub async fn get_pcap(
}
let qmdl_size_bytes = entry.qmdl_size_bytes;
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
.open_file(entry_index, FileKind::Qmdl)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?;
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?
.ok_or((StatusCode::NOT_FOUND, "QMDL file not found".to_string()))?;
let (reader, writer) = duplex(1024);
let gps_records = load_gps_records_for_entry(&state, entry_index).await;
drop(qmdl_store);
@@ -75,7 +77,7 @@ pub(crate) async fn load_gps_records_for_entry(
entry_index: usize,
) -> Vec<GpsRecord> {
let qmdl_store = state.qmdl_store_lock.read().await;
match qmdl_store.open_entry_gps(entry_index).await {
match qmdl_store.open_file(entry_index, FileKind::Gps).await {
Ok(Some(file)) => load_gps_records(file).await,
Ok(None) => {
let gps_mode = qmdl_store

View File

@@ -136,16 +136,8 @@ impl ManifestEntry {
}
}
pub fn get_qmdl_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
FileKind::Qmdl.get_filepath(&self.name, path)
}
pub fn get_analysis_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
FileKind::Analysis.get_filepath(&self.name, path)
}
pub fn get_gps_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
FileKind::Gps.get_filepath(&self.name, path)
pub fn get_filepath<P: AsRef<Path>>(&self, file_kind: FileKind, path: P) -> PathBuf {
file_kind.get_filepath(&self.name, path)
}
}
@@ -306,15 +298,15 @@ impl RecordingStore {
self.close_current_entry().await?;
}
let new_entry = ManifestEntry::new(gps_mode);
let qmdl_filepath = new_entry.get_qmdl_filepath(&self.path);
let qmdl_filepath = new_entry.get_filepath(FileKind::Qmdl, &self.path);
let qmdl_file = File::create(&qmdl_filepath)
.await
.map_err(RecordingStoreError::CreateFileError)?;
let analysis_filepath = new_entry.get_analysis_filepath(&self.path);
let analysis_filepath = new_entry.get_filepath(FileKind::Analysis, &self.path);
let analysis_file = File::create(&analysis_filepath)
.await
.map_err(RecordingStoreError::CreateFileError)?;
let gps_filepath = new_entry.get_gps_filepath(&self.path);
let gps_filepath = new_entry.get_filepath(FileKind::Gps, &self.path);
File::create(&gps_filepath)
.await
.map_err(RecordingStoreError::CreateFileError)?;
@@ -324,32 +316,6 @@ impl RecordingStore {
Ok((qmdl_file, analysis_file))
}
// Returns the corresponding QMDL file for a given entry
pub async fn open_entry_qmdl(&self, entry_index: usize) -> Result<File, RecordingStoreError> {
let entry = &self.manifest.entries[entry_index];
File::open(entry.get_qmdl_filepath(&self.path))
.await
.map_err(RecordingStoreError::ReadFileError)
}
// Returns the corresponding QMDL file for a given entry
pub async fn open_entry_analysis(
&self,
entry_index: usize,
) -> Result<File, RecordingStoreError> {
let entry = &self.manifest.entries[entry_index];
File::open(entry.get_analysis_filepath(&self.path))
.await
.map_err(RecordingStoreError::ReadFileError)
}
pub async fn open_entry_gps(
&self,
entry_index: usize,
) -> Result<Option<File>, RecordingStoreError> {
self.open_file(entry_index, FileKind::Gps).await
}
pub async fn open_file(
&self,
entry_index: usize,
@@ -373,7 +339,7 @@ impl RecordingStore {
match OpenOptions::new()
.create(true)
.append(true)
.open(entry.get_gps_filepath(&self.path))
.open(entry.get_filepath(FileKind::Gps, &self.path))
.await
{
Ok(file) => Ok(Some(file)),
@@ -390,7 +356,7 @@ impl RecordingStore {
let file = OpenOptions::new()
.write(true)
.truncate(true)
.open(entry.get_analysis_filepath(&self.path))
.open(entry.get_filepath(FileKind::Analysis, &self.path))
.await
.map_err(RecordingStoreError::ReadFileError)?;
Ok(file)

View File

@@ -72,14 +72,15 @@ pub async fn get_qmdl(
format!("couldn't find qmdl file with name {qmdl_idx}"),
))?;
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
.open_file(entry_index, FileKind::Qmdl)
.await
.map_err(|err| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("error opening QMDL file: {err}"),
)
})?;
})?
.ok_or((StatusCode::NOT_FOUND, "QMDL file not found".to_string()))?;
let limited_qmdl_file = qmdl_file.take(entry.qmdl_size_bytes as u64);
let qmdl_stream = ReaderStream::new(limited_qmdl_file);
@@ -405,8 +406,9 @@ pub async fn get_zip(
let qmdl_file_for_pcap = {
let qmdl_store = qmdl_store_lock.read().await;
qmdl_store
.open_entry_qmdl(entry_index)
.open_file(entry_index, FileKind::Qmdl)
.await?
.ok_or_else(|| anyhow::anyhow!("QMDL file not found"))?
.take(qmdl_size_bytes as u64)
};