You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by er...@apache.org on 2026/08/15 07:17:05 UTC

(opendal) branch fix/onedrive-behavior-followups created (now 50cd01b26)

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

erickguan pushed a change to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git


      at 50cd01b26 fix(services/onedrive): honor list start after

This branch includes the following new commits:

     new f0b954f0c createUploadSession requires full path
     new 083999e54 fix(services/onedrive): build upload session URL from full path
     new 285ad051e test(services/onedrive): cover nested upload session paths
     new 74b7b043c fix(services/onedrive): align version capabilities
     new 7382faf9d fix(services/onedrive): normalize oversized suffix reads
     new 2c5d11012 fix(services/onedrive): retry consistency-lag writes
     new 50cd01b26 fix(services/onedrive): honor list start after

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(opendal) 04/07: fix(services/onedrive): align version capabilities

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 74b7b043c87b9bb514880e30180f3049ab946c4d
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Sat Aug 15 12:28:34 2026 +0800

    fix(services/onedrive): align version capabilities
---
 core/services/onedrive/src/backend.rs | 23 +++++++++++--
 core/services/onedrive/src/config.rs  |  4 +--
 core/services/onedrive/src/core.rs    | 64 +++++++++++++++++++++++++++++++++++
 core/services/onedrive/src/lister.rs  | 40 ++++++++++++++++------
 4 files changed, 115 insertions(+), 16 deletions(-)

diff --git a/core/services/onedrive/src/backend.rs b/core/services/onedrive/src/backend.rs
index d2f8597e2..77fd0ce10 100644
--- a/core/services/onedrive/src/backend.rs
+++ b/core/services/onedrive/src/backend.rs
@@ -108,10 +108,10 @@ impl OnedriveBuilder {
         self
     }
 
-    /// Deprecated: OneDrive versioning capability is enabled by default.
+    /// Deprecated: OneDrive version listing is enabled by default.
     #[deprecated(
         since = "0.57.0",
-        note = "OneDrive versioning capability is enabled by default and this option is no longer needed."
+        note = "OneDrive version listing is enabled by default and this option is no longer needed."
     )]
     pub fn enable_versioning(self, _enabled: bool) -> Self {
         self
@@ -143,7 +143,6 @@ impl Builder for OnedriveBuilder {
 
             stat: true,
             stat_with_if_none_match: true,
-            stat_with_version: true,
 
             delete: true,
             create_dir: true,
@@ -354,3 +353,21 @@ impl Service for OnedriveBackend {
         ))
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use opendal_core::Builder;
+    use opendal_core::raw::Service;
+
+    use super::OnedriveBuilder;
+
+    #[test]
+    fn capability_does_not_advertise_versioned_stat() {
+        let backend = OnedriveBuilder::default()
+            .access_token("test-token")
+            .build()
+            .unwrap();
+
+        assert!(!backend.capability().stat_with_version);
+    }
+}
diff --git a/core/services/onedrive/src/config.rs b/core/services/onedrive/src/config.rs
index 5979688fd..a757d16ff 100644
--- a/core/services/onedrive/src/config.rs
+++ b/core/services/onedrive/src/config.rs
@@ -38,10 +38,10 @@ pub struct OnedriveConfig {
     pub client_id: Option<String>,
     /// Microsoft Graph API Application client secret that is in the Azure's app registration portal
     pub client_secret: Option<String>,
-    /// Deprecated: OneDrive versioning capability is enabled by default.
+    /// Deprecated: OneDrive version listing is enabled by default.
     #[deprecated(
         since = "0.57.0",
-        note = "OneDrive versioning capability is enabled by default and this option is no longer needed."
+        note = "OneDrive version listing is enabled by default and this option is no longer needed."
     )]
     pub enable_versioning: bool,
 }
diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index 4af466dfc..e0362cb96 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -263,6 +263,9 @@ impl OneDriveCore {
         self.sign(ctx, &mut request).await?;
 
         let response = ctx.http_transport().send(request).await?;
+        if !response.status().is_success() {
+            return Err(parse_error(response));
+        }
         let decoded_response: GraphApiOneDriveVersionsResponse =
             serde_json::from_reader(response.into_body().reader())
                 .map_err(new_json_deserialize_error)?;
@@ -805,6 +808,7 @@ mod tests {
 
     const ROOT_STAT_RESPONSE: &str = r#"{"id":"0","name":"root","lastModifiedDateTime":"2026-01-01T00:00:00Z","eTag":"aTag","size":0,"parentReference":{"path":"","driveId":"d","id":"p"},"folder":{"childCount":1}}"#;
     const ROOT_CHILDREN_RESPONSE: &str = r#"{"value":[{"id":"1","name":"test.txt","lastModifiedDateTime":"2026-01-01T00:00:00Z","eTag":"aTag","size":5,"parentReference":{"path":"/drive/root:","driveId":"d","id":"p"},"file":{"mimeType":"text/plain"}}]}"#;
+    const VERSION_RESPONSE: &str = r#"{"value":[{"id":"2.0","lastModifiedDateTime":"2026-01-02T00:00:00Z","size":6},{"id":"1.0","lastModifiedDateTime":"2026-01-01T00:00:00Z","size":5}]}"#;
 
     #[derive(Clone)]
     struct MockHttpTransport;
@@ -970,6 +974,66 @@ mod tests {
         assert_eq!(entries[1].path(), "test.txt");
         assert_eq!(entries[1].mode(), EntryMode::FILE);
     }
+
+    #[tokio::test]
+    async fn list_with_versions_returns_each_file_version() {
+        let core = test_core("/");
+        let ctx = OperationContext::new()
+            .with_http_transport(HttpTransporter::new(VersionMockHttpTransport));
+        let lister = OneDriveLister::new(
+            "/".to_string(),
+            core,
+            ctx,
+            Capability {
+                list_with_versions: true,
+                ..Default::default()
+            },
+            &OpList::new().with_versions(true),
+        );
+        let mut lister = oio::PageLister::new(lister);
+
+        let mut entries = Vec::new();
+        while let Some(entry) = lister.next().await.unwrap() {
+            entries.push(entry);
+        }
+
+        assert_eq!(entries.len(), 3);
+        assert_eq!(entries[1].metadata().version(), Some("2.0"));
+        assert_eq!(entries[2].metadata().version(), Some("1.0"));
+    }
+
+    #[derive(Clone)]
+    struct VersionMockHttpTransport;
+
+    impl HttpTransport for VersionMockHttpTransport {
+        async fn fetch(&self, req: Request<Buffer>) -> Result<Response<HttpBody>> {
+            let url = req.uri().to_string();
+            let root_url = OneDriveCore::DRIVE_ROOT_URL;
+            let (status, body) = if url == format!("{root_url}/children?{GENERAL_SELECT_PARAM}") {
+                (StatusCode::OK, ROOT_CHILDREN_RESPONSE)
+            } else if url == root_url {
+                (StatusCode::OK, ROOT_STAT_RESPONSE)
+            } else if url == format!("{root_url}:/test.txt:/versions?{VERSION_SELECT_PARAM}") {
+                (StatusCode::OK, VERSION_RESPONSE)
+            } else {
+                (
+                    StatusCode::NOT_FOUND,
+                    r#"{"error":{"code":"itemNotFound","message":"Item not found"}}"#,
+                )
+            };
+
+            let data = Bytes::from_static(body.as_bytes());
+            let size = data.len() as u64;
+            Ok(Response::builder()
+                .status(status)
+                .header(header::CONTENT_LENGTH, size)
+                .body(HttpBody::new(
+                    stream::iter(vec![Ok(Buffer::from(data))]),
+                    Some(size),
+                ))
+                .unwrap())
+        }
+    }
 }
 
 mod error {
diff --git a/core/services/onedrive/src/lister.rs b/core/services/onedrive/src/lister.rs
index 8dce0d07b..b001d72eb 100644
--- a/core/services/onedrive/src/lister.rs
+++ b/core/services/onedrive/src/lister.rs
@@ -81,7 +81,7 @@ impl oio::PageList for OneDriveLister {
         let decoded_response: GraphApiOneDriveListResponse =
             serde_json::from_reader(bytes.reader()).map_err(new_json_deserialize_error)?;
 
-        let list_with_versions = self.capability.list_with_versions;
+        let list_with_versions = self.op.versions() && self.capability.list_with_versions;
 
         // Include the current directory itself when handling the first page of the listing.
         if ctx.token.is_empty() && !ctx.done {
@@ -135,22 +135,40 @@ impl oio::PageList for OneDriveLister {
             let last_modified = drive_item.last_modified_date_time.parse::<Timestamp>()?;
             meta.set_last_modified(last_modified);
 
-            // When listing a directory with `$expand=versions`, OneDrive returns 400 "Operation not supported".
-            // Thus, `list_with_versions` induces N+1 requests. This N+1 is intentional.
-            // N+1 is horrendous but we can't do any better without OneDrive's API support.
-            // When OneDrive supports listing with versions API, remove this.
-            if list_with_versions {
+            // OneDrive doesn't support expanding versions while listing a directory.
+            // Query each file separately when callers request versions.
+            if list_with_versions && entry_mode == EntryMode::FILE {
                 let versions = self
                     .core
                     .onedrive_list_versions(&self.ctx, &normalized_path)
                     .await?;
-                if let Some(version) = versions.first() {
-                    meta.set_version(&version.id);
+
+                if versions.is_empty() {
+                    ctx.entries
+                        .push_back(oio::Entry::new(&normalized_path, meta));
+                    continue;
                 }
-            }
 
-            let entry = oio::Entry::new(&normalized_path, meta);
-            ctx.entries.push_back(entry)
+                for (index, version) in versions.into_iter().enumerate() {
+                    let mut version_meta =
+                        Metadata::new(entry_mode).with_content_length(version.size.max(0) as u64);
+                    version_meta
+                        .set_last_modified(version.last_modified_date_time.parse::<Timestamp>()?);
+                    version_meta.set_version(&version.id);
+                    version_meta.set_is_current(index == 0);
+
+                    // OneDrive exposes the ETag only for the current item.
+                    if index == 0 {
+                        version_meta.set_etag(meta.etag().unwrap_or_default());
+                    }
+
+                    ctx.entries
+                        .push_back(oio::Entry::new(&normalized_path, version_meta));
+                }
+            } else {
+                ctx.entries
+                    .push_back(oio::Entry::new(&normalized_path, meta));
+            }
         }
 
         Ok(())


(opendal) 03/07: test(services/onedrive): cover nested upload session paths

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 285ad051ece1a7c1ec8ef8092384ed83937a6fee
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Sat Aug 15 12:06:38 2026 +0800

    test(services/onedrive): cover nested upload session paths
---
 core/services/onedrive/src/core.rs | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index bb8c264d6..4af466dfc 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -929,6 +929,24 @@ mod tests {
         );
     }
 
+    #[test]
+    fn upload_session_request_for_nested_encoded_path_uses_full_path_addressing() {
+        let core = test_core("/base/");
+        let request = core
+            .onedrive_create_upload_session_request(
+                "nested directory/upload session #1.bin",
+                &OpWrite::default(),
+            )
+            .unwrap();
+        assert_eq!(
+            request.uri().to_string(),
+            format!(
+                "{}:/base/nested%20directory/upload%20session%20%231.bin:/createUploadSession",
+                OneDriveCore::DRIVE_ROOT_URL
+            )
+        );
+    }
+
     #[tokio::test]
     async fn list_root_returns_entries() {
         let core = test_core("/");


(opendal) 06/07: fix(services/onedrive): retry consistency-lag writes

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 2c5d11012d0d5831317cd61e4208ac670356b30f
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Sat Aug 15 12:28:34 2026 +0800

    fix(services/onedrive): retry consistency-lag writes
---
 core/services/onedrive/src/backend.rs |  4 +-
 core/services/onedrive/src/core.rs    | 81 ++++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/core/services/onedrive/src/backend.rs b/core/services/onedrive/src/backend.rs
index 77fd0ce10..f8c29f182 100644
--- a/core/services/onedrive/src/backend.rs
+++ b/core/services/onedrive/src/backend.rs
@@ -23,7 +23,7 @@ use opendal_core::raw::*;
 use opendal_core::*;
 
 use super::core::OneDriveCore;
-use super::core::parse_error;
+use super::core::parse_write_consistency_error;
 use super::deleter::OneDriveDeleter;
 use super::lister::OneDriveLister;
 use super::reader::*;
@@ -244,7 +244,7 @@ impl Service for OnedriveBackend {
         let response = self.core.onedrive_create_dir(ctx, path).await?;
         match response.status() {
             StatusCode::CREATED | StatusCode::OK => Ok(RpCreateDir::default()),
-            _ => Err(parse_error(response)),
+            _ => Err(parse_write_consistency_error(response)),
         }
     }
 
diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index e0362cb96..dde05b848 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -132,7 +132,7 @@ impl OneDriveCore {
                         serde_json::from_reader(bytes.reader())
                             .map_err(new_json_deserialize_error)?
                     }
-                    _ => return Err(parse_error(response)),
+                    _ => return Err(parse_write_consistency_error(response)),
                 }
             }
             _ => return Err(parse_error(response)),
@@ -620,7 +620,7 @@ impl OneDriveCore {
                     )
                 })
                 .map(String::from),
-            _ => Err(parse_error(response)),
+            _ => Err(parse_write_consistency_error(response)),
         }
     }
 
