diff --git a/src/scan_manager/menu.rs b/src/scan_manager/menu.rs index 9d85024..04751c4 100644 --- a/src/scan_manager/menu.rs +++ b/src/scan_manager/menu.rs @@ -210,10 +210,14 @@ impl Menu { } }); } else { + if value.is_empty() { + continue; + } + let value = self.str_to_usize(value); - if value != 0 && !nums.contains(&value) { - // the zeroth scan is always skipped, skip already known values + if !nums.contains(&value) { + // skip already known values nums.push(value); } } diff --git a/src/scan_manager/scan.rs b/src/scan_manager/scan.rs index 84e09ad..82426cd 100644 --- a/src/scan_manager/scan.rs +++ b/src/scan_manager/scan.rs @@ -39,6 +39,7 @@ pub struct FeroxScan { pub scan_type: ScanType, /// The order in which the scan was received + #[allow(dead_code)] // not entirely sure this isn't used somewhere pub(crate) scan_order: ScanOrder, /// Number of requests to populate the progress bar with diff --git a/src/scan_manager/scan_container.rs b/src/scan_manager/scan_container.rs index 9e99876..a22a044 100644 --- a/src/scan_manager/scan_container.rs +++ b/src/scan_manager/scan_container.rs @@ -325,11 +325,6 @@ impl FeroxScans { let mut printed = 0; for (i, scan) in scans.iter().enumerate() { - if matches!(scan.scan_order, ScanOrder::Initial) || scan.task.try_lock().is_err() { - // original target passed in via either -u or --stdin - continue; - } - if matches!(scan.scan_type, ScanType::Directory) { if printed == 0 { self.menu @@ -378,14 +373,13 @@ impl FeroxScans { if input == 'y' || input == '\n' { self.menu.println(&format!("Stopping {}...", selected.url)); - selected .abort() .await .unwrap_or_else(|e| log::warn!("Could not cancel task: {}", e)); let pb = selected.progress_bar(); - num_cancelled += pb.length() as usize - pb.position() as usize + num_cancelled += pb.length() as usize - pb.position() as usize; } else { self.menu.println("Ok, doing nothing..."); } @@ -459,6 +453,32 @@ impl FeroxScans { self.menu.show_progress_bars(); + let has_active_scans = if let Ok(guard) = self.scans.read() { + guard.iter().any(|s| s.is_active()) + } else { + // if we can't tell for sure, we'll let it ride + // + // i'm not sure which is the better option here: + // either return true and let it potentially hang, or + // return false and exit, so just going with not + // abruptly exiting for maybe no reason + true + }; + + if !has_active_scans { + // the last active scan was cancelled, so we can exit + self.menu.println(&format!( + " 😱 no more active scans... {}", + style("exiting").red() + )); + + let (tx, rx) = tokio::sync::oneshot::channel::(); + handles + .send_scan_command(Command::JoinTasks(tx)) + .unwrap_or_default(); + rx.await.unwrap_or_default(); + } + result } diff --git a/src/scan_manager/tests.rs b/src/scan_manager/tests.rs index ce0c81f..88626c4 100644 --- a/src/scan_manager/tests.rs +++ b/src/scan_manager/tests.rs @@ -668,11 +668,7 @@ fn menu_get_command_input_from_user_returns_cancel() { assert!(matches!(result, MenuCmd::Cancel(_, _))); if let MenuCmd::Cancel(canx_list, ret_force) = result { - if idx == 0 { - assert!(canx_list.is_empty()); - } else { - assert_eq!(canx_list, vec![idx]); - } + assert_eq!(canx_list, vec![idx]); assert_eq!(force, ret_force); } }