todo:list_object

This commit is contained in:
weisd
2024-07-26 17:29:50 +08:00
parent d378753f7c
commit 5d3cc2146b
7 changed files with 76 additions and 16 deletions
+46 -6
View File
@@ -1,6 +1,6 @@
use std::{
fs::Metadata,
io::SeekFrom,
io::{self, SeekFrom},
os::unix::ffi::OsStringExt,
path::{Path, PathBuf},
sync::Arc,
@@ -218,8 +218,14 @@ impl LocalDisk {
if recursive {
let trash_path = self.get_object_path(RUSTFS_META_TMP_DELETED_BUCKET, Uuid::new_v4().to_string().as_str())?;
fs::create_dir_all(&trash_path).await?;
fs::rename(&delete_path, &trash_path).await?;
// fs::create_dir_all(&trash_path).await?;
fs::rename(&delete_path, &trash_path).await.map_err(|err| {
// 使用文件路径自定义错误信息
io::Error::new(
err.kind(),
format!("Failed to rename file '{:?}' to '{:?}': {}", &delete_path, &trash_path, err),
)
})?;
// TODO: immediate
@@ -526,6 +532,40 @@ impl DiskAPI for LocalDisk {
// Ok((buffer, bytes_read))
}
async fn list_dir(&self, origvolume: &str, volume: &str, dir_path: &str, count: usize) -> Result<Vec<String>> {
let p = self.get_bucket_path(&volume)?;
let mut entries = fs::read_dir(&p).await?;
let mut volumes = Vec::new();
while let Some(entry) = entries.next_entry().await? {
if let Ok(metadata) = entry.metadata().await {
let vec = entry.file_name().into_vec();
// if !metadata.is_dir() {
// continue;
// }
let name = match String::from_utf8(vec) {
Ok(s) => s,
Err(_) => return Err(Error::msg("Not supported utf8 file name on this platform")),
};
// let created = match metadata.created() {
// Ok(md) => OffsetDateTime::from(md),
// Err(_) => return Err(Error::msg("Not supported created on this platform")),
// };
volumes.push(name);
}
}
Ok(volumes)
}
async fn walk_dir(&self) -> Result<Vec<FileInfo>> {
unimplemented!()
}
async fn rename_data(
&self,
src_volume: &str,
@@ -648,9 +688,9 @@ impl DiskAPI for LocalDisk {
if let Ok(metadata) = entry.metadata().await {
let vec = entry.file_name().into_vec();
if !metadata.is_dir() {
continue;
}
// if !metadata.is_dir() {
// continue;
// }
let name = match String::from_utf8(vec) {
Ok(s) => s,
+4 -2
View File
@@ -26,6 +26,10 @@ pub trait DiskAPI: Debug + Send + Sync + 'static {
async fn create_file(&self, origvolume: &str, volume: &str, path: &str, file_size: usize) -> Result<FileWriter>;
async fn append_file(&self, volume: &str, path: &str) -> Result<FileWriter>;
async fn read_file(&self, volume: &str, path: &str) -> Result<FileReader>;
// 读目录下的所有文件、目录
async fn list_dir(&self, origvolume: &str, volume: &str, dir_path: &str, count: usize) -> Result<Vec<String>>;
// 读目录下的所有xl.meta
async fn walk_dir(&self) -> Result<Vec<FileInfo>>;
async fn rename_data(
&self,
src_volume: &str,
@@ -206,8 +210,6 @@ pub enum DiskError {
impl DiskError {
pub fn check_disk_fatal_errs(errs: &Vec<Option<Error>>) -> Result<()> {
println!("errs: {:?}", errs);
if Self::count_errs(errs, &DiskError::UnsupportedDisk) == errs.len() {
return Err(Error::new(DiskError::UnsupportedDisk));
}
+4
View File
@@ -29,6 +29,10 @@ pub struct Erasure {
impl Erasure {
pub fn new(data_shards: usize, parity_shards: usize, block_size: usize) -> Self {
warn!(
"Erasure new data_shards {},parity_shards {} block_size {} ",
data_shards, parity_shards, block_size
);
Erasure {
data_shards,
parity_shards,
+2
View File
@@ -1,4 +1,5 @@
use futures::future::join_all;
use tracing::warn;
use uuid::Uuid;
use crate::{
@@ -99,6 +100,7 @@ fn get_format_file_in_quorum(formats: &Vec<Option<FormatV3>>) -> Result<FormatV3
let (max_drives, max_count) = countmap.iter().max_by_key(|&(_, c)| c).unwrap_or((&0, &0));
if *max_drives == 0 || *max_count < formats.len() / 2 {
warn!("*max_drives == 0 || *max_count < formats.len() / 2");
return Err(Error::new(ErasureError::ErasureReadQuorum));
}