mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-01 18:53:34 -07:00
Fix similar bug in zip download, also use FileKind there
This commit is contained in:
committed by
Markus Unterwaditzer
parent
e3e84a0185
commit
7aaa7e589e
+28
-14
@@ -28,7 +28,7 @@ use crate::display::DisplayState;
|
|||||||
use crate::gps::GpsData;
|
use crate::gps::GpsData;
|
||||||
use crate::notifications::DEFAULT_NOTIFICATION_TIMEOUT;
|
use crate::notifications::DEFAULT_NOTIFICATION_TIMEOUT;
|
||||||
use crate::pcap::{generate_pcap_data, load_gps_records_for_entry};
|
use crate::pcap::{generate_pcap_data, load_gps_records_for_entry};
|
||||||
use crate::qmdl_store::RecordingStore;
|
use crate::qmdl_store::{FileKind, RecordingStore};
|
||||||
use crate::update::UpdateStatus;
|
use crate::update::UpdateStatus;
|
||||||
|
|
||||||
pub struct ServerState {
|
pub struct ServerState {
|
||||||
@@ -359,24 +359,34 @@ pub async fn get_zip(
|
|||||||
let result: Result<(), Error> = async {
|
let result: Result<(), Error> = async {
|
||||||
let mut zip = ZipFileWriter::with_tokio(writer);
|
let mut zip = ZipFileWriter::with_tokio(writer);
|
||||||
|
|
||||||
// Add QMDL file
|
// Add stored files
|
||||||
{
|
for &file_kind in FileKind::ALL {
|
||||||
let entry =
|
let file_opt = {
|
||||||
ZipEntryBuilder::new(format!("{qmdl_idx}.qmdl").into(), Compression::Stored);
|
let qmdl_store = qmdl_store_lock.read().await;
|
||||||
|
qmdl_store.open_file(entry_index, file_kind).await?
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(mut file) = file_opt else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
let entry = ZipEntryBuilder::new(
|
||||||
|
file_kind.get_filename(&qmdl_idx).into(),
|
||||||
|
Compression::Stored,
|
||||||
|
);
|
||||||
// FuturesAsyncWriteCompatExt::compat_write because async-zip's entrystream does
|
// FuturesAsyncWriteCompatExt::compat_write because async-zip's entrystream does
|
||||||
// not impl tokio's AsyncWrite, but only future's AsyncWrite. This can be removed
|
// not impl tokio's AsyncWrite, but only future's AsyncWrite. This can be removed
|
||||||
// once https://github.com/Majored/rs-async-zip/pull/160 is released.
|
// once https://github.com/Majored/rs-async-zip/pull/160 is released.
|
||||||
let mut entry_writer = zip.write_entry_stream(entry).await?.compat_write();
|
let mut entry_writer = zip.write_entry_stream(entry).await?.compat_write();
|
||||||
|
|
||||||
let mut qmdl_file = {
|
// Truncating to qmdl_size_bytes is an attempt to ignore partial writes by the diag
|
||||||
let qmdl_store = qmdl_store_lock.read().await;
|
// thread.
|
||||||
qmdl_store
|
if file_kind == FileKind::Qmdl {
|
||||||
.open_entry_qmdl(entry_index)
|
copy(&mut file.take(qmdl_size_bytes as u64), &mut entry_writer).await?;
|
||||||
.await?
|
} else {
|
||||||
.take(qmdl_size_bytes as u64)
|
copy(&mut file, &mut entry_writer).await?;
|
||||||
};
|
}
|
||||||
|
|
||||||
copy(&mut qmdl_file, &mut entry_writer).await?;
|
|
||||||
entry_writer.into_inner().close().await?;
|
entry_writer.into_inner().close().await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,7 +625,11 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
filenames,
|
filenames,
|
||||||
vec![format!("{entry_name}.qmdl"), format!("{entry_name}.pcapng"),]
|
vec![
|
||||||
|
format!("{entry_name}.qmdl"),
|
||||||
|
format!("{entry_name}-gps.ndjson"),
|
||||||
|
format!("{entry_name}.pcapng"),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user