Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/gdrive): List shows modified timestamp gdrive #5226

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<A: Access> CompleteAccessor<A> {
));
}

return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
return Ok(RpStat::new(meta));
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
}

// Otherwise, we can simulate stat dir via `list`.
Expand Down
13 changes: 9 additions & 4 deletions core/src/services/gdrive/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ impl Access for GdriveBackend {
.set_root(&self.core.root)
.set_native_capability(Capability {
stat: true,
stat_has_content_length: true,
stat_has_content_type: true,
stat_has_last_modified: true,

read: true,

list: true,
list_has_content_type: true,

write: true,

Expand Down Expand Up @@ -91,11 +95,12 @@ impl Access for GdriveBackend {
let gdrive_file: GdriveFile =
serde_json::from_reader(bs.reader()).map_err(new_json_deserialize_error)?;

if gdrive_file.mime_type == "application/vnd.google-apps.folder" {
return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
let file_type = if gdrive_file.mime_type == "application/vnd.google-apps.folder" {
EntryMode::DIR
} else {
EntryMode::FILE
};

let mut meta = Metadata::new(EntryMode::FILE);
let mut meta = Metadata::new(file_type).with_content_type(gdrive_file.mime_type);
if let Some(v) = gdrive_file.size {
meta = meta.with_content_length(v.parse::<u64>().map_err(|e| {
Error::new(ErrorKind::Unexpected, "parse content length").set_source(e)
Expand Down
12 changes: 8 additions & 4 deletions core/src/services/gdrive/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ impl oio::PageList for GdriveLister {
_ => return Err(parse_error(resp)),
};

// Gdrive returns empty content when this dir is not exist.
// Google Drive returns an empty response when attempting to list a non-existent directory.
if bytes.is_empty() {
ctx.done = true;
return Ok(());
}

// Return self at the first page.
// Include the current directory itself when handling the first page of the listing.
if ctx.token.is_empty() && !ctx.done {
let path = build_rel_path(&self.core.root, &self.path);
let e = oio::Entry::new(&path, Metadata::new(EntryMode::DIR));
Expand Down Expand Up @@ -94,8 +94,12 @@ impl oio::PageList for GdriveLister {
let path = format!("{}{}", &self.path, file.name);
let normalized_path = build_rel_path(root, &path);

// Update path cache with list result.
self.core.path_cache.insert(&path, &file.id).await;
// Update path cache when path doesn't exist.
// When Google Drive converts a format, for example, Microsoft PowerPoint,
// Google Drive keeps two entries with the same ID.
if let Ok(None) = self.core.path_cache.get(&path).await {
self.core.path_cache.insert(&path, &file.id).await;
}

let entry = oio::Entry::new(&normalized_path, Metadata::new(file_type));
ctx.entries.push_back(entry);
Expand Down
Loading