From 6afb26b3777c7545f6772b692fc594d00976466e Mon Sep 17 00:00:00 2001 From: overtrue Date: Tue, 10 Jun 2025 22:02:29 +0800 Subject: [PATCH 1/2] fix: resolve duplicate Error import and ParseIntError conversion in linux.rs --- ecstore/src/utils/os/linux.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ecstore/src/utils/os/linux.rs b/ecstore/src/utils/os/linux.rs index e43fc5f7..1e923727 100644 --- a/ecstore/src/utils/os/linux.rs +++ b/ecstore/src/utils/os/linux.rs @@ -1,11 +1,10 @@ use nix::sys::stat::{self, stat}; use nix::sys::statfs::{self, FsType, statfs}; use std::fs::File; -use std::io::{self, BufRead, Error, ErrorKind}; +use std::io::{self, BufRead, Error, ErrorKind, Result}; use std::path::Path; use crate::disk::Info; -use std::io::{Error, Result}; use super::IOStats; @@ -163,7 +162,9 @@ fn read_stat(file_name: &str) -> Result> { // 分割行并解析为 u64 // https://rust-lang.github.io/rust-clippy/master/index.html#trim_split_whitespace for token in line.split_whitespace() { - let ui64: u64 = token.parse()?; + let ui64: u64 = token + .parse() + .map_err(|e| Error::new(ErrorKind::InvalidData, format!("Failed to parse token '{}': {}", token, e)))?; stats.push(ui64); } } From 4252377249db81a21b2a635a20810e5d0e8b9947 Mon Sep 17 00:00:00 2001 From: overtrue Date: Tue, 10 Jun 2025 22:15:52 +0800 Subject: [PATCH 2/2] fix: replace Error::new(ErrorKind::Other) with Error::other() for clippy compliance --- crates/utils/src/os/linux.rs | 45 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/crates/utils/src/os/linux.rs b/crates/utils/src/os/linux.rs index 06c14a86..7d0f4845 100644 --- a/crates/utils/src/os/linux.rs +++ b/crates/utils/src/os/linux.rs @@ -18,30 +18,24 @@ pub fn get_info(p: impl AsRef) -> std::io::Result { let reserved = match bfree.checked_sub(bavail) { Some(reserved) => reserved, None => { - return Err(Error::new( - ErrorKind::Other, - format!( - "detected f_bavail space ({}) > f_bfree space ({}), fs corruption at ({}). please run 'fsck'", - bavail, - bfree, - p.as_ref().display() - ), - )); + return Err(Error::other(format!( + "detected f_bavail space ({}) > f_bfree space ({}), fs corruption at ({}). please run 'fsck'", + bavail, + bfree, + p.as_ref().display() + ))); } }; let total = match blocks.checked_sub(reserved) { Some(total) => total * bsize, None => { - return Err(Error::new( - ErrorKind::Other, - format!( - "detected reserved space ({}) > blocks space ({}), fs corruption at ({}). please run 'fsck'", - reserved, - blocks, - p.as_ref().display() - ), - )); + return Err(Error::other(format!( + "detected reserved space ({}) > blocks space ({}), fs corruption at ({}). please run 'fsck'", + reserved, + blocks, + p.as_ref().display() + ))); } }; @@ -49,15 +43,12 @@ pub fn get_info(p: impl AsRef) -> std::io::Result { let used = match total.checked_sub(free) { Some(used) => used, None => { - return Err(Error::new( - ErrorKind::Other, - format!( - "detected free space ({}) > total drive space ({}), fs corruption at ({}). please run 'fsck'", - free, - total, - p.as_ref().display() - ), - )); + return Err(Error::other(format!( + "detected free space ({}) > total drive space ({}), fs corruption at ({}). please run 'fsck'", + free, + total, + p.as_ref().display() + ))); } };