@@ -1039,17 +1039,34 @@ mod tests {
 mod error {
     use http::Response;
     use http::StatusCode;
+    use serde::Deserialize;
 
     use opendal_core::raw::*;
     use opendal_core::*;
 
     /// Parse error response into Error.
     pub(crate) fn parse_error(response: Response<Buffer>) -> Error {
+        parse_error_with_consistency_retry(response, false)
+    }
+
+    pub(crate) fn parse_write_consistency_error(response: Response<Buffer>) -> Error {
+        parse_error_with_consistency_retry(response, true)
+    }
+
+    fn parse_error_with_consistency_retry(
+        response: Response<Buffer>,
+        retry_consistency_lag: bool,
+    ) -> Error {
         let (parts, body) = response.into_parts();
         let bs = body.to_bytes();
 
         let (kind, retryable) = match parts.status {
             StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
+            // OneDrive can return this exact response before a just-created path
+            // becomes available to a follow-up write operation.
+            StatusCode::BAD_REQUEST if retry_consistency_lag && is_consistency_lag_error(&bs) => {
+                (ErrorKind::Unexpected, true)
+            }
             // The OneDrive service replaces resources.
             // However, the Onedrive doesn't have Strong Read-After-Write properties,
             // the concurrent requests to create directories might result in errors.
@@ -1081,6 +1098,66 @@ mod error {
 
         err
     }
+
+    fn is_consistency_lag_error(body: &[u8]) -> bool {
+        let Ok(response) = serde_json::from_slice::<GraphErrorResponse>(body) else {
+            return false;
+        };
+
+        response.error.code == "invalidRequest" && response.error.message == "Invalid request"
+    }
+
+    #[derive(Deserialize)]
+    struct GraphErrorResponse {
+        error: GraphError,
+    }
+
+    #[derive(Deserialize)]
+    struct GraphError {
+        code: String,
+        message: String,
+    }
+
+    #[cfg(test)]
+    mod tests {
+        use super::*;
+
+        #[test]
+        fn invalid_request_from_consistency_lag_is_temporary() {
+            let response = Response::builder()
+                .status(StatusCode::BAD_REQUEST)
+                .body(Buffer::from(
+                    r#"{"error":{"code":"invalidRequest","message":"Invalid request"}}"#,
+                ))
+                .unwrap();
+
+            assert!(parse_write_consistency_error(response).is_temporary());
+        }
+
+        #[test]
+        fn invalid_request_is_not_temporary_outside_write_consistency_handling() {
+            let response = Response::builder()
+                .status(StatusCode::BAD_REQUEST)
+                .body(Buffer::from(
+                    r#"{"error":{"code":"invalidRequest","message":"Invalid request"}}"#,
+                ))
+                .unwrap();
+
+            assert!(!parse_error(response).is_temporary());
+        }
+
+        #[test]
+        fn other_bad_requests_are_not_temporary() {
+            let response = Response::builder()
+                .status(StatusCode::BAD_REQUEST)
+                .body(Buffer::from(
+                    r#"{"error":{"code":"invalidRequest","message":"Name from path does not match name from body"}}"#,
+                ))
+                .unwrap();
+
+            assert!(!parse_write_consistency_error(response).is_temporary());
+        }
+    }
 }
 
 pub(super) use error::*;


(opendal) 02/07: fix(services/onedrive): build upload session URL from full path

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 083999e544d797b6b198f7d5aad97ba60681a0f9
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Fri Aug 14 22:50:49 2026 +0800

    fix(services/onedrive): build upload session URL from full path
---
 core/services/onedrive/src/core.rs | 51 ++++++++++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 7 deletions(-)

diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index 49cff5f6e..bb8c264d6 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -447,17 +447,15 @@ impl OneDriveCore {
     /// This endpoint supports `If-None-Match` but [`onedrive_upload_simple()`] doesn't.
     ///
     /// Read more at https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession?view=odsp-graph-online#upload-bytes-to-the-upload-session
-    pub(crate) async fn onedrive_create_upload_session(
+    pub(crate) fn onedrive_create_upload_session_request(
         &self,
-        ctx: &OperationContext,
         path: &str,
         args: &OpWrite,
-    ) -> Result<Response<Buffer>> {
-        let parent_path = get_parent(path);
+    ) -> Result<Request<Buffer>> {
         let file_name = get_basename(path);
         let url = format!(
             "{}:/createUploadSession",
-            self.onedrive_item_url(parent_path, true) + "/" + file_name,
+            self.onedrive_item_url(path, true),
         );
         let mut request = Request::post(url).header(header::CONTENT_TYPE, "application/json");
 
@@ -468,11 +466,20 @@ impl OneDriveCore {
         let body = OneDriveUploadSessionCreationRequestBody::new(file_name.to_string());
         let body_bytes = serde_json::to_vec(&body).map_err(new_json_serialize_error)?;
         let body = Buffer::from(Bytes::from(body_bytes));
-        let mut request = request
+        request
             .extension(Operation::Write)
             .extension(ServiceOperation("CreateUploadSession"))
             .body(body)
-            .map_err(new_request_build_error)?;
+            .map_err(new_request_build_error)
+    }
+
+    pub(crate) async fn onedrive_create_upload_session(
+        &self,
+        ctx: &OperationContext,
+        path: &str,
+        args: &OpWrite,
+    ) -> Result<Response<Buffer>> {
+        let mut request = self.onedrive_create_upload_session_request(path, args)?;
 
         self.sign(ctx, &mut request).await?;
 
@@ -892,6 +899,36 @@ mod tests {
         );
     }
 
+    #[test]
+    fn upload_session_request_for_root_file_uses_path_addressing() {
+        let core = test_core("/");
+        let request = core
+            .onedrive_create_upload_session_request("file.bin", &OpWrite::default())
+            .unwrap();
+        assert_eq!(
+            request.uri().to_string(),
+            format!(
+                "{}:/file.bin:/createUploadSession",
+                OneDriveCore::DRIVE_ROOT_URL
+            )
+        );
+    }
+
+    #[test]
+    fn upload_session_request_percent_encodes_file_name() {
+        let core = test_core("/");
+        let request = core
+            .onedrive_create_upload_session_request("upload session #1.bin", &OpWrite::default())
+            .unwrap();
+        assert_eq!(
+            request.uri().to_string(),
+            format!(
+                "{}:/upload%20session%20%231.bin:/createUploadSession",
+                OneDriveCore::DRIVE_ROOT_URL
+            )
+        );
+    }
+
     #[tokio::test]
     async fn list_root_returns_entries() {
         let core = test_core("/");


(opendal) 05/07: fix(services/onedrive): normalize oversized suffix reads

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 7382faf9dcbe38ce0ca717cc874cf90eb2197525
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Sat Aug 15 12:28:34 2026 +0800

    fix(services/onedrive): normalize oversized suffix reads
---
 core/services/onedrive/src/reader.rs | 111 +++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/core/services/onedrive/src/reader.rs b/core/services/onedrive/src/reader.rs
index 0413b63ec..627add25d 100644
--- a/core/services/onedrive/src/reader.rs
+++ b/core/services/onedrive/src/reader.rs
@@ -51,6 +51,17 @@ impl oio::StreamRead for OnedriveReader {
         let backend = &self.backend;
         let path = self.path.as_str();
         let args = self.args.clone();
+        let range = match range {
+            BytesRange::Suffix { size } => {
+                let content_length = backend
+                    .core
+                    .onedrive_stat(&self.ctx, path, OpStat::default())
+                    .await?
+                    .content_length();
+                BytesRange::new(content_length.saturating_sub(size), None)
+            }
+            range => range,
+        };
         let response = backend
             .core
             .onedrive_get_content(&self.ctx, path, range, &args)
@@ -70,3 +81,103 @@ impl oio::StreamRead for OnedriveReader {
         Ok((rp, Box::new(stream) as Box<dyn oio::ReadStreamDyn>))
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use std::sync::Arc;
+    use std::sync::Mutex;
+
+    use bytes::Bytes;
+    use futures::stream;
+    use http::Request;
+    use http::Response;
+    use http::StatusCode;
+    use http::header;
+
+    use super::*;
+    use crate::core::OneDriveCore;
+    use crate::core::OneDriveSigner;
+
+    const FILE_STAT_RESPONSE: &str = r#"{"id":"1","name":"file.txt","lastModifiedDateTime":"2026-01-01T00:00:00Z","eTag":"aTag","size":1024,"parentReference":{"path":"/drive/root:","driveId":"d","id":"p"},"file":{"mimeType":"text/plain"}}"#;
+
+    type RecordedRequest = (String, Option<String>);
+    type RecordedRequests = Arc<Mutex<Vec<RecordedRequest>>>;
+
+    #[derive(Clone)]
+    struct MockHttpTransport {
+        requests: RecordedRequests,
+    }
+
+    impl HttpTransport for MockHttpTransport {
+        async fn fetch(&self, req: Request<Buffer>) -> Result<Response<HttpBody>> {
+            let uri = req.uri().to_string();
+            let range = req
+                .headers()
+                .get(header::RANGE)
+                .map(|value| value.to_str().unwrap().to_string());
+            self.requests.lock().unwrap().push((uri.clone(), range));
+
+            let (status, body) = if uri.ends_with(":/content") {
+                match self.requests.lock().unwrap().last().unwrap().1.as_deref() {
+                    Some("bytes=-2048") => (StatusCode::RANGE_NOT_SATISFIABLE, ""),
+                    Some("bytes=0-") => (StatusCode::OK, "content"),
+                    _ => (StatusCode::BAD_REQUEST, ""),
+                }
+            } else {
+                (StatusCode::OK, FILE_STAT_RESPONSE)
+            };
+
+            let bytes = Bytes::from_static(body.as_bytes());
+            let size = bytes.len() as u64;
+            Ok(Response::builder()
+                .status(status)
+                .header(header::CONTENT_LENGTH, size)
+                .body(HttpBody::new(
+                    stream::iter(vec![Ok(Buffer::from(bytes))]),
+                    Some(size),
+                ))
+                .unwrap())
+        }
+    }
+
+    fn test_backend() -> OnedriveBackend {
+        let mut signer = OneDriveSigner::new();
+        signer.access_token = "token".to_string();
+        signer.expires_in = Timestamp::MAX;
+
+        OnedriveBackend {
+            core: Arc::new(OneDriveCore {
+                info: ServiceInfo::new("onedrive", "/", ""),
+                capability: Capability::default(),
+                root: "/".to_string(),
+                signer: Arc::new(asyncband::mutex::Mutex::new(signer)),
+            }),
+        }
+    }
+
+    #[tokio::test]
+    async fn read_suffix_larger_than_file_requests_full_content() {
+        let transport = MockHttpTransport {
+            requests: Arc::new(Mutex::new(Vec::new())),
+        };
+        let requests = transport.requests.clone();
+        let ctx = OperationContext::new().with_http_transport(HttpTransporter::new(transport));
+        let backend = test_backend();
+
+        let reader = Service::read(&backend, &ctx, "file.txt", OpRead::default()).unwrap();
+        oio::Read::open(&reader, BytesRange::suffix(2048))
+            .await
+            .unwrap();
+
+        assert_eq!(
+            *requests.lock().unwrap(),
+            vec![
+                (format!("{}:/file.txt", OneDriveCore::DRIVE_ROOT_URL), None,),
+                (
+                    format!("{}:/file.txt:/content", OneDriveCore::DRIVE_ROOT_URL),
+                    Some("bytes=0-".to_string()),
+                ),
+            ]
+        );
+    }
+}


(opendal) 01/07: createUploadSession requires full path

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit f0b954f0c0a837f2ae27b282242d3c663c4653ff
Author: Benjamin Desef <pr...@users.noreply.github.com>
AuthorDate: Wed Aug 12 16:26:18 2026 +0200

    createUploadSession requires full path
---
 core/services/onedrive/src/core.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index 849b19547..49cff5f6e 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -457,7 +457,7 @@ impl OneDriveCore {
         let file_name = get_basename(path);
         let url = format!(
             "{}:/createUploadSession",
-            self.onedrive_item_url(parent_path, true),
+            self.onedrive_item_url(parent_path, true) + "/" + file_name,
         );
         let mut request = Request::post(url).header(header::CONTENT_TYPE, "application/json");
 


(opendal) 07/07: fix(services/onedrive): honor list start after

Posted by er...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

erickguan pushed a commit to branch fix/onedrive-behavior-followups
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit 50cd01b267cf616c64d03b07685d37ebdc7e45e8
Author: Erick Guan <29...@users.noreply.github.com>
AuthorDate: Sat Aug 15 14:02:36 2026 +0800

    fix(services/onedrive): honor list start after
---
 core/services/onedrive/src/backend.rs |  4 +-
 core/services/onedrive/src/core.rs    | 87 +++++++++++++++++++++++++++++++++++
 core/services/onedrive/src/lister.rs  | 16 ++++++-
 3 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/core/services/onedrive/src/backend.rs b/core/services/onedrive/src/backend.rs
index f8c29f182..62098a5ca 100644
--- a/core/services/onedrive/src/backend.rs
+++ b/core/services/onedrive/src/backend.rs
@@ -149,6 +149,7 @@ impl Builder for OnedriveBuilder {
 
             list: true,
             list_with_limit: true,
+            list_with_start_after: true,
             list_with_versions: true,
 
             shared: true,
@@ -362,12 +363,13 @@ mod tests {
     use super::OnedriveBuilder;
 
     #[test]
-    fn capability_does_not_advertise_versioned_stat() {
+    fn capabilities_match_supported_version_listing() {
         let backend = OnedriveBuilder::default()
             .access_token("test-token")
             .build()
             .unwrap();
 
         assert!(!backend.capability().stat_with_version);
+        assert!(backend.capability().list_with_start_after);
     }
 }
diff --git a/core/services/onedrive/src/core.rs b/core/services/onedrive/src/core.rs
index dde05b848..a1349ff05 100644
--- a/core/services/onedrive/src/core.rs
+++ b/core/services/onedrive/src/core.rs
@@ -1002,6 +1002,44 @@ mod tests {
         assert_eq!(entries[2].metadata().version(), Some("1.0"));
     }
 
+    #[tokio::test]
+    async fn list_with_versions_respects_start_after() {
+        let core = test_core("/");
+        let ctx = OperationContext::new()
+            .with_http_transport(HttpTransporter::new(StartAfterMockHttpTransport));
+        let lister = OneDriveLister::new(
+            "dir/".to_string(),
+            core,
+            ctx,
+            Capability {
+                list_with_start_after: true,
+                list_with_versions: true,
+                ..Default::default()
+            },
+            &OpList::new()
+                .with_versions(true)
+                .with_start_after("dir/file-2"),
+        );
+        let mut lister = oio::PageLister::new(lister);
+
+        let mut paths = Vec::new();
+        while let Some(entry) = lister.next().await.unwrap() {
+            paths.push(entry.path().to_string());
+        }
+
+        assert_eq!(
+            paths,
+            [
+                "dir/file-3",
+                "dir/file-3",
+                "dir/file-4",
+                "dir/file-4",
+                "dir/file-5",
+                "dir/file-5",
+            ]
+        );
+    }
+
     #[derive(Clone)]
     struct VersionMockHttpTransport;
 
@@ -1034,6 +1072,55 @@ mod tests {
                 .unwrap())
         }
     }
+
+    #[derive(Clone)]
+    struct StartAfterMockHttpTransport;
+
+    impl HttpTransport for StartAfterMockHttpTransport {
+        async fn fetch(&self, req: Request<Buffer>) -> Result<Response<HttpBody>> {
+            let url = req.uri().to_string();
+            let root_url = OneDriveCore::DRIVE_ROOT_URL;
+
+            let (status, body) = if url
+                == format!("{root_url}:/dir:/children?{GENERAL_SELECT_PARAM}")
+            {
+                let items = (0..6)
+                    .map(|index| {
+                        format!(
+                            r#"{{"id":"{index}","name":"file-{index}","lastModifiedDateTime":"2026-01-01T00:00:00Z","eTag":"tag-{index}","size":5,"parentReference":{{"path":"/drive/root:/dir","driveId":"d","id":"p"}},"file":{{"mimeType":"text/plain"}}}}"#
+                        )
+                    })
+                    .collect::<Vec<_>>()
+                    .join(",");
+                (StatusCode::OK, format!(r#"{{"value":[{items}]}}"#))
+            } else if url == format!("{root_url}:/dir") {
+                (
+                    StatusCode::OK,
+                    r#"{"id":"dir","name":"dir","lastModifiedDateTime":"2026-01-01T00:00:00Z","eTag":"dir-tag","size":0,"parentReference":{"path":"/drive/root:","driveId":"d","id":"p"},"folder":{"childCount":6}}"#.to_string(),
+                )
+            } else if url.starts_with(&format!("{root_url}:/dir/file-"))
+                && url.ends_with(&format!(":/versions?{VERSION_SELECT_PARAM}"))
+            {
+                (StatusCode::OK, VERSION_RESPONSE.to_string())
+            } else {
+                (
+                    StatusCode::NOT_FOUND,
+                    r#"{"error":{"code":"itemNotFound","message":"Item not found"}}"#.to_string(),
+                )
+            };
+
+            let data = Bytes::from(body);
+            let size = data.len() as u64;
+            Ok(Response::builder()
+                .status(status)
+                .header(header::CONTENT_LENGTH, size)
+                .body(HttpBody::new(
+                    stream::iter(vec![Ok(Buffer::from(data))]),
+                    Some(size),
+                ))
+                .unwrap())
+        }
+    }
 }
 
 mod error {
diff --git a/core/services/onedrive/src/lister.rs b/core/services/onedrive/src/lister.rs
index b001d72eb..ab7bb540b 100644
--- a/core/services/onedrive/src/lister.rs
+++ b/core/services/onedrive/src/lister.rs
@@ -54,6 +54,12 @@ impl OneDriveLister {
             op: args.clone(),
         }
     }
+
+    fn is_after_start(&self, path: &str) -> bool {
+        self.op
+            .start_after()
+            .is_none_or(|start_after| path > start_after)
+    }
 }
 
 impl oio::PageList for OneDriveLister {
@@ -100,8 +106,10 @@ impl oio::PageList for OneDriveLister {
 
             // skip `list_with_versions` intentionally because a folder doesn't have versions
 
-            let entry = oio::Entry::new(&path, meta);
-            ctx.entries.push_back(entry);
+            if self.is_after_start(&path) {
+                let entry = oio::Entry::new(&path, meta);
+                ctx.entries.push_back(entry);
+            }
         }
 
         if let Some(next_link) = decoded_response.next_link {
@@ -129,6 +137,10 @@ impl oio::PageList for OneDriveLister {
                 normalized_path.push('/');
             }
 
+            if !self.is_after_start(&normalized_path) {
+                continue;
+            }
+
             let mut meta = Metadata::new(entry_mode)
                 .with_etag(drive_item.e_tag)
                 .with_content_length(drive_item.size.max(0) as u64);