Fix clippy complaints

This commit is contained in:
Simon Fondrie-Teitler
2025-06-27 13:32:59 -04:00
committed by Markus Unterwaditzer
parent 2b86691e57
commit 94289dcad5
13 changed files with 67 additions and 74 deletions

View File

@@ -137,20 +137,20 @@ async fn perform_analysis(
enable_dummy_analyzer: bool,
analyzer_config: &AnalyzerConfig,
) -> Result<(), String> {
info!("Opening QMDL and analysis file for {}...", name);
info!("Opening QMDL and analysis file for {name}...");
let (analysis_file, qmdl_file, entry_index) = {
let mut qmdl_store = qmdl_store_lock.write().await;
let (entry_index, _) = qmdl_store
.entry_for_name(name)
.ok_or(format!("failed to find QMDL store entry for {}", name))?;
.ok_or(format!("failed to find QMDL store entry for {name}"))?;
let analysis_file = qmdl_store
.clear_and_open_entry_analysis(entry_index)
.await
.map_err(|e| format!("{:?}", e))?;
.map_err(|e| format!("{e:?}"))?;
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
.await
.map_err(|e| format!("{:?}", e))?;
.map_err(|e| format!("{e:?}"))?;
(analysis_file, qmdl_file, entry_index)
};
@@ -158,7 +158,7 @@ async fn perform_analysis(
let mut analysis_writer =
AnalysisWriter::new(analysis_file, enable_dummy_analyzer, analyzer_config)
.await
.map_err(|e| format!("{:?}", e))?;
.map_err(|e| format!("{e:?}"))?;
let file_size = qmdl_file
.metadata()
.await
@@ -169,7 +169,7 @@ async fn perform_analysis(
.as_stream()
.try_filter(|container| future::ready(container.data_type == DataType::UserSpace)));
info!("Starting analysis for {}...", name);
info!("Starting analysis for {name}...");
while let Some(container) = qmdl_stream
.try_next()
.await
@@ -178,20 +178,20 @@ async fn perform_analysis(
let (size_bytes, _) = analysis_writer
.analyze(container)
.await
.map_err(|e| format!("{:?}", e))?;
debug!("{} analysis: {} bytes written", name, size_bytes);
.map_err(|e| format!("{e:?}"))?;
debug!("{name} analysis: {size_bytes} bytes written");
let mut qmdl_store = qmdl_store_lock.write().await;
qmdl_store
.update_entry_analysis_size(entry_index, size_bytes)
.await
.map_err(|e| format!("{:?}", e))?;
.map_err(|e| format!("{e:?}"))?;
}
analysis_writer
.close()
.await
.map_err(|e| format!("{:?}", e))?;
info!("Analysis for {} complete!", name);
.map_err(|e| format!("{e:?}"))?;
info!("Analysis for {name} complete!");
Ok(())
}
@@ -219,7 +219,7 @@ pub fn run_analysis_thread(
)
.await
{
error!("failed to analyze {}: {}", name, err);
error!("failed to analyze {name}: {err}");
}
finish_running_analysis(analysis_status_lock.clone()).await;
}
@@ -280,7 +280,7 @@ pub async fn start_analysis(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to queue new analysis files: {:?}", e),
format!("failed to queue new analysis files: {e:?}"),
)
})?;
}

View File

@@ -84,14 +84,13 @@ async fn analyze_file(enable_dummy_analyzer: bool, qmdl_path: &str, show_skipped
}
}
if show_skipped && skipped > 0 {
info!("{}: messages skipped:", qmdl_path);
info!("{qmdl_path}: messages skipped:");
for (reason, count) in skipped_reasons.iter() {
info!(" - {}: \"{}\"", count, reason);
info!(" - {count}: \"{reason}\"");
}
}
info!(
"{}: {} messages analyzed, {} warnings, {} messages skipped",
qmdl_path, total_messages, warnings, skipped
"{qmdl_path}: {total_messages} messages analyzed, {warnings} warnings, {skipped} messages skipped"
);
}

View File

