diff --git a/CHANGELOG.md b/CHANGELOG.md index 060985a..2120a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,14 @@ is on main, the release is published with that section as its notes (AGENTS.md, - On Linux, running Orchard as root leaves the USB access rule for your regular account in place. +- With the device named (`--ecid`, `--location`), other devices on USB no + longer hold the install or launch up: devices running m1n1 or Linux + elsewhere don't count, and the ibss route and checkra1n's start of iOS + go ahead beside them. checkra1n waits, and stops, while another device + it could take is in DFU, recovery or Pongo mode. +- On iOS 12 to 14, an installer started again while iOS runs as + checkra1n started it goes on at the split, without another round + through DFU mode. ### Command line diff --git a/crates/cli/src/commands/install.rs b/crates/cli/src/commands/install.rs index 72fce4a..9ca5f98 100644 --- a/crates/cli/src/commands/install.rs +++ b/crates/cli/src/commands/install.rs @@ -179,7 +179,15 @@ fn flow_options(access: Option<&str>, tool: &ToolFlags, busy_cpu: bool) -> Resul let seconds = tool.port_reset.or_else(|| env("ORCHARD_PORT_RESET_SECONDS")?.parse::().ok().map(|s| s.clamp(0., 15.).round() as u8)).unwrap_or(10); Ok(Some(orchard_flow::Options { helper, - start: None, + // The route named with --boot (or its short forms, or ORCHARD_BOOT): + // the flow has to know it too, since it decides by it whether other + // devices on USB hold a start up (the ibss route is addressed). + start: orchard_runtime::flags::chosen_boot().or_else(|| env("ORCHARD_BOOT")).and_then(|b| match b.as_str() { + "ibss" => Some(orchard_flow::Start::Ibss), + "checkra1n" => Some(orchard_flow::Start::Checkra1n), + "palera1n" => Some(orchard_flow::Start::Palera1n), + _ => None, + }), palera1n: if two { Palera1n::Two } else { Palera1n::Three }, port_reset: (seconds > 0).then_some(seconds), busy_cpu: busy_cpu || orchard_runtime::flags::busy_cpu(), diff --git a/crates/flow/src/lib.rs b/crates/flow/src/lib.rs index de0149d..985c6c5 100644 --- a/crates/flow/src/lib.rs +++ b/crates/flow/src/lib.rs @@ -1172,9 +1172,22 @@ fn step_inner(app: App, mut flow: Flow, event: Event) -> (Flow, Vec) { /// start of the device while other Apple devices are on USB. fn route(flow: &mut Flow, effects: Vec, out: &mut Vec) { let fetch = |assets: Vec| assets.into_iter().map(Effect::Fetch); + // Starts that are addressed to the device itself don't wait for other + // devices to go: the ibss route (gaster's worker matches the ECID, chip + // and board, and everything after it goes to the device's port), and + // checkra1n's start of iOS, which waits by itself for the devices + // checkra1n could take (access_checkra1n::start_ios). palera1n and + // checkra1n as boot routes take the first device they find, and wait. + let own_start = flow.state.device().is_some_and(|d| rules::start(&flow.options, d, false) == Some(Start::Ibss)); + let own_helper = flow.helper() == Some(Helper::Checkra1n); for effect in effects { + let addressed = match effect { + Effect::BootIpadosWithOverlay(_) => own_helper, + Effect::BootInstallEnv(_) | Effect::ListEntries(_) => own_start, + _ => false, + }; match effect { - Effect::BootIpadosWithOverlay(_) | Effect::BootInstallEnv(_) | Effect::ListEntries(_) if !flow.others.is_empty() => { + Effect::BootIpadosWithOverlay(_) | Effect::BootInstallEnv(_) | Effect::ListEntries(_) if !flow.others.is_empty() && !addressed => { if matches!(effect, Effect::BootIpadosWithOverlay(_)) { out.extend(fetch(flow.assets.start(&[Asset::Overlay]))); } diff --git a/crates/runtime/src/access_checkra1n.rs b/crates/runtime/src/access_checkra1n.rs index 39c3718..c60616d 100644 --- a/crates/runtime/src/access_checkra1n.rs +++ b/crates/runtime/src/access_checkra1n.rs @@ -69,30 +69,65 @@ fn on_host(mut error: Error, soc: &str, linux: bool) -> Error { /// checkra1n's start on the device, and the SSH connection it brings; a /// failure of either says what helps on this host. -fn start(executor: &Executor, soc: &str) -> Result<(String, Ssh)> { - let started = start_ios(executor).and_then(|udid| Ssh::open(&udid).map(|ssh| (udid, ssh))); +fn start(executor: &Executor, soc: &str, ecid: Option<&str>) -> Result<(String, Ssh)> { + let started = start_ios(executor, ecid).and_then(|udid| Ssh::open(&udid).map(|ssh| (udid, ssh))); started.map_err(|e| on_host(e, soc, cfg!(target_os = "linux"))) } -/// The one device running iOS on USB, by its UDID. -fn udid() -> Result> { - let mut usb: Vec<_> = usbmux::devices(Path::new(usbmux::SOCKET))?.into_iter().filter(|d| d.usb).collect(); - match usb.len() { - 0 => Ok(None), - 1 => Ok(Some(usb.remove(0).udid)), - _ => Err(fail("more than one device running iOS is connected; connect only the one to resize")), - } +/// The devices running iOS on USB, by their UDIDs. +fn udids() -> Result> { + Ok(usbmux::devices(Path::new(usbmux::SOCKET))?.into_iter().filter(|d| d.usb).map(|d| d.udid).collect()) +} + +/// Whether checkra1n's SSH server greets on this device. +fn greets(udid: &str) -> bool { + let Ok(mut stream) = usbmux::connect(Path::new(usbmux::SOCKET), udid, SSH_PORT) else { return false }; + let _ = stream.set_read_timeout(Some(Duration::from_secs(5))); + let mut greeting = [0u8; 4]; + stream.read_exact(&mut greeting).is_ok() && &greeting == b"SSH-" } /// The device whose SSH server sends its greeting over the cable: that, not /// checkra1n's exit, is the start having worked (its command line goes on /// waiting for the next DFU device). -fn ssh_answers() -> Result> { - let Some(udid) = udid()? else { return Ok(None) }; - let Ok(mut stream) = usbmux::connect(Path::new(usbmux::SOCKET), &udid, SSH_PORT) else { return Ok(None) }; - let _ = stream.set_read_timeout(Some(Duration::from_secs(5))); - let mut greeting = [0u8; 4]; - Ok((stream.read_exact(&mut greeting).is_ok() && &greeting == b"SSH-").then_some(udid)) +/// +/// With the target's ECID (`ecid`), other devices running iOS may stay +/// connected: only the device that tells this ECID over lockdown is asked +/// for the greeting, and nothing is sent to port 44 of any other. Without +/// an ECID there must be one device running iOS, as before. +fn ssh_answers(ecid: Option<&str>) -> Result> { + let mut usb = udids()?; + let udid = match ecid { + Some(wanted) => { + let is = |udid: &String| { + crate::lockdown::ask(Path::new(usbmux::SOCKET), udid).ok().and_then(|a| a.ecid).is_some_and(|e| crate::ecid_key(&e) == crate::ecid_key(wanted)) + }; + usb.into_iter().find(is) + } + None => match usb.len() { + 0 => None, + 1 => Some(usb.remove(0)), + _ => return Err(fail("more than one device running iOS is connected; connect only the one to resize, or name it with --ecid")), + }, + }; + Ok(udid.filter(|u| greets(u))) +} + +/// Other devices checkra1n would take or disturb: it has no way to be told +/// which device it is for, and goes for any in DFU mode. Recovery mode and +/// Pongo count too (it starts devices from there). `ecid` and `at` (the +/// target's port) say which one is ours. +fn in_checkra1ns_way(ecid: Option<&str>, at: Option<&str>) -> Vec { + let ours = |d: &orchard_usb::Device| match (d.identity.ecid.as_deref(), ecid) { + (Some(a), Some(b)) => crate::ecid_key(a) == crate::ecid_key(b), + _ => at.is_some_and(|at| d.location == at), + }; + orchard_usb::list() + .unwrap_or_default() + .into_iter() + .filter(|d| matches!(d.mode, orchard_usb::Mode::Dfu | orchard_usb::Mode::Recovery | orchard_usb::Mode::Pongo) && !ours(d)) + .map(|d| format!("{} in {} mode at {}", d.product.clone().unwrap_or_else(|| "a device".into()), d.mode.as_str(), d.location)) + .collect() } /// usbmuxd is not running: on Linux it may start only once iOS is on USB. @@ -128,7 +163,26 @@ fn timed_out(log: &str, usbmuxd_down: Option) -> Error { /// Runs checkra1n until the device's SSH server answers, and returns the /// device's UDID. -fn start_ios(executor: &Executor) -> Result { +fn start_ios(executor: &Executor, ecid: Option<&str>) -> Result { + // The target's port, while it is in DFU mode: what it is known by in + // the modes that don't tell an ECID. + let at: Option = orchard_usb::list().unwrap_or_default().into_iter().find_map(|d| { + let named = ecid.is_some_and(|e| d.identity.ecid.as_deref().is_some_and(|k| crate::ecid_key(k) == crate::ecid_key(e))); + (d.mode == orchard_usb::Mode::Dfu && named).then(|| d.location.clone()) + }); + // checkra1n takes any device in DFU mode: it only starts once ours is + // the only one it could take. Others are waited for, a minute at most. + let clear = Instant::now() + Duration::from_secs(60); + loop { + let others = in_checkra1ns_way(ecid, at.as_deref()); + if others.is_empty() { + break; + } + if Instant::now() > clear { + return Err(fail(format!("checkra1n would also take another device ({}); it can't be told which one to start. Start again once that device has left DFU and recovery mode", others.join(", ")))); + } + std::thread::sleep(Duration::from_secs(1)); + } // 0.12.4: the build whose start brings its loader and SSH server. let (pin, release) = crate::flags::checkra1n_jailbreak_pin().ok_or_else(|| Error::new(Code::NotFound, "checkra1n publishes no build for this computer"))?; let checkra1n = executor.palera1n(pin, release)?; @@ -167,16 +221,38 @@ fn start_ios(executor: &Executor) -> Result { let until = Instant::now() + BOOT; let read_log = || std::fs::read(&log_path).map(|t| String::from_utf8_lossy(&t).into_owned()).unwrap_or_default(); let (mut seen, mut changed) = (0usize, Instant::now()); + // Once checkra1n says it is done with our device it is stopped: left + // running, it waits for the next device in DFU mode and takes it. + let mut done = false; + let mut ticks = 0u32; let outcome = loop { - std::thread::sleep(Duration::from_secs(3)); - let usbmuxd_down = match ssh_answers() { + std::thread::sleep(Duration::from_secs(1)); + ticks += 1; + if !done { + // Another device came into its reach while it runs: stop it at once. + let others = in_checkra1ns_way(ecid, at.as_deref()); + if !others.is_empty() { + break Err(fail(format!("another device came into DFU or recovery mode while checkra1n ran ({}); checkra1n was stopped so that it does not start that one", others.join(", ")))); + } + if std::fs::read_to_string(&log_path).is_ok_and(|l| l.contains("All Done")) { + done = true; + let _ = child.kill(); + let _ = child.wait(); + } + } + if ticks % 3 != 0 { + continue; + } + let usbmuxd_down = match ssh_answers(ecid) { Ok(Some(udid)) => break Ok(udid), Err(e) if !not_running(&e) => break Err(e), waiting => waiting.err(), }; - if let Ok(Some(status)) = child.try_wait() { - if !status.success() { - break Err(fail(format!("checkra1n failed ({status}); its log: {}", log_path.display()))); + if !done { + if let Ok(Some(status)) = child.try_wait() { + if !status.success() { + break Err(fail(format!("checkra1n failed ({status}); its log: {}", log_path.display()))); + } } } let text = read_log(); @@ -404,9 +480,29 @@ const COMPANION: &str = "/private/var/OrchardCompanion"; /// Starts iOS on the device in DFU mode, on a chip with `soc`, with /// checkra1n and the companion's `helper` there, taking `token` and saying -/// `system` for what is installed. -pub fn companion(executor: &Executor, soc: &str, helper: &[u8], token: &str, system: &str) -> Result { - let (udid, ssh) = start(executor, soc)?; +/// `system` for what is installed. With `ecid`, only that device is started. +pub fn companion(executor: &Executor, soc: &str, ecid: Option<&str>, helper: &[u8], token: &str, system: &str) -> Result { + let (udid, ssh) = start(executor, soc, ecid)?; + put_helper(udid, ssh, helper, token, system) +} + +/// The UDID of the device with this ECID when iOS on it already runs as +/// checkra1n started it (its SSH server answers): an installer started again +/// goes on from there, without another round through DFU mode. +pub fn running(ecid: &str) -> Option { + ssh_answers(Some(ecid)).ok().flatten() +} + +/// Puts the companion's helper on a device checkra1n has started and starts +/// it. A helper an earlier session left is stopped first; a split it was +/// doing is in the engine's journal, and the new helper goes on with it. +pub fn companion_on(udid: String, helper: &[u8], token: &str, system: &str) -> Result { + let ssh = Ssh::open(&udid)?; + put_helper(udid, ssh, helper, token, system) +} + +/// The helper onto the device over `ssh`, and started there. +fn put_helper(udid: String, ssh: Ssh, helper: &[u8], token: &str, system: &str) -> Result { let (program, pidfile) = (format!("{COMPANION}/orchard-companion"), format!("{COMPANION}/helper.pid")); ssh.must( &format!("if [ -f {pidfile} ]; then kill \"$(cat {pidfile})\" 2>/dev/null; fi; rm -rf {COMPANION}; umask 077; mkdir -p {COMPANION}"), @@ -485,7 +581,7 @@ pub fn run(executor: &Executor, soc: &str, app: &Older, say: &dyn Fn(&str), done /// One checkra1n start and one session. fn round(executor: &Executor, soc: &str, app: &Older, say: &dyn Fn(&str), done: &mut dyn FnMut(&dyn Fn() -> bool) -> Result) -> Result { say("Starting iOS with checkra1n"); - let (udid, ssh) = start(executor, soc)?; + let (udid, ssh) = start(executor, soc, None)?; say("iOS is up; copying Resize APFS"); ssh.must(&format!("{}; {}", leftover(OLD_SESSION, OLD_APP), leftover(SESSION, APP)), "Removing an earlier session", None)?; // 755: the app runs as mobile and must read its bundle; the helper trusts diff --git a/crates/runtime/src/driver.rs b/crates/runtime/src/driver.rs index 07e49b0..bd76693 100644 --- a/crates/runtime/src/driver.rs +++ b/crates/runtime/src/driver.rs @@ -11,6 +11,7 @@ use orchard_boards::catalog::Catalog; use orchard_cache::Result; use orchard_flow::{step, App, Effect, Event, Flow, UsbMode}; use std::path::PathBuf; +use std::sync::atomic::Ordering::SeqCst; use std::sync::mpsc::{self, Receiver, Sender}; use std::time::{Duration, Instant}; @@ -173,6 +174,7 @@ pub fn start(options: Options, observer: impl Observer) -> Result { app_options: orchard_flow::Options::default(), login: Default::default(), checkra1n: Default::default(), + picking_up: Default::default(), executor, events: tx, observer, @@ -245,6 +247,7 @@ struct Driver { login: std::sync::Arc>>, /// The session of checkra1n's helper, until it is taken off again. checkra1n: std::sync::Arc>>, + picking_up: std::sync::Arc, observer: O, } @@ -350,8 +353,9 @@ impl Driver { .and_then(|d| Catalog::open(&executor.data().ok()?).and_then(|c| c.chip(c.board(&d.board)?.chip)).ok()) .map(|chip| chip.soc) .unwrap_or_default(); + let ecid = device.as_ref().map(|d| d.id.0.clone()); let started = crate::overlay::Companion::embedded() - .and_then(|companion| crate::access_checkra1n::companion(&executor, &soc, &companion.helper, &token, orchard_flow::system_name())); + .and_then(|companion| crate::access_checkra1n::companion(&executor, &soc, ecid.as_deref(), &companion.helper, &token, orchard_flow::system_name())); match (started, device) { (Ok(session), Some(device)) => { let _ = jobs.send(CompanionJob::Attach { udid: session.udid.clone(), device, token }); @@ -583,7 +587,20 @@ impl Driver { && self.only.as_ref().is_some_and(|only| only.ecid.is_some()) && watcher.ecid(d).is_none() }; - let mut unnamed: Vec<_> = unnamed.into_iter().filter(|d| orchard_usb::apple_device(d) && !asked(d)).collect(); + // With the device named (--ecid, --location) the flow never + // waits for other devices to go: it knows which one is its own, + // and everything of ours is addressed to it (its ECID, its port). + // What can't be addressed is guarded where it runs, not here: + // palera1n and checkra1n take the first device they find, so + // their starts check for a device they could take right before + // and while they run (chain::alone, access_checkra1n::start_ios). + // Refusing the whole flow instead stopped runs that were safe: + // a second phone in iOS held up a launch by the ibss route. + let target_named = self.only.is_some(); + let mut unnamed: Vec<_> = unnamed + .into_iter() + .filter(|d| orchard_usb::apple_device(d) && !asked(d)) + .collect(); // One piece of work on a device at a time: a device in // DFU mode is taken before the flow hears of it, and one // that other work holds is left to it. @@ -624,6 +641,40 @@ impl Driver { if let Some(udid) = watcher.udid(&device.id) { self.udids.insert(device.id.clone(), udid); } + // iOS as checkra1n started it, from a session before this + // one (the installer was started again): the helper is put + // there now, and the flow picks up at the split when it + // answers, without another round through DFU mode, which + // would restart the device under a split that may be running. + let ours = self.only.as_ref().is_some_and(|only| only.ecid.is_some()); + if ours && flow.options.helper == Some(orchard_flow::Helper::Checkra1n) && { + let slot = self.checkra1n.lock().expect("checkra1n"); + slot.is_none() && self.picking_up.compare_exchange(false, true, SeqCst, SeqCst).is_ok() + } { + let (events, jobs, slot, device) = (self.events.clone(), self.companion_jobs.clone(), self.checkra1n.clone(), device.clone()); + let picking_up = self.picking_up.clone(); + std::thread::spawn(move || { + let Some(udid) = crate::access_checkra1n::running(&device.id.0) else { + picking_up.store(false, SeqCst); + return; + }; + let token = crate::overlay::Identity::random().token_hex(); + let started = crate::overlay::Companion::embedded() + .and_then(|companion| crate::access_checkra1n::companion_on(udid, &companion.helper, &token, orchard_flow::system_name())); + match started { + Ok(session) => { + let mut slot = slot.lock().expect("checkra1n"); + if slot.is_none() { + let udid = session.udid.clone(); + *slot = Some(session); + let _ = jobs.send(CompanionJob::Attach { udid, device, token }); + } + } + Err(e) => drop(events.send(Event::ChainFailed(e.to_string()))), + } + picking_up.store(false, SeqCst); + }); + } } } // Other Apple devices besides the one being worked on: @@ -633,10 +684,14 @@ impl Driver { let mut others = if target.is_none() && !unnamed.is_empty() { // Only devices that were not named are there. listed_devices(&catalog, &watcher, &unnamed, None) - } else if watcher.others(&devices, target.as_ref()).is_empty() { - Vec::new() } else { - listed_devices(&catalog, &watcher, &devices, flow.state.device()) + // The ones in the way, and the target with them: + // not the devices the rule leaves alone. + let mut shown = if target_named { Vec::new() } else { watcher.others(&devices, target.as_ref()) }; + if !shown.is_empty() { + shown.extend(devices.iter().filter(|d| target.as_ref().is_some_and(|t| watcher.is_target(d, t))).cloned()); + } + listed_devices(&catalog, &watcher, &shown, flow.state.device()) }; // A device other work holds says so in place of its mode. for (device, holder) in &in_use { @@ -683,9 +738,19 @@ impl Driver { // The token of the helper that runs there: the // helper app's on the route without DFU, else // the overlay's. + // A helper this run put there through checkra1n's SSH has its + // own token, whatever the flow makes of the helper just now + // (before the device's version is known it names none, and + // the overlay's token then took the place of the right one: + // the helper refused every connection). With checkra1n chosen + // there is no overlay, so no token until that helper runs. + let ours = self.checkra1n.lock().expect("checkra1n").as_ref().map(|s| s.token.clone()); + let chosen = flow.options.helper == Some(orchard_flow::Helper::Checkra1n); let token = |udid: &str| match flow.helper() { + _ if ours.is_some() => ours.clone(), Some(orchard_flow::Helper::Dopamine) => crate::helper_app::token(&self.executor, udid), - Some(orchard_flow::Helper::Checkra1n) => self.checkra1n.lock().expect("checkra1n").as_ref().map(|s| s.token.clone()), + Some(orchard_flow::Helper::Checkra1n) => None, + _ if chosen => None, _ => self.executor.companion_token(), }; if let Some((udid, token)) = udid.and_then(|udid| token(&udid).map(|token| (udid, token))) { @@ -730,7 +795,7 @@ fn listed_devices( target: Option<&orchard_flow::Device>, ) -> Vec { // Whether a listed device is the one being installed on (orchard_usb::others). - let is_target = |d: &orchard_usb::Device| target.is_some_and(|t| watcher.others(std::slice::from_ref(d), Some(&t.id)).is_empty()); + let is_target = |d: &orchard_usb::Device| target.is_some_and(|t| watcher.is_target(d, &t.id)); devices .iter() .filter(|d| orchard_usb::apple_device(d)) diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 974f19f..bf9f288 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -366,6 +366,18 @@ impl Watcher { orchard_usb::others(&listing, target).into_iter().cloned().collect() } + /// Whether a listed device is `target` itself: by its ECID where both + /// are known, else by the port the target was last seen at. Unlike an + /// empty `others`, this is not true of a device the rule merely ignores. + pub fn is_target(&self, device: &orchard_usb::Device, target: &DeviceId) -> bool { + let told = device.identity.udid.as_deref().and_then(|u| self.told.get(u)).and_then(|t| t.ecid.clone()); + let ecid = device.identity.ecid.clone().or(told); + match (ecid.as_deref(), (!target.0.contains('-')).then_some(target.0.as_str())) { + (Some(a), Some(b)) => orchard_usb::ecid_key(a) == orchard_usb::ecid_key(b), + _ => self.locations.get(target).is_some_and(|at| *at == device.location), + } + } + /// Identifies a listing and returns the events since the last one. pub fn see(&mut self, catalog: &Catalog, listing: &[orchard_usb::Device]) -> Vec { let mut now = Vec::new(); diff --git a/crates/usb/src/others.rs b/crates/usb/src/others.rs index e736e53..1219e36 100644 --- a/crates/usb/src/others.rs +++ b/crates/usb/src/others.rs @@ -35,6 +35,18 @@ pub fn others<'a>(listing: &'a [Device], target: Option) -> Vec<&'a Devi let Some(target) = target else { return if devices.len() > 1 { devices } else { Vec::new() }; }; + // With the target named (--ecid, --location), a device elsewhere that + // runs m1n1 or an Orchard system is no danger and doesn't count: + // palera1n and checkra1n only take devices in DFU, recovery, Pongo or + // iOS, and everything of ours follows the target by its port. People + // who work on several devices keep them plugged in. + let named = target.ecid.is_some() || target.location.is_some(); + let known_target = |d: &Device| match (d.identity.ecid.as_deref(), target.ecid) { + (Some(a), Some(b)) => ecid_key(a) == ecid_key(b), + _ => target.location.is_some_and(|at| d.location == at), + }; + let devices: Vec<&Device> = + devices.into_iter().filter(|d| known_target(d) || !(named && matches!(d.mode, Mode::Linux | Mode::M1n1))).collect(); let lone = devices.len() == 1; let is_target = |d: &Device| match (d.identity.ecid.as_deref(), target.ecid) { (Some(a), Some(b)) => ecid_key(a) == ecid_key(b), @@ -125,7 +137,20 @@ mod tests { fn without_a_known_port_a_lone_device_is_the_target() { let t = Some(Target { ecid: Some("11223344556677"), location: None }); assert!(others(&[device(Mode::Normal, "x", None)], t).is_empty()); - let two = [device(Mode::Normal, "x", None), device(Mode::M1n1, "y", None)]; + let two = [device(Mode::Normal, "x", None), device(Mode::Recovery, "y", None)]; assert_eq!(others(&two, t).len(), 2); } + + #[test] + fn with_the_target_named_devices_in_m1n1_or_linux_elsewhere_dont_count() { + let mut system = device(Mode::Linux, "0x100000", None); + system.system = Some(crate::System::Installed); + let listing = [device(Mode::Normal, "x", None), device(Mode::M1n1, "y", None), system]; + let t = Some(Target { ecid: Some("11223344556677"), location: None }); + assert!(others(&listing, t).is_empty()); + // Unnamed, they still count; and one in DFU mode always does. + assert_eq!(others(&listing, None).len(), 3); + let dfu = [device(Mode::Normal, "x", None), device(Mode::Dfu, "y", Some("99"))]; + assert_eq!(others(&dfu, t).len(), 2); + } }