This is an automated email from the ASF dual-hosted git repository.

suyanhanx pushed a commit to branch gdrive
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/gdrive by this push:
     new a2a28cba1 fix metadata parse
a2a28cba1 is described below

commit a2a28cba11322c9f1b63d9a3f73982edbae6327e
Author: suyanhanx <[email protected]>
AuthorDate: Tue Aug 22 00:05:42 2023 +0800

    fix metadata parse
    
    Signed-off-by: suyanhanx <[email protected]>
---
 core/src/services/gdrive/backend.rs | 15 ++++++++++-----
 core/src/services/gdrive/core.rs    |  7 ++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/core/src/services/gdrive/backend.rs 
b/core/src/services/gdrive/backend.rs
index 6da2c6d04..49ce23314 100644
--- a/core/src/services/gdrive/backend.rs
+++ b/core/src/services/gdrive/backend.rs
@@ -221,19 +221,24 @@ impl GdriveBackend {
             "application/vnd.google-apps.folder" => EntryMode::DIR,
             _ => EntryMode::FILE,
         });
-        meta = meta.with_content_length(
+
+        let size = if meta.mode() == EntryMode::DIR {
+            // Google Drive does not return the size for folders.
+            0
+        } else {
             metadata
                 .size
-                .unwrap_or(String::from("0"))
+                .expect("file size must exist")
                 .parse::<u64>()
                 .map_err(|e| {
                     Error::new(ErrorKind::Unexpected, "parse content 
length").set_source(e)
-                })?,
-        );
+                })?
+        };
+        meta = meta.with_content_length(size);
         meta = meta.with_last_modified(
             metadata
                 .modified_time
-                .unwrap_or_default()
+                .expect("modified time must exist. please check your query 
param - fields")
                 .parse::<chrono::DateTime<Utc>>()
                 .map_err(|e| {
                     Error::new(ErrorKind::Unexpected, "parse last modified 
time").set_source(e)
diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs
index 3d5517a71..acf8b0747 100644
--- a/core/src/services/gdrive/core.rs
+++ b/core/src/services/gdrive/core.rs
@@ -412,13 +412,18 @@ impl GdriveCore {
 // This is the file struct returned by the Google Drive API.
 // This is a complex struct, but we only add the fields we need.
 // refer to 
https://developers.google.com/drive/api/reference/rest/v3/files#File
-#[derive(Deserialize)]
+#[derive(Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
 pub struct GdriveFile {
     pub mime_type: String,
     pub id: String,
     pub name: String,
     pub size: Option<String>,
+    // The modified time is not returned unless the `fields`
+    // query parameter contains `modifiedTime`.
+    // As we only need the modified time when we do `stat` operation,
+    // if other operations(such as search) do not specify the `fields` query 
parameter,
+    // try to access this field, it will be `None`.
     pub modified_time: Option<String>,
 }
 

Reply via email to