mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-24 08:18:11 -07:00
Fix WebDAV not uploading GPS files
When merging WebDAV and GPS features, we forgot to update the WebDAV feature to also upload the GPS files. WebDAV had hardcoded knowledge of which files exist and its own FileKind enum. Move the FileKind enum into QMDL store so that webdav can be agnostic over which files belong to a recording, so this is less likely to happen again. (This refactor was AI-assisted)
This commit is contained in:
committed by
Markus Unterwaditzer
parent
517a17db14
commit
e3e84a0185
@@ -1,3 +1,4 @@
|
||||
use std::fmt::Display;
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -43,6 +44,40 @@ pub enum RecordingStoreError {
|
||||
SerializationError(#[from] serde_json::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FileKind {
|
||||
Qmdl,
|
||||
Analysis,
|
||||
Gps,
|
||||
}
|
||||
|
||||
impl FileKind {
|
||||
// List of all possible physical files on disk.
|
||||
pub const ALL: &'static [FileKind] = &[FileKind::Qmdl, FileKind::Analysis, FileKind::Gps];
|
||||
|
||||
pub fn get_filename(&self, entry_name: &str) -> String {
|
||||
match self {
|
||||
FileKind::Qmdl => format!("{}.qmdl", entry_name),
|
||||
FileKind::Analysis => format!("{}.ndjson", entry_name),
|
||||
FileKind::Gps => format!("{}-gps.ndjson", entry_name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_filepath<P: AsRef<Path>>(&self, entry_name: &str, base_path: P) -> PathBuf {
|
||||
base_path.as_ref().join(self.get_filename(entry_name))
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FileKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
FileKind::Qmdl => write!(f, "QMDL"),
|
||||
FileKind::Analysis => write!(f, "analysis"),
|
||||
FileKind::Gps => write!(f, "GPS"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RecordingStore {
|
||||
pub path: PathBuf,
|
||||
pub manifest: Manifest,
|
||||
@@ -102,19 +137,15 @@ impl ManifestEntry {
|
||||
}
|
||||
|
||||
pub fn get_qmdl_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
|
||||
let mut filepath = path.as_ref().join(&self.name);
|
||||
filepath.set_extension("qmdl");
|
||||
filepath
|
||||
FileKind::Qmdl.get_filepath(&self.name, path)
|
||||
}
|
||||
|
||||
pub fn get_analysis_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
|
||||
let mut filepath = path.as_ref().join(&self.name);
|
||||
filepath.set_extension("ndjson");
|
||||
filepath
|
||||
FileKind::Analysis.get_filepath(&self.name, path)
|
||||
}
|
||||
|
||||
pub fn get_gps_filepath<P: AsRef<Path>>(&self, path: P) -> PathBuf {
|
||||
path.as_ref().join(format!("{}-gps.ndjson", self.name))
|
||||
FileKind::Gps.get_filepath(&self.name, path)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,9 +346,19 @@ impl RecordingStore {
|
||||
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,
|
||||
file_kind: FileKind,
|
||||
) -> Result<Option<File>, RecordingStoreError> {
|
||||
let entry = &self.manifest.entries[entry_index];
|
||||
match File::open(entry.get_gps_filepath(&self.path)).await {
|
||||
let filepath = file_kind.get_filepath(&entry.name, &self.path);
|
||||
|
||||
match File::open(&filepath).await {
|
||||
Ok(file) => Ok(Some(file)),
|
||||
Err(e) if e.kind() == ErrorKind::NotFound => Ok(None),
|
||||
Err(e) => Err(RecordingStoreError::ReadFileError(e)),
|
||||
|
||||
Reference in New Issue
Block a user