mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-24 05:06:28 +00:00
Merge pull request #459 from rustfs/fix/linux-error-handling
fix: resolve duplicate Error import and ParseIntError
This commit is contained in:
@@ -18,30 +18,24 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
|||||||
let reserved = match bfree.checked_sub(bavail) {
|
let reserved = match bfree.checked_sub(bavail) {
|
||||||
Some(reserved) => reserved,
|
Some(reserved) => reserved,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::other(format!(
|
||||||
ErrorKind::Other,
|
"detected f_bavail space ({}) > f_bfree space ({}), fs corruption at ({}). please run 'fsck'",
|
||||||
format!(
|
bavail,
|
||||||
"detected f_bavail space ({}) > f_bfree space ({}), fs corruption at ({}). please run 'fsck'",
|
bfree,
|
||||||
bavail,
|
p.as_ref().display()
|
||||||
bfree,
|
)));
|
||||||
p.as_ref().display()
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let total = match blocks.checked_sub(reserved) {
|
let total = match blocks.checked_sub(reserved) {
|
||||||
Some(total) => total * bsize,
|
Some(total) => total * bsize,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::other(format!(
|
||||||
ErrorKind::Other,
|
"detected reserved space ({}) > blocks space ({}), fs corruption at ({}). please run 'fsck'",
|
||||||
format!(
|
reserved,
|
||||||
"detected reserved space ({}) > blocks space ({}), fs corruption at ({}). please run 'fsck'",
|
blocks,
|
||||||
reserved,
|
p.as_ref().display()
|
||||||
blocks,
|
)));
|
||||||
p.as_ref().display()
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,15 +43,12 @@ pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
|||||||
let used = match total.checked_sub(free) {
|
let used = match total.checked_sub(free) {
|
||||||
Some(used) => used,
|
Some(used) => used,
|
||||||
None => {
|
None => {
|
||||||
return Err(Error::new(
|
return Err(Error::other(format!(
|
||||||
ErrorKind::Other,
|
"detected free space ({}) > total drive space ({}), fs corruption at ({}). please run 'fsck'",
|
||||||
format!(
|
free,
|
||||||
"detected free space ({}) > total drive space ({}), fs corruption at ({}). please run 'fsck'",
|
total,
|
||||||
free,
|
p.as_ref().display()
|
||||||
total,
|
)));
|
||||||
p.as_ref().display()
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use nix::sys::stat::{self, stat};
|
use nix::sys::stat::{self, stat};
|
||||||
use nix::sys::statfs::{self, FsType, statfs};
|
use nix::sys::statfs::{self, FsType, statfs};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead, Error, ErrorKind};
|
use std::io::{self, BufRead, Error, ErrorKind, Result};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::disk::Info;
|
use crate::disk::Info;
|
||||||
use std::io::{Error, Result};
|
|
||||||
|
|
||||||
use super::IOStats;
|
use super::IOStats;
|
||||||
|
|
||||||
@@ -163,7 +162,9 @@ fn read_stat(file_name: &str) -> Result<Vec<u64>> {
|
|||||||
// 分割行并解析为 u64
|
// 分割行并解析为 u64
|
||||||
// https://rust-lang.github.io/rust-clippy/master/index.html#trim_split_whitespace
|
// https://rust-lang.github.io/rust-clippy/master/index.html#trim_split_whitespace
|
||||||
for token in line.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);
|
stats.push(ui64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user