@@ -108,7 +108,7 @@ async fn init_qmdl_store(config: &config::Config) -> Result<RecordingStore, Rayh
match RecordingStore::load(&config.qmdl_store_path).await {
Ok(store) => Ok(store),
Err(RecordingStoreError::ParseManifestError(err)) => {
error!("failed to parse QMDL manifest: {}", err);
error!("failed to parse QMDL manifest: {err}");
info!("creating new empty manifest...");
Ok(RecordingStore::create(&config.qmdl_store_path).await?)
}
@@ -139,14 +139,14 @@ fn run_shutdown_thread(
select! {
res = tokio::signal::ctrl_c() => {
if let Err(err) = res {
error!("Unable to listen for shutdown signal: {}", err);
error!("Unable to listen for shutdown signal: {err}");
}
should_restart_flag.store(false, Ordering::Relaxed);
}
res = daemon_restart_rx => {
if let Err(err) = res {
error!("Unable to listen for shutdown signal: {}", err);
error!("Unable to listen for shutdown signal: {err}");
}
should_restart_flag.store(true, Ordering::Relaxed);

View File

@@ -54,7 +54,7 @@ pub fn run_diag_read_thread(
let (qmdl_file, new_analysis_file) = match qmdl_store.new_entry().await {
Ok(x) => x,
Err(e) => {
error!("couldn't create new qmdl entry: {}", e);
error!("couldn't create new qmdl entry: {e}");
continue;
}
};
@@ -69,7 +69,7 @@ pub fn run_diag_read_thread(
.expect("failed to write to analysis file"));
if let Err(e) = ui_update_sender.send(display::DisplayState::Recording).await {
warn!("couldn't send ui update message: {}", e);
warn!("couldn't send ui update message: {e}");
}
},
Some(DiagDeviceCtrlMessage::StopRecording) => {
@@ -80,11 +80,11 @@ pub fn run_diag_read_thread(
entry.name.to_string(),
))
.await {
warn!("couldn't send analysis message: {}", e);
warn!("couldn't send analysis message: {e}");
}
}
if let Err(e) = qmdl_store.close_current_entry().await {
error!("couldn't close current entry: {}", e);
error!("couldn't close current entry: {e}");
}
maybe_qmdl_writer = None;
@@ -94,7 +94,7 @@ pub fn run_diag_read_thread(
maybe_analysis_writer = None;
if let Err(e) = ui_update_sender.send(display::DisplayState::Paused).await {
warn!("couldn't send ui update message: {}", e);
warn!("couldn't send ui update message: {e}");
}
},
// None means all the Senders have been dropped, so it's
@@ -145,7 +145,7 @@ pub fn run_diag_read_thread(
}
},
Err(err) => {
error!("error reading diag device: {}", err);
error!("error reading diag device: {err}");
return Err(err);
}
}
@@ -169,7 +169,7 @@ pub async fn start_recording(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send start recording message: {}", e),
format!("couldn't send start recording message: {e}"),
)
})?;
@@ -189,7 +189,7 @@ pub async fn stop_recording(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send stop recording message: {}", e),
format!("couldn't send stop recording message: {e}"),
)
})?;
Ok((StatusCode::ACCEPTED, "ok".to_string()))
@@ -225,7 +225,7 @@ pub async fn delete_recording(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send stop recording message: {}", e),
format!("couldn't send stop recording message: {e}"),
)
})?;
state
@@ -235,7 +235,7 @@ pub async fn delete_recording(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send ui update message: {}", e),
format!("couldn't send ui update message: {e}"),
)
})?;
Ok((StatusCode::ACCEPTED, "ok".to_string()))
@@ -254,14 +254,14 @@ pub async fn delete_all_recordings(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send stop recording message: {}", e),
format!("couldn't send stop recording message: {e}"),
)
})?;
let mut qmdl_store = state.qmdl_store_lock.write().await;
qmdl_store.delete_all_entries().await.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't delete all recordings: {}", e),
format!("couldn't delete all recordings: {e}"),
)
})?;
state
@@ -271,7 +271,7 @@ pub async fn delete_all_recordings(
.map_err(|e| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("couldn't send ui update message: {}", e),
format!("couldn't send ui update message: {e}"),
)
})?;
Ok((StatusCode::ACCEPTED, "ok".to_string()))
@@ -290,13 +290,13 @@ pub async fn get_analysis_report(
} else {
qmdl_store.entry_for_name(&qmdl_name).ok_or((
StatusCode::NOT_FOUND,
format!("Couldn't find QMDL entry with name \"{}\"", qmdl_name),
format!("Couldn't find QMDL entry with name \"{qmdl_name}\""),
))?
};
let analysis_file = qmdl_store
.open_entry_analysis(entry_index)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{:?}", e)))?;
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?;
let analysis_stream = ReaderStream::new(analysis_file);
let headers = [(CONTENT_TYPE, "application/x-ndjson")];

View File

