From 921404d13545d87ae04395dca4c8faa57db98f8e Mon Sep 17 00:00:00 2001 From: Matthew Jackson <1085847+MattJackson@users.noreply.github.com> Date: Wed, 29 Jul 2026 22:37:47 -0700 Subject: [PATCH] Fix five clippy errors that only appear on the target CI lints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI's clippy job runs on ubuntu-latest, so cfg(target_os = "linux") code is what the gate actually compiles — and none of it is built by clippy on a Mac. Five `-D warnings` errors were sitting in drive/linux.rs, scsi/linux.rs, io/writeback/linux.rs and the Linux arm of drive/mod.rs: four collapsible let-chains and one manual `% n == 0`. CI was red on the lint job while the local gate reported all green. Collapsed into let-chains, which the declared toolchain supports, and folded drive/mod.rs's length precondition into its chain so the body no longer needs a nested block. Found because an agent working on the SCSI backends reported the lints in passing while checking that a Windows-only file compiled. Worth noting how it stayed hidden: every one of these files is cfg-gated to a platform this machine is not, so no amount of local gating would have surfaced them. The companion change to the precommit script closes that hole. --- src/drive/linux.rs | 14 ++++---- src/drive/mod.rs | 70 ++++++++++++++++++--------------------- src/io/writeback/linux.rs | 2 +- src/scsi/linux.rs | 10 +++--- 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/src/drive/linux.rs b/src/drive/linux.rs index 03fdcbb..bfdda33 100644 --- a/src/drive/linux.rs +++ b/src/drive/linux.rs @@ -23,14 +23,12 @@ pub fn find_drives() -> Vec<(String, DriveId)> { if !std::path::Path::new(&path).exists() { continue; } - if let Ok(mut transport) = crate::scsi::open(std::path::Path::new(&path)) { - if let Ok(id) = DriveId::from_drive(transport.as_mut()) { - if !id.raw_inquiry.is_empty() - && (id.raw_inquiry[0] & 0x1F) == SCSI_PERIPHERAL_TYPE_OPTICAL - { - drives.push((path, id)); - } - } + if let Ok(mut transport) = crate::scsi::open(std::path::Path::new(&path)) + && let Ok(id) = DriveId::from_drive(transport.as_mut()) + && !id.raw_inquiry.is_empty() + && (id.raw_inquiry[0] & 0x1F) == SCSI_PERIPHERAL_TYPE_OPTICAL + { + drives.push((path, id)); } } drives diff --git a/src/drive/mod.rs b/src/drive/mod.rs index e6079b3..7226adb 100644 --- a/src/drive/mod.rs +++ b/src/drive/mod.rs @@ -902,45 +902,39 @@ impl Drive { // 2026-05-08) dd via /dev/sr0 recovers ~50% of bad // sectors that a single-shot SG_IO READ misses. #[cfg(target_os = "linux")] - if recovery { - if let Some(fd) = self.block_dev_fd { - let len = count as usize * 2048; - if buf.len() >= len { - let offset = lba as i64 * 2048; - // Drop kernel cache for this region so we get - // a fresh device read, not stale page-cache - // data from a prior successful neighbour read. - let _ = unsafe { - libc::posix_fadvise( - fd, - offset, - len as i64, - libc::POSIX_FADV_DONTNEED, - ) - }; - let n = unsafe { - libc::pread(fd, buf.as_mut_ptr() as *mut libc::c_void, len, offset) - }; - if n == len as isize { - tracing::info!( - target: "freemkv::drive", - lba, - count, - bytes = len, - "Drive::read recovered via /dev/sr0 pread fallback" - ); - return Ok(len); - } - tracing::debug!( - target: "freemkv::drive", - lba, - count, - pread_ret = n as i64, - errno = std::io::Error::last_os_error().raw_os_error().unwrap_or(0), - "/dev/sr0 pread fallback also failed" - ); - } + if recovery + && let Some(fd) = self.block_dev_fd + && buf.len() >= count as usize * 2048 + { + let len = count as usize * 2048; + let offset = lba as i64 * 2048; + // Drop kernel cache for this region so we get + // a fresh device read, not stale page-cache + // data from a prior successful neighbour read. + let _ = unsafe { + libc::posix_fadvise(fd, offset, len as i64, libc::POSIX_FADV_DONTNEED) + }; + let n = unsafe { + libc::pread(fd, buf.as_mut_ptr() as *mut libc::c_void, len, offset) + }; + if n == len as isize { + tracing::info!( + target: "freemkv::drive", + lba, + count, + bytes = len, + "Drive::read recovered via /dev/sr0 pread fallback" + ); + return Ok(len); } + tracing::debug!( + target: "freemkv::drive", + lba, + count, + pread_ret = n as i64, + errno = std::io::Error::last_os_error().raw_os_error().unwrap_or(0), + "/dev/sr0 pread fallback also failed" + ); } Err(Error::DiscRead { diff --git a/src/io/writeback/linux.rs b/src/io/writeback/linux.rs index 7d4e97d..3ed2195 100644 --- a/src/io/writeback/linux.rs +++ b/src/io/writeback/linux.rs @@ -272,7 +272,7 @@ impl WritebackPipeline { self.chunk_bytes, self.skip_wait(), ); - if self.chunk_count % SIZE_LOG_INTERVAL == 0 { + if self.chunk_count.is_multiple_of(SIZE_LOG_INTERVAL) { tracing::debug!( target: "mux", "WritebackPipeline chunk_bytes={} after {} chunks is_nfs={} degraded={}", diff --git a/src/scsi/linux.rs b/src/scsi/linux.rs index bfecbf8..cb12fa7 100644 --- a/src/scsi/linux.rs +++ b/src/scsi/linux.rs @@ -169,11 +169,11 @@ impl SgIoTransport { if dev_name.starts_with("sr") { let sg_dir = format!("/sys/class/block/{}/device/scsi_generic", dev_name); - if let Ok(mut entries) = std::fs::read_dir(&sg_dir) { - if let Some(Ok(entry)) = entries.next() { - let sg_name = entry.file_name(); - return std::path::PathBuf::from(format!("/dev/{}", sg_name.to_string_lossy())); - } + if let Ok(mut entries) = std::fs::read_dir(&sg_dir) + && let Some(Ok(entry)) = entries.next() + { + let sg_name = entry.file_name(); + return std::path::PathBuf::from(format!("/dev/{}", sg_name.to_string_lossy())); } }