diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 50e71e5f..e2c349cf 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -26,9 +26,9 @@ use uuid::Uuid; #[derive(Debug)] pub struct FormatInfo { pub id: Option, - pub data: Vec, - pub file_info: Option, - pub last_check: Option, + pub _data: Vec, + pub _file_info: Option, + pub _last_check: Option, } impl FormatInfo {} @@ -79,9 +79,9 @@ impl LocalDisk { let format_info = FormatInfo { id, - data: format_data, - file_info: format_meta, - last_check: format_last_check, + _data: format_data, + _file_info: format_meta, + _last_check: format_last_check, }; let disk = Self { @@ -158,6 +158,12 @@ impl LocalDisk { pub async fn move_to_trash(&self, delete_path: &PathBuf, _recursive: bool, _immediate_purge: bool) -> Result<()> { let trash_path = self.get_object_path(super::RUSTFS_META_TMP_DELETED_BUCKET, Uuid::new_v4().to_string().as_str())?; + if let Some(parent) = trash_path.parent() { + if !parent.exists() { + fs::create_dir_all(parent).await?; + } + } + debug!("move_to_trash from:{:?} to {:?}", &delete_path, &trash_path); // TODO: 清空回收站 if let Err(err) = fs::rename(&delete_path, &trash_path).await { match err.kind() { @@ -170,7 +176,22 @@ impl LocalDisk { } // FIXME: 先清空回收站吧,有时间再添加判断逻辑 - let _ = fs::remove_dir_all(&trash_path).await; + + if let Err(err) = { + if trash_path.is_dir() { + fs::remove_dir_all(&trash_path).await + } else { + fs::remove_file(&trash_path).await + } + } { + match err.kind() { + ErrorKind::NotFound => (), + _ => { + warn!("delete_file remove trash {:?} err {:?}", &trash_path, &err); + return Err(Error::from(err)); + } + } + } // TODO: immediate Ok(()) @@ -201,6 +222,7 @@ impl LocalDisk { } else { if delete_path.is_dir() { if let Err(err) = fs::remove_dir(&delete_path).await { + debug!("remove_dir err {:?} when {:?}", &err, &delete_path); match err.kind() { ErrorKind::NotFound => (), // ErrorKind::DirectoryNotEmpty => (), @@ -214,6 +236,7 @@ impl LocalDisk { } } else { if let Err(err) = fs::remove_file(&delete_path).await { + debug!("remove_file err {:?} when {:?}", &err, &delete_path); match err.kind() { ErrorKind::NotFound => (), _ => { @@ -299,16 +322,17 @@ impl LocalDisk { for fi in fis { let data_dir = fm.delete_version(fi)?; - + warn!("删除版本号 对应data_dir {:?}", &data_dir); if data_dir.is_some() { let dir_path = self.get_object_path(volume, format!("{}/{}", path, data_dir.unwrap().to_string()).as_str())?; - self.move_to_trash(&dir_path, true, false).await?; } } // 没有版本了,删除xl.meta if fm.versions.is_empty() { + warn!("没有版本了,删除xl.meta"); + self.delete_file(&volume_dir, &xlpath, true, false).await?; return Ok(()); }