test_list_path_raw done

This commit is contained in:
weisd
2024-12-17 14:28:37 +08:00
parent dc0d415b15
commit 4195371a1e
9 changed files with 401 additions and 198 deletions
+11
View File
@@ -273,6 +273,17 @@ pub fn is_err_file_not_found(err: &Error) -> bool {
matches!(err.downcast_ref::<DiskError>(), Some(DiskError::FileNotFound))
}
pub fn is_err_volume_not_found(err: &Error) -> bool {
matches!(err.downcast_ref::<DiskError>(), Some(DiskError::VolumeNotFound))
}
pub fn is_err_eof(err: &Error) -> bool {
if let Some(ioerr) = err.downcast_ref::<io::Error>() {
return ioerr.kind() == ErrorKind::UnexpectedEof;
}
false
}
pub fn is_sys_err_no_space(e: &io::Error) -> bool {
if let Some(no) = e.raw_os_error() {
return no == 28;
-47
View File
@@ -2426,51 +2426,4 @@ mod test {
let _ = fs::remove_dir_all(&p).await;
}
#[tokio::test]
async fn test_walk_dir() {
let mut ep = Endpoint::try_from("/Users/weisd/project/weisd/s3-rustfs/target/volume/test").unwrap();
ep.pool_idx = 0;
ep.set_idx = 0;
ep.disk_idx = 0;
let disk = match LocalDisk::new(&ep, false).await {
Ok(res) => res,
Err(err) => {
println!("LocalDisk::new err {:?}", err);
return;
}
};
let (rd, mut wr) = tokio::io::duplex(1024);
let job = tokio::spawn(async move {
let opts = WalkDirOptions {
bucket: "dada".to_owned(),
base_dir: "".to_owned(),
recursive: true,
..Default::default()
};
if let Err(err) = disk.walk_dir(opts, &mut wr).await {
println!("walk_dir err {:?}", err);
}
});
let job2 = tokio::spawn(async move {
let mut mrd = MetacacheReader::new(rd);
while let Some(info) = mrd.peek().await.unwrap_or_default() {
println!("info {:?}", info.name)
}
});
job.await;
job2.await;
// let mut jobs = Vec::new();
// jobs.push(job);
// jobs.push(job2);
// join_all(jobs).await;
}
}
+4 -3
View File
@@ -770,7 +770,8 @@ impl MetaCacheEntry {
}
}
pub struct MetaCacheEntries(pub Vec<MetaCacheEntry>);
#[derive(Debug)]
pub struct MetaCacheEntries(pub Vec<Option<MetaCacheEntry>>);
impl MetaCacheEntries {
pub fn resolve(&self, mut params: MetadataResolutionParams) -> Result<Option<MetaCacheEntry>> {
@@ -785,7 +786,7 @@ impl MetaCacheEntries {
let mut objs_agree = 0;
let mut objs_valid = 0;
for entry in self.0.iter() {
for entry in self.0.iter().flatten() {
if entry.name.is_empty() {
continue;
}
@@ -859,7 +860,7 @@ impl MetaCacheEntries {
}
pub fn first_found(&self) -> (Option<MetaCacheEntry>, usize) {
(self.0.iter().find(|x| !x.name.is_empty()).cloned(), self.0.len())
(self.0.iter().find(|x| x.is_some()).cloned().unwrap_or_default(), self.0.len())
}
}