Skip to content

Commit

Permalink
if path not exists, don't return it
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorgan committed Aug 6, 2024
1 parent d40e03b commit b85bb21
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
4 changes: 0 additions & 4 deletions core/src/raw/oio/list/page_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ pub struct PageContext {
/// PageLister makes sure that entries is reset before calling `next_page`. Implementer
/// can call `push_back` on `entries` directly.
pub entries: VecDeque<oio::Entry>,

/// whether the path itself has been added
pub path_added: bool,
}

/// PageLister implements [`oio::List`] based on [`PageList`].
Expand All @@ -83,7 +80,6 @@ where
done: false,
token: "".to_string(),
entries: VecDeque::new(),
path_added: false,
},
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ impl Access for FsBackend {
};
}
};

let rd = FsLister::new(&self.core.root, path, f);

Ok((RpList::default(), Some(rd)))
Expand Down
21 changes: 2 additions & 19 deletions core/src/services/s3/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl oio::PageList for S3Lister {
if resp.status() != http::StatusCode::OK {
return Err(parse_error(resp));
}

let bs = resp.into_body();

let output: ListObjectsOutput =
Expand All @@ -100,22 +99,19 @@ impl oio::PageList for S3Lister {
};
ctx.token = output.next_continuation_token.clone().unwrap_or_default();

let mut prefix_existing = false;
for prefix in output.common_prefixes {
let de = oio::Entry::new(
&build_rel_path(&self.core.root, &prefix.prefix),
Metadata::new(EntryMode::DIR),
);

ctx.entries.push_back(de);
prefix_existing = true;
}

for object in output.contents {
let path = build_rel_path(&self.core.root, &object.key);

let mut path = build_rel_path(&self.core.root, &object.key);
if path.is_empty() {
continue;
path = "/".to_string();
}

let mut meta = Metadata::new(EntryMode::from_path(&path));
Expand All @@ -130,21 +126,8 @@ impl oio::PageList for S3Lister {
// nanosecond, let's trim them.
meta.set_last_modified(parse_datetime_from_rfc3339(object.last_modified.as_str())?);

if path == self.path {
ctx.path_added = true;
}
let de = oio::Entry::with(path, meta);
ctx.entries.push_back(de);

prefix_existing = true;
}

// if the path is dir, but hasn't created yet and exists only as the prefix of a key,
// add it manually
if prefix_existing && self.path.ends_with("/") && !ctx.path_added {
let entry = oio::Entry::new(self.path.as_str(), Metadata::new(EntryMode::DIR));
ctx.entries.push_front(entry);
ctx.path_added = true;
}

Ok(())
Expand Down
15 changes: 10 additions & 5 deletions core/tests/behavior/async_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use futures::stream::FuturesUnordered;
use futures::StreamExt;
use futures::TryStreamExt;
use log::debug;

use crate::*;

pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
Expand Down Expand Up @@ -370,17 +369,21 @@ pub async fn test_list_sub_dir(op: Operator) -> Result<()> {
/// List dir should also to list nested dir.
pub async fn test_list_nested_dir(op: Operator) -> Result<()> {
let parent = format!("{}/", uuid::Uuid::new_v4());
op.create_dir(&parent)
.await
.expect("create dir must succeed");

let dir = format!("{parent}{}/", uuid::Uuid::new_v4());
op.create_dir(&dir).await.expect("create must succeed");

let file_name = uuid::Uuid::new_v4().to_string();
let file_path = format!("{dir}{file_name}");
let dir_name = format!("{}/", uuid::Uuid::new_v4());
let dir_path = format!("{dir}{dir_name}");

op.create_dir(&dir).await.expect("create must succeed");
op.write(&file_path, "test_list_nested_dir")
.await
.expect("create must succeed");

let dir_name = format!("{}/", uuid::Uuid::new_v4());
let dir_path = format!("{dir}{dir_name}");
op.create_dir(&dir_path).await.expect("create must succeed");

let obs = op.list(&parent).await?;
Expand Down Expand Up @@ -504,6 +507,8 @@ pub async fn test_list_with_start_after(op: Operator) -> Result<()> {
}

pub async fn test_list_root_with_recursive(op: Operator) -> Result<()> {
op.create_dir("/").await?;

let w = op.lister_with("").recursive(true).await?;
let actual = w
.try_collect::<Vec<_>>()
Expand Down

0 comments on commit b85bb21

Please sign in to comment.