clippy

clippy
This commit is contained in:
weisd
2024-12-04 11:15:49 +08:00
parent 3e56641b0a
commit 84d4a08128
7 changed files with 66 additions and 26 deletions
+8
View File
@@ -450,3 +450,11 @@ pub fn is_all_buckets_not_found(errs: &[Option<Error>]) -> bool {
} }
errs.len() == not_found_count errs.len() == not_found_count
} }
pub fn is_err_os_not_exist(err: &Error) -> bool {
if let Some(os_err) = err.downcast_ref::<io::Error>() {
os_is_not_exist(os_err)
} else {
false
}
}
+41 -12
View File
@@ -12,8 +12,8 @@ use crate::bitrot::bitrot_verify;
use crate::bucket::metadata_sys::{self}; use crate::bucket::metadata_sys::{self};
use crate::cache_value::cache::{Cache, Opts, UpdateFn}; use crate::cache_value::cache::{Cache, Opts, UpdateFn};
use crate::disk::error::{ use crate::disk::error::{
convert_access_error, is_sys_err_handle_invalid, is_sys_err_invalid_arg, is_sys_err_is_dir, is_sys_err_not_dir, convert_access_error, is_err_os_not_exist, is_sys_err_handle_invalid, is_sys_err_invalid_arg, is_sys_err_is_dir,
map_err_not_exists, os_err_to_file_err, is_sys_err_not_dir, map_err_not_exists, os_err_to_file_err,
}; };
use crate::disk::os::{check_path_length, is_empty_dir}; use crate::disk::os::{check_path_length, is_empty_dir};
use crate::disk::{LocalFileReader, LocalFileWriter, STORAGE_FORMAT_FILE}; use crate::disk::{LocalFileReader, LocalFileWriter, STORAGE_FORMAT_FILE};
@@ -40,6 +40,7 @@ use crate::{
utils, utils,
}; };
use common::defer; use common::defer;
use nix::NixPath;
use path_absolutize::Absolutize; use path_absolutize::Absolutize;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::fmt::Debug; use std::fmt::Debug;
@@ -57,7 +58,7 @@ use tokio::fs::{self, File};
use tokio::io::{AsyncReadExt, AsyncWriteExt, ErrorKind}; use tokio::io::{AsyncReadExt, AsyncWriteExt, ErrorKind};
use tokio::sync::mpsc::Sender; use tokio::sync::mpsc::Sender;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tracing::{error, info, warn}; use tracing::{info, warn};
use uuid::Uuid; use uuid::Uuid;
#[derive(Debug)] #[derive(Debug)]
@@ -399,22 +400,49 @@ impl LocalDisk {
} }
/// read xl.meta raw data /// read xl.meta raw data
#[tracing::instrument(level = "debug", skip(self, volume_dir, path))] #[tracing::instrument(level = "debug", skip(self, volume_dir, file_path))]
async fn read_raw( async fn read_raw(
&self, &self,
bucket: &str, bucket: &str,
volume_dir: impl AsRef<Path>, volume_dir: impl AsRef<Path>,
path: impl AsRef<Path>, file_path: impl AsRef<Path>,
read_data: bool, read_data: bool,
) -> Result<(Vec<u8>, Option<OffsetDateTime>)> { ) -> Result<(Vec<u8>, Option<OffsetDateTime>)> {
let meta_path = path.as_ref().join(Path::new(super::STORAGE_FORMAT_FILE)); if file_path.as_ref().is_empty() {
if read_data { return Err(Error::new(DiskError::FileNotFound));
self.read_all_data_with_dmtime(bucket, volume_dir, meta_path).await
} else {
self.read_all_data_with_dmtime(bucket, volume_dir, meta_path).await
// FIXME: read_metadata only suport
// self.read_metadata_with_dmtime(meta_path).await
} }
let meta_path = file_path.as_ref().join(Path::new(super::STORAGE_FORMAT_FILE));
let res = {
if read_data {
self.read_all_data_with_dmtime(bucket, volume_dir, meta_path).await
} else {
match self.read_metadata_with_dmtime(meta_path).await {
Ok(res) => Ok(res),
Err(err) => {
if is_err_os_not_exist(&err)
&& !skip_access_checks(volume_dir.as_ref().to_string_lossy().to_string().as_str())
{
if let Err(aerr) = access(volume_dir.as_ref()).await {
if os_is_not_exist(&aerr) {
return Err(Error::new(DiskError::VolumeNotFound));
}
}
}
Err(err)
}
}
}
};
let (buf, mtime) = res?;
if buf.is_empty() {
return Err(Error::new(DiskError::FileNotFound));
}
Ok((buf, mtime))
} }
async fn read_metadata(&self, file_path: impl AsRef<Path>) -> Result<Vec<u8>> { async fn read_metadata(&self, file_path: impl AsRef<Path>) -> Result<Vec<u8>> {
@@ -445,6 +473,7 @@ impl LocalDisk {
let mut bytes = Vec::new(); let mut bytes = Vec::new();
bytes.try_reserve_exact(size)?; bytes.try_reserve_exact(size)?;
// FIXME: real xl no data
f.read_to_end(&mut bytes).await.map_err(os_err_to_file_err)?; f.read_to_end(&mut bytes).await.map_err(os_err_to_file_err)?;
let modtime = match meta.modified() { let modtime = match meta.modified() {
+5 -5
View File
@@ -484,7 +484,7 @@ impl FileMeta {
} }
} }
let mut fi = ver.into_fileinfo(volume, path, has_vid, all_parts)?; let mut fi = ver.to_fileinfo(volume, path, has_vid, all_parts)?;
fi.is_latest = is_latest; fi.is_latest = is_latest;
if let Some(_d) = succ_mod_time { if let Some(_d) = succ_mod_time {
fi.successor_mod_time = succ_mod_time; fi.successor_mod_time = succ_mod_time;
@@ -511,7 +511,7 @@ impl FileMeta {
for version in self.versions.iter() { for version in self.versions.iter() {
let mut file_version = FileMetaVersion::default(); let mut file_version = FileMetaVersion::default();
file_version.unmarshal_msg(&version.meta)?; file_version.unmarshal_msg(&version.meta)?;
let fi = file_version.into_fileinfo(volume, path, None, all_parts); let fi = file_version.to_fileinfo(volume, path, None, all_parts);
versions.push(fi); versions.push(fi);
} }
@@ -553,10 +553,10 @@ pub struct FileMetaShallowVersion {
} }
impl FileMetaShallowVersion { impl FileMetaShallowVersion {
pub fn into_fileinfo(&self, volume: &str, path: &str, version_id: Option<Uuid>, all_parts: bool) -> Result<FileInfo> { pub fn to_fileinfo(&self, volume: &str, path: &str, version_id: Option<Uuid>, all_parts: bool) -> Result<FileInfo> {
let file_version = FileMetaVersion::try_from(self.meta.as_slice())?; let file_version = FileMetaVersion::try_from(self.meta.as_slice())?;
Ok(file_version.into_fileinfo(volume, path, version_id, all_parts)) Ok(file_version.to_fileinfo(volume, path, version_id, all_parts))
} }
} }
@@ -760,7 +760,7 @@ impl FileMetaVersion {
FileMetaVersionHeader::from(self.clone()) FileMetaVersionHeader::from(self.clone())
} }
pub fn into_fileinfo(self, volume: &str, path: &str, version_id: Option<Uuid>, all_parts: bool) -> FileInfo { pub fn to_fileinfo(&self, volume: &str, path: &str, version_id: Option<Uuid>, all_parts: bool) -> FileInfo {
match self.version_type { match self.version_type {
VersionType::Invalid => FileInfo { VersionType::Invalid => FileInfo {
name: path.to_string(), name: path.to_string(),
+1
View File
@@ -26,6 +26,7 @@ pub fn get_global_notification_sys() -> Option<&'static NotificationSys> {
pub struct NotificationSys { pub struct NotificationSys {
peer_clients: Vec<Option<PeerRestClient>>, peer_clients: Vec<Option<PeerRestClient>>,
#[allow(dead_code)]
all_peer_clients: Vec<Option<PeerRestClient>>, all_peer_clients: Vec<Option<PeerRestClient>>,
} }
+9 -7
View File
@@ -177,6 +177,7 @@ impl SetDisks {
} }
#[tracing::instrument(level = "debug", skip(disks, file_infos))] #[tracing::instrument(level = "debug", skip(disks, file_infos))]
#[allow(clippy::type_complexity)]
async fn rename_data( async fn rename_data(
disks: &[Option<DiskStore>], disks: &[Option<DiskStore>],
src_bucket: &str, src_bucket: &str,
@@ -1107,9 +1108,9 @@ impl SetDisks {
let finfo = match meta.into_fileinfo(bucket, object, "", true, true) { let finfo = match meta.into_fileinfo(bucket, object, "", true, true) {
Ok(res) => res, Ok(res) => res,
Err(err) => { Err(err) => {
for i in 0..errs.len() { for item in errs.iter_mut() {
if errs[i].is_none() { if item.is_none() {
errs[i] = Some(err.clone()) *item = Some(err.clone())
} }
} }
@@ -1118,9 +1119,9 @@ impl SetDisks {
}; };
if !finfo.is_valid() { if !finfo.is_valid() {
for i in 0..errs.len() { for item in errs.iter_mut() {
if errs[i].is_none() { if item.is_none() {
errs[i] = Some(Error::new(DiskError::FileCorrupt)); *item = Some(Error::new(DiskError::FileCorrupt));
} }
} }
@@ -1629,6 +1630,7 @@ impl SetDisks {
Ok((fi, parts_metadata, online_disks)) Ok((fi, parts_metadata, online_disks))
} }
#[allow(clippy::too_many_arguments)]
async fn get_object_with_fileinfo( async fn get_object_with_fileinfo(
// &self, // &self,
bucket: &str, bucket: &str,
@@ -5008,7 +5010,7 @@ async fn get_disks_info(disks: &[Option<DiskStore>], eps: &[Endpoint]) -> Vec<ma
ret ret
} }
async fn get_storage_info(disks: &Vec<Option<DiskStore>>, eps: &Vec<Endpoint>) -> madmin::StorageInfo { async fn get_storage_info(disks: &[Option<DiskStore>], eps: &[Endpoint]) -> madmin::StorageInfo {
let mut disks = get_disks_info(disks, eps).await; let mut disks = get_disks_info(disks, eps).await;
disks.sort_by(|a, b| a.total_space.cmp(&b.total_space)); disks.sort_by(|a, b| a.total_space.cmp(&b.total_space));
+2 -2
View File
@@ -86,7 +86,7 @@ impl Sets {
let mut disk_set = Vec::with_capacity(set_count); let mut disk_set = Vec::with_capacity(set_count);
for i in 0..set_count { for (i, locker) in lockers.iter().enumerate().take(set_count) {
let mut set_drive = Vec::with_capacity(set_drive_count); let mut set_drive = Vec::with_capacity(set_drive_count);
let mut set_endpoints = Vec::with_capacity(set_drive_count); let mut set_endpoints = Vec::with_capacity(set_drive_count);
for j in 0..set_drive_count { for j in 0..set_drive_count {
@@ -131,7 +131,7 @@ impl Sets {
// warn!("sets new set_drive {:?}", &set_drive); // warn!("sets new set_drive {:?}", &set_drive);
let set_disks = SetDisks { let set_disks = SetDisks {
lockers: lockers[i].clone(), lockers: locker.clone(),
locker_owner: GLOBAL_Local_Node_Name.read().await.to_string(), locker_owner: GLOBAL_Local_Node_Name.read().await.to_string(),
ns_mutex: Arc::new(RwLock::new(NsLockMap::new(is_dist_erasure().await))), ns_mutex: Arc::new(RwLock::new(NsLockMap::new(is_dist_erasure().await))),
disks: RwLock::new(set_drive), disks: RwLock::new(set_drive),
Regular → Executable
View File