From 4ccd69c7829bb257b0c6fcd452b9b519b576f646 Mon Sep 17 00:00:00 2001 From: weisd Date: Wed, 4 Dec 2024 11:15:49 +0800 Subject: [PATCH] clippy clippy clippy --- ecstore/src/disk/error.rs | 8 +++++ ecstore/src/disk/local.rs | 53 +++++++++++++++++++++++++-------- ecstore/src/file_meta.rs | 10 +++---- ecstore/src/notification_sys.rs | 1 + ecstore/src/set_disk.rs | 14 ++++----- ecstore/src/sets.rs | 4 +-- 6 files changed, 64 insertions(+), 26 deletions(-) diff --git a/ecstore/src/disk/error.rs b/ecstore/src/disk/error.rs index 4ecbd632d..d20c00a3f 100644 --- a/ecstore/src/disk/error.rs +++ b/ecstore/src/disk/error.rs @@ -456,3 +456,11 @@ pub fn is_all_buckets_not_found(errs: &[Option]) -> bool { } errs.len() == not_found_count } + +pub fn is_err_os_not_exist(err: &Error) -> bool { + if let Some(os_err) = err.downcast_ref::() { + os_is_not_exist(os_err) + } else { + false + } +} diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 762962466..3f51c1b66 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -12,8 +12,8 @@ use crate::bitrot::bitrot_verify; use crate::bucket::metadata_sys::{self}; use crate::cache_value::cache::{Cache, Opts, UpdateFn}; 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, - map_err_not_exists, os_err_to_file_err, + convert_access_error, is_err_os_not_exist, is_sys_err_handle_invalid, is_sys_err_invalid_arg, is_sys_err_is_dir, + 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::{LocalFileReader, LocalFileWriter, STORAGE_FORMAT_FILE}; @@ -40,6 +40,7 @@ use crate::{ utils, }; use common::defer; +use nix::NixPath; use path_absolutize::Absolutize; use std::collections::{HashMap, HashSet}; use std::fmt::Debug; @@ -57,7 +58,7 @@ use tokio::fs::{self, File}; use tokio::io::{AsyncReadExt, AsyncWriteExt, ErrorKind}; use tokio::sync::mpsc::Sender; use tokio::sync::RwLock; -use tracing::{error, info, warn}; +use tracing::{info, warn}; use uuid::Uuid; #[derive(Debug)] @@ -400,22 +401,49 @@ impl LocalDisk { } /// 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( &self, bucket: &str, volume_dir: impl AsRef, - path: impl AsRef, + file_path: impl AsRef, read_data: bool, ) -> Result<(Vec, Option)> { - let meta_path = path.as_ref().join(Path::new(super::STORAGE_FORMAT_FILE)); - if read_data { - 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 + if file_path.as_ref().is_empty() { + return Err(Error::new(DiskError::FileNotFound)); } + + 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) -> Result> { @@ -446,6 +474,7 @@ impl LocalDisk { let mut bytes = Vec::new(); bytes.try_reserve_exact(size)?; + // FIXME: real xl no data f.read_to_end(&mut bytes).await.map_err(os_err_to_file_err)?; let modtime = match meta.modified() { diff --git a/ecstore/src/file_meta.rs b/ecstore/src/file_meta.rs index 3afae0557..2a4fa0baf 100644 --- a/ecstore/src/file_meta.rs +++ b/ecstore/src/file_meta.rs @@ -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; if let Some(_d) = succ_mod_time { fi.successor_mod_time = succ_mod_time; @@ -511,7 +511,7 @@ impl FileMeta { for version in self.versions.iter() { let mut file_version = FileMetaVersion::default(); 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); } @@ -553,10 +553,10 @@ pub struct FileMetaShallowVersion { } impl FileMetaShallowVersion { - pub fn into_fileinfo(&self, volume: &str, path: &str, version_id: Option, all_parts: bool) -> Result { + pub fn to_fileinfo(&self, volume: &str, path: &str, version_id: Option, all_parts: bool) -> Result { 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()) } - pub fn into_fileinfo(self, volume: &str, path: &str, version_id: Option, all_parts: bool) -> FileInfo { + pub fn to_fileinfo(&self, volume: &str, path: &str, version_id: Option, all_parts: bool) -> FileInfo { match self.version_type { VersionType::Invalid => FileInfo { name: path.to_string(), diff --git a/ecstore/src/notification_sys.rs b/ecstore/src/notification_sys.rs index 004bf2495..76df1e637 100644 --- a/ecstore/src/notification_sys.rs +++ b/ecstore/src/notification_sys.rs @@ -26,6 +26,7 @@ pub fn get_global_notification_sys() -> Option<&'static NotificationSys> { pub struct NotificationSys { pub peer_clients: Vec>, + #[allow(dead_code)] pub all_peer_clients: Vec>, } diff --git a/ecstore/src/set_disk.rs b/ecstore/src/set_disk.rs index 4bbc64c08..58c209d22 100644 --- a/ecstore/src/set_disk.rs +++ b/ecstore/src/set_disk.rs @@ -1109,9 +1109,9 @@ impl SetDisks { let finfo = match meta.into_fileinfo(bucket, object, "", true, true) { Ok(res) => res, Err(err) => { - for i in 0..errs.len() { - if errs[i].is_none() { - errs[i] = Some(err.clone()) + for item in errs.iter_mut() { + if item.is_none() { + *item = Some(err.clone()) } } @@ -1120,9 +1120,9 @@ impl SetDisks { }; if !finfo.is_valid() { - for i in 0..errs.len() { - if errs[i].is_none() { - errs[i] = Some(Error::new(DiskError::FileCorrupt)); + for item in errs.iter_mut() { + if item.is_none() { + *item = Some(Error::new(DiskError::FileCorrupt)); } } @@ -5009,7 +5009,7 @@ async fn get_disks_info(disks: &[Option], eps: &[Endpoint]) -> Vec>, eps: &Vec) -> madmin::StorageInfo { +async fn get_storage_info(disks: &[Option], eps: &[Endpoint]) -> madmin::StorageInfo { let mut disks = get_disks_info(disks, eps).await; disks.sort_by(|a, b| a.total_space.cmp(&b.total_space)); diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index e39d09002..594e88f58 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -87,7 +87,7 @@ impl Sets { 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_endpoints = Vec::with_capacity(set_drive_count); for j in 0..set_drive_count { @@ -145,7 +145,7 @@ impl Sets { // warn!("sets new set_drive {:?}", &set_drive); let set_disks = SetDisks { - lockers: lockers[i].clone(), + lockers: locker.clone(), locker_owner: GLOBAL_Local_Node_Name.read().await.to_string(), ns_mutex: Arc::new(RwLock::new(NsLockMap::new(is_dist_erasure().await))), disks: RwLock::new(set_drive),