From 040bc8b14dbdc4540b3f682d53b5d58a492e94f3 Mon Sep 17 00:00:00 2001 From: Matthew Jackson <1085847+MattJackson@users.noreply.github.com> Date: Wed, 19 Aug 2026 09:10:26 -0700 Subject: [PATCH] drive: select the platform module once, not per function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit find_drives and resolve_device each carried a three-arm cfg(target_os) block in their bodies. Alias the current platform's module once (`use linux as platform` under a single cfg) and let both dispatch through `platform::…`, so the function bodies are cfg-free and a new entry point cannot forget an arm. --- src/drive/mod.rs | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/drive/mod.rs b/src/drive/mod.rs index 727f86a..d502c6a 100644 --- a/src/drive/mod.rs +++ b/src/drive/mod.rs @@ -35,6 +35,15 @@ pub(crate) mod macos; #[cfg(windows)] pub(crate) mod windows; +// Pick the platform module ONCE, here, so the cross-platform entry points below +// dispatch through `platform::…` with no per-function `#[cfg]` in their bodies. +#[cfg(target_os = "linux")] +pub(crate) use linux as platform; +#[cfg(target_os = "macos")] +pub(crate) use macos as platform; +#[cfg(windows)] +pub(crate) use windows as platform; + use crate::error::{Error, Result}; use crate::event::Event; use crate::identity::DriveId; @@ -1385,18 +1394,7 @@ fn sleep_until_halted(halt: &AtomicBool, total: std::time::Duration) -> Result<( /// Internal: discover drive paths + IDs without opening full Drive objects. fn discover_drives() -> Vec<(String, DriveId)> { - #[cfg(target_os = "linux")] - { - linux::find_drives() - } - #[cfg(target_os = "macos")] - { - macos::find_drives() - } - #[cfg(windows)] - { - windows::find_drives() - } + platform::find_drives() } /// Structured outcome of [`resolve_device`] — a machine-readable signal @@ -1416,20 +1414,14 @@ pub enum DeviceResolution { /// Resolve a device path to its raw SCSI device. Returns the resolved /// path plus a structured [`DeviceResolution`] signal describing whether /// any substitution happened; the application layer maps that to UX text. +/// +/// Staged, not yet wired: the cross-platform dispatch is kept ready for the +/// caller that will consume it, so the per-platform implementations below it +/// (and their tests) stay live. `allow(dead_code)` marks that deliberately — +/// this is not an accidental orphan. #[allow(dead_code)] pub(crate) fn resolve_device(path: &str) -> Result<(String, DeviceResolution)> { - #[cfg(target_os = "linux")] - { - linux::resolve_device(path) - } - #[cfg(target_os = "macos")] - { - macos::resolve_device(path) - } - #[cfg(windows)] - { - windows::resolve_device(path) - } + platform::resolve_device(path) } #[cfg(test)]