Skip to content

Commit

Permalink
feat(core/services-gdrive): report stat metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
erickguan committed Nov 16, 2024
1 parent 084892f commit fa55c90
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 6 additions & 1 deletion core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ impl<A: Access> LayeredAccess for CompleteAccessor<A> {
}

async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
self.complete_stat(path, args).await
let capability = self.info.full_capability();
if !capability.stat {
return self.complete_stat(path, args).await;
}

self.inner().stat(path, args).await
}

async fn delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
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 @@ -88,11 +92,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
10 changes: 7 additions & 3 deletions core/src/services/gdrive/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl oio::PageList for GdriveLister {
_ => return Err(parse_error(resp)),
};

// Gdrive returns empty content when this dir is not exist.
// Google Drive returns empty content when this dir does not exist.
if bytes.is_empty() {
ctx.done = true;
return Ok(());
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

0 comments on commit fa55c90

Please sign in to comment.