You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2023/04/12 14:12:44 UTC

[incubator-opendal] branch azdfs-rename created (now 4b8fd775)

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

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


      at 4b8fd775 feat(services/azdfs): support rename

This branch includes the following new commits:

     new 4b8fd775 feat(services/azdfs): support rename

The 1 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.



[incubator-opendal] 01/01: feat(services/azdfs): support rename

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

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

commit 4b8fd775c8851d97bb6602b58ce03367df230efb
Author: suyanhanx <su...@gmail.com>
AuthorDate: Wed Apr 12 22:10:39 2023 +0800

    feat(services/azdfs): support rename
    
    Signed-off-by: suyanhanx <su...@gmail.com>
---
 core/src/services/azdfs/backend.rs | 20 +++++++++++++++++++-
 core/src/services/azdfs/core.rs    | 25 +++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/core/src/services/azdfs/backend.rs b/core/src/services/azdfs/backend.rs
index 4bdf402e..081b4649 100644
--- a/core/src/services/azdfs/backend.rs
+++ b/core/src/services/azdfs/backend.rs
@@ -57,6 +57,7 @@ const KNOWN_AZDFS_ENDPOINT_SUFFIX: &[&str] = &[
 ///
 /// - [x] read
 /// - [x] write
+/// - [x] rename
 /// - [x] list
 /// - [ ] ~~scan~~
 /// - [ ] presign
@@ -308,7 +309,10 @@ impl Accessor for AzdfsBackend {
             .set_root(&self.core.root)
             .set_name(&self.core.filesystem)
             .set_capabilities(
-                AccessorCapability::Read | AccessorCapability::Write | AccessorCapability::List,
+                AccessorCapability::Read
+                    | AccessorCapability::Write
+                    | AccessorCapability::Rename
+                    | AccessorCapability::List,
             )
             .set_hints(AccessorHint::ReadStreamable);
 
@@ -369,6 +373,20 @@ impl Accessor for AzdfsBackend {
         ))
     }
 
+    async fn rename(&self, from: &str, to: &str, _args: OpRename) -> Result<RpRename> {
+        let resp = self.core.azdfs_rename(from, to).await?;
+
+        let status = resp.status();
+
+        match status {
+            StatusCode::CREATED => {
+                resp.into_body().consume().await?;
+                Ok(RpRename::default())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+
     async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
         // Stat root always returns a DIR.
         if path == "/" {
diff --git a/core/src/services/azdfs/core.rs b/core/src/services/azdfs/core.rs
index 8386c4ba..20ab247c 100644
--- a/core/src/services/azdfs/core.rs
+++ b/core/src/services/azdfs/core.rs
@@ -32,6 +32,9 @@ use reqsign::AzureStorageSigner;
 use crate::raw::*;
 use crate::*;
 
+const X_MS_RENAME_SOURCE: &str = "x-ms-rename-source";
+const X_MS_PROPERTIES: &str = "x-ms-properties";
+
 pub struct AzdfsCore {
     pub filesystem: String,
     pub root: String,
@@ -161,6 +164,28 @@ impl AzdfsCore {
         Ok(req)
     }
 
+    pub async fn azdfs_rename(&self, from: &str, to: &str) -> Result<Response<IncomingAsyncBody>> {
+        let source = build_abs_path(&self.root, from);
+        let target = build_abs_path(&self.root, to);
+
+        let url = format!(
+            "{}/{}/{}",
+            self.endpoint,
+            self.filesystem,
+            percent_encode_path(&target)
+        );
+
+        let mut req = Request::put(&url)
+            // We specify overwrite=true to make sure the target file will be overwritten.
+            .header(X_MS_PROPERTIES, "overwrite=true")
+            .header(X_MS_RENAME_SOURCE, percent_encode_path(&source))
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)?;
+
+        self.sign(&mut req).await?;
+        self.send(req).await
+    }
+
     /// ref: https://learn.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/update
     pub fn azdfs_update_request(
         &self,