mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-05 20:51:53 -07:00
Fixes #433 do not stop recording when deleting a past entry
This commit is contained in:
+33
-34
@@ -20,7 +20,7 @@ use tokio_util::task::TaskTracker;
|
|||||||
|
|
||||||
use crate::analysis::{AnalysisCtrlMessage, AnalysisWriter};
|
use crate::analysis::{AnalysisCtrlMessage, AnalysisWriter};
|
||||||
use crate::display;
|
use crate::display;
|
||||||
use crate::qmdl_store::{RecordingStore, RecordingStoreError};
|
use crate::qmdl_store::{EntryType, RecordingStore, RecordingStoreError};
|
||||||
use crate::server::ServerState;
|
use crate::server::ServerState;
|
||||||
|
|
||||||
pub enum DiagDeviceCtrlMessage {
|
pub enum DiagDeviceCtrlMessage {
|
||||||
@@ -199,41 +199,40 @@ pub async fn delete_recording(
|
|||||||
}
|
}
|
||||||
let mut qmdl_store = state.qmdl_store_lock.write().await;
|
let mut qmdl_store = state.qmdl_store_lock.write().await;
|
||||||
match qmdl_store.delete_entry(&qmdl_name).await {
|
match qmdl_store.delete_entry(&qmdl_name).await {
|
||||||
Err(RecordingStoreError::NoSuchEntryError) => {
|
Err(RecordingStoreError::NoSuchEntryError) => Err((
|
||||||
return Err((
|
StatusCode::BAD_REQUEST,
|
||||||
StatusCode::BAD_REQUEST,
|
format!("no recording with name {qmdl_name}"),
|
||||||
format!("no recording with name {qmdl_name}"),
|
)),
|
||||||
));
|
Err(e) => Err((
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
format!("couldn't delete recording: {e}"),
|
||||||
|
)),
|
||||||
|
Ok(entry_type) => {
|
||||||
|
if entry_type == EntryType::Current {
|
||||||
|
state
|
||||||
|
.diag_device_ctrl_sender
|
||||||
|
.send(DiagDeviceCtrlMessage::StopRecording)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
(
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
format!("couldn't send stop recording message: {e}"),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
state
|
||||||
|
.ui_update_sender
|
||||||
|
.send(display::DisplayState::Paused)
|
||||||
|
.await
|
||||||
|
.map_err(|e| {
|
||||||
|
(
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
format!("couldn't send ui update message: {e}"),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
Ok((StatusCode::ACCEPTED, "ok".to_string()))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
return Err((
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("couldn't delete recording: {e}"),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(_) => {}
|
|
||||||
}
|
}
|
||||||
state
|
|
||||||
.diag_device_ctrl_sender
|
|
||||||
.send(DiagDeviceCtrlMessage::StopRecording)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("couldn't send stop recording message: {e}"),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
state
|
|
||||||
.ui_update_sender
|
|
||||||
.send(display::DisplayState::Paused)
|
|
||||||
.await
|
|
||||||
.map_err(|e| {
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
format!("couldn't send ui update message: {e}"),
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
Ok((StatusCode::ACCEPTED, "ok".to_string()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_all_recordings(
|
pub async fn delete_all_recordings(
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ pub struct ManifestEntry {
|
|||||||
pub arch: Option<String>,
|
pub arch: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
pub enum EntryType {
|
||||||
|
Current,
|
||||||
|
Past,
|
||||||
|
}
|
||||||
|
|
||||||
impl ManifestEntry {
|
impl ManifestEntry {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
@@ -341,20 +347,24 @@ impl RecordingStore {
|
|||||||
Some((entry_index, &self.manifest.entries[entry_index]))
|
Some((entry_index, &self.manifest.entries[entry_index]))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_entry(&mut self, name: &str) -> Result<ManifestEntry, RecordingStoreError> {
|
pub async fn delete_entry(&mut self, name: &str) -> Result<EntryType, RecordingStoreError> {
|
||||||
let entry_to_delete_idx = self
|
let entry_to_delete_idx = self
|
||||||
.manifest
|
.manifest
|
||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.position(|entry| entry.name == name)
|
.position(|entry| entry.name == name)
|
||||||
.ok_or(RecordingStoreError::NoSuchEntryError)?;
|
.ok_or(RecordingStoreError::NoSuchEntryError)?;
|
||||||
if let Some(current_entry) = self.current_entry {
|
let is_current = match self.current_entry {
|
||||||
if current_entry == entry_to_delete_idx {
|
Some(current_entry) if current_entry == entry_to_delete_idx => {
|
||||||
self.close_current_entry().await?;
|
self.close_current_entry().await?;
|
||||||
} else {
|
EntryType::Current
|
||||||
self.current_entry = Some(current_entry - 1);
|
|
||||||
}
|
}
|
||||||
}
|
Some(current_entry) => {
|
||||||
|
self.current_entry = Some(current_entry - 1);
|
||||||
|
EntryType::Past
|
||||||
|
}
|
||||||
|
None => EntryType::Past,
|
||||||
|
};
|
||||||
let entry_to_delete = self.manifest.entries.remove(entry_to_delete_idx);
|
let entry_to_delete = self.manifest.entries.remove(entry_to_delete_idx);
|
||||||
self.write_manifest().await?;
|
self.write_manifest().await?;
|
||||||
let qmdl_filepath = entry_to_delete.get_qmdl_filepath(&self.path);
|
let qmdl_filepath = entry_to_delete.get_qmdl_filepath(&self.path);
|
||||||
@@ -365,7 +375,7 @@ impl RecordingStore {
|
|||||||
remove_file_if_exists(&analysis_filepath)
|
remove_file_if_exists(&analysis_filepath)
|
||||||
.await
|
.await
|
||||||
.map_err(RecordingStoreError::DeleteFileError)?;
|
.map_err(RecordingStoreError::DeleteFileError)?;
|
||||||
Ok(entry_to_delete)
|
Ok(is_current)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_all_entries(&mut self) -> Result<(), RecordingStoreError> {
|
pub async fn delete_all_entries(&mut self) -> Result<(), RecordingStoreError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user