From 96c69ef2243e5832f50883987e14412ed0269655 Mon Sep 17 00:00:00 2001 From: weisd Date: Fri, 27 Sep 2024 00:06:34 +0800 Subject: [PATCH] opt: rename_data --- ecstore/src/disk/local.rs | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index b25ec2fd9..6a3891fb0 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -1312,12 +1312,19 @@ impl DiskAPI for LocalDisk { return Err(Error::msg("Invalid arguments specified")); } - let p = self.get_bucket_path(volume)?; + let volume_dir = self.get_bucket_path(volume)?; - if let Err(e) = utils::fs::access(&p).await { + if let Err(e) = utils::fs::access(&volume_dir).await { if os_is_not_exist(&e) { - os::make_dir_all(&p, self.root.as_path()).await?; + os::make_dir_all(&volume_dir, self.root.as_path()).await?; } + if os_is_permission(&e) { + return Err(Error::new(DiskError::DiskAccessDenied)); + } else if is_sys_err_io(&e) { + return Err(Error::new(DiskError::FaultyDisk)); + } + + return Err(Error::new(e)); } Err(Error::from(DiskError::VolumeExists)) @@ -1349,17 +1356,27 @@ impl DiskAPI for LocalDisk { Ok(volumes) } async fn stat_volume(&self, volume: &str) -> Result { - let p = self.get_bucket_path(volume)?; - - let m = read_file_metadata(&p).await?; - let modtime = match m.modified() { - Ok(md) => Some(OffsetDateTime::from(md)), - Err(_) => { - warn!("Not supported modified on this platform"); - None + let volume_dir = self.get_bucket_path(volume)?; + let meta = match utils::fs::lstat(&volume_dir).await { + Ok(res) => res, + Err(e) => { + if os_is_not_exist(&e) { + return Err(Error::new(DiskError::VolumeNotFound)); + } else if os_is_permission(&e) { + return Err(Error::new(DiskError::DiskAccessDenied)); + } else if is_sys_err_io(&e) { + return Err(Error::new(DiskError::FaultyDisk)); + } else { + return Err(Error::new(e)); + } } }; + let modtime = match meta.modified() { + Ok(md) => Some(OffsetDateTime::from(md)), + Err(_) => None, + }; + Ok(VolumeInfo { name: volume.to_string(), created: modtime,