@@ -32,7 +32,7 @@ pub fn run_key_input_thread(
let mut file = match File::open("/dev/input/event0").await {
Ok(file) => file,
Err(e) => {
error!("Failed to open /dev/input/event0: {}", e);
error!("Failed to open /dev/input/event0: {e}");
return;
}
};
@@ -49,7 +49,7 @@ pub fn run_key_input_thread(
}
result = file.read_exact(&mut buffer) => {
if let Err(e) = result {
error!("failed to read key input: {}", e);
error!("failed to read key input: {e}");
return;
}
}
@@ -79,12 +79,12 @@ pub fn run_key_input_thread(
{
if let Err(e) = diag_tx.send(DiagDeviceCtrlMessage::StopRecording).await
{
error!("Failed to send StopRecording: {}", e);
error!("Failed to send StopRecording: {e}");
}
if let Err(e) =
diag_tx.send(DiagDeviceCtrlMessage::StartRecording).await
{
error!("Failed to send StartRecording: {}", e);
error!("Failed to send StartRecording: {e}");
}
last_keyup = None;
continue;

View File

@@ -28,7 +28,7 @@ pub async fn get_pcap(
}
let (entry_index, entry) = qmdl_store.entry_for_name(&qmdl_name).ok_or((
StatusCode::NOT_FOUND,
format!("couldn't find manifest entry with name {}", qmdl_name),
format!("couldn't find manifest entry with name {qmdl_name}"),
))?;
if entry.qmdl_size_bytes == 0 {
return Err((
@@ -40,14 +40,14 @@ pub async fn get_pcap(
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{:?}", e)))?;
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("{e:?}")))?;
// the QMDL reader should stop at the last successfully written data chunk
// (entry.size_bytes)
let (reader, writer) = duplex(1024);
tokio::spawn(async move {
if let Err(e) = generate_pcap_data(writer, qmdl_file, qmdl_size_bytes).await {
error!("failed to generate PCAP: {:?}", e);
error!("failed to generate PCAP: {e:?}");
}
});
@@ -84,7 +84,7 @@ where
.await?;
}
}
Err(e) => error!("error parsing message: {:?}", e),
Err(e) => error!("error parsing message: {e:?}"),
}
}
}

View File

@@ -44,7 +44,7 @@ pub async fn get_qmdl(
let qmdl_store = state.qmdl_store_lock.read().await;
let (entry_index, entry) = qmdl_store.entry_for_name(qmdl_idx).ok_or((
StatusCode::NOT_FOUND,
format!("couldn't find qmdl file with name {}", qmdl_idx),
format!("couldn't find qmdl file with name {qmdl_idx}"),
))?;
let qmdl_file = qmdl_store
.open_entry_qmdl(entry_index)
@@ -52,7 +52,7 @@ pub async fn get_qmdl(
.map_err(|err| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("error opening QMDL file: {}", err),
format!("error opening QMDL file: {err}"),
)
})?;
let limited_qmdl_file = qmdl_file.take(entry.qmdl_size_bytes as u64);
@@ -105,14 +105,14 @@ pub async fn set_config(
let config_str = toml::to_string_pretty(&config).map_err(|err| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to serialize config as TOML: {}", err),
format!("failed to serialize config as TOML: {err}"),
)
})?;
write(&state.config_path, config_str).await.map_err(|err| {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("failed to write config file: {}", err),
format!("failed to write config file: {err}"),
)
})?;
@@ -146,7 +146,7 @@ pub async fn get_zip(
let qmdl_store = state.qmdl_store_lock.read().await;
let (entry_index, entry) = qmdl_store.entry_for_name(&qmdl_idx).ok_or((
StatusCode::NOT_FOUND,
format!("couldn't find entry with name {}", qmdl_idx),
format!("couldn't find entry with name {qmdl_idx}"),
))?;
if entry.qmdl_size_bytes == 0 {
@@ -207,7 +207,7 @@ pub async fn get_zip(
{
// if we fail to generate the PCAP file, we should still continue and give the
// user the QMDL.
error!("Failed to generate PCAP: {:?}", e);
error!("Failed to generate PCAP: {e:?}");
}
entry_writer.into_inner().close().await?;
@@ -219,7 +219,7 @@ pub async fn get_zip(
.await;
if let Err(e) = result {
error!("Error generating ZIP file: {:?}", e);
error!("Error generating ZIP file: {e:?}");
}
});
@@ -283,7 +283,7 @@ mod tests {
let analysis_status = {
let store = store_lock.try_read().unwrap();
crate::analysis::AnalysisStatus::new(&*store)
crate::analysis::AnalysisStatus::new(&store)
};
Arc::new(ServerState {

View File

@@ -102,7 +102,7 @@ impl MemoryStats {
// turns a number of kilobytes (like 28293) into a human-readable string (like "28.3M")
fn humanize_kb(kb: usize) -> String {
if kb < 1000 {
return format!("{}K", kb);
return format!("{kb}K");
}
format!("{:.1}M", kb as f64 / 1024.0)
}
@@ -114,7 +114,7 @@ pub async fn get_system_stats(
match SystemStats::new(qmdl_store.path.to_str().unwrap()).await {
Ok(stats) => Ok(Json(stats)),
Err(err) => {
error!("error getting system stats: {}", err);
error!("error getting system stats: {err}");
Err((
StatusCode::INTERNAL_SERVER_ERROR,
"error getting system stats".to_string(),