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

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


The following commit(s) were added to refs/heads/main by this push:
     new 43df0ccb feat(services/sftp): support copy and read_seek (#2267)
43df0ccb is described below

commit 43df0ccb3f66e11775113a3131f8803d65ba4069
Author: silver-ymz <[email protected]>
AuthorDate: Wed May 17 23:52:42 2023 +0800

    feat(services/sftp): support copy and read_seek (#2267)
    
    * feat(services/sftp): support copy and read_seek
    
    Signed-off-by: silver-ymz <[email protected]>
    
    * add copyable in document
    
    Signed-off-by: silver-ymz <[email protected]>
    
    * fix document typo
    
    Signed-off-by: silver-ymz <[email protected]>
    
    * change copyable to enable_copy
    
    Signed-off-by: silver-ymz <[email protected]>
    
    ---------
    
    Signed-off-by: silver-ymz <[email protected]>
---
 Cargo.lock                        |  8 ++++----
 core/Cargo.toml                   |  2 +-
 core/src/services/sftp/backend.rs | 16 +++++++++++++++-
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index ba053170..bf0603b3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2747,9 +2747,9 @@ dependencies = [
 
 [[package]]
 name = "openssh-sftp-client"
-version = "0.13.4"
+version = "0.13.5"
 source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "cbf7ee42fa3533261da10b179b27ce4fd7b6954b9919836d26d9a96f39c62d26"
+checksum = "866d0eab409a2fcb6b8c3838fdbf10d7399d486548c19179a80f1c1142e93348"
 dependencies = [
  "bytes",
  "derive_destructure2",
@@ -2768,9 +2768,9 @@ dependencies = [
 
 [[package]]
 name = "openssh-sftp-client-lowlevel"
-version = "0.5.0"
+version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "8efd4c88a55c2baa1162e97f201a26a3d0b65773e6f942ada35ef455b1194ede"
+checksum = "f4975d0a824e82d4f61e3edf870254ce97bd7f8154751d2afdd97c7f43e57dff"
 dependencies = [
  "awaitable",
  "bytes",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 6d1f0e99..ccbc2451 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -180,7 +180,7 @@ minitrace = { version = "0.4.0", optional = true }
 moka = { version = "0.10", optional = true, features = ["future"] }
 once_cell = "1"
 openssh = { version = "0.9.9", optional = true }
-openssh-sftp-client = { version = "0.13.4", optional = true, features = [
+openssh-sftp-client = { version = "0.13.5", optional = true, features = [
   "openssh",
   "tracing",
 ] }
diff --git a/core/src/services/sftp/backend.rs 
b/core/src/services/sftp/backend.rs
index 08c9d2cb..d15fba0e 100644
--- a/core/src/services/sftp/backend.rs
+++ b/core/src/services/sftp/backend.rs
@@ -55,7 +55,7 @@ use crate::*;
 /// - [x] write
 /// - [x] create_dir
 /// - [x] delete
-/// - [ ] copy
+/// - [x] copy
 /// - [x] rename
 /// - [x] list
 /// - [ ] ~~scan~~
@@ -69,6 +69,7 @@ use crate::*;
 /// - `user`: Set the login user
 /// - `key`: Set the public key for login
 /// - `known_hosts_strategy`: Set the strategy for known hosts, default to 
`Strict`
+/// - `enable_copy`: Set whether the remote server has copy-file extension
 ///
 /// It doesn't support password login, you can use public key instead.
 ///
@@ -104,6 +105,7 @@ pub struct SftpBuilder {
     user: Option<String>,
     key: Option<String>,
     known_hosts_strategy: Option<String>,
+    enable_copy: bool,
 }
 
 impl Debug for SftpBuilder {
@@ -174,6 +176,14 @@ impl SftpBuilder {
 
         self
     }
+
+    /// set enable_copy for sftp backend.
+    /// It requires the server supports copy-file extension.
+    pub fn enable_copy(&mut self, enable_copy: bool) -> &mut Self {
+        self.enable_copy = enable_copy;
+
+        self
+    }
 }
 
 impl Builder for SftpBuilder {
@@ -225,6 +235,7 @@ impl Builder for SftpBuilder {
             user,
             key: self.key.clone(),
             known_hosts_strategy,
+            copyable: self.enable_copy,
             client: tokio::sync::OnceCell::new(),
         })
     }
@@ -250,6 +261,7 @@ pub struct SftpBackend {
     user: String,
     key: Option<String>,
     known_hosts_strategy: KnownHosts,
+    copyable: bool,
     client: tokio::sync::OnceCell<Sftp>,
 }
 
@@ -278,6 +290,7 @@ impl Accessor for SftpBackend {
 
                 read: true,
                 read_with_range: true,
+                read_can_seek: true,
 
                 write: true,
                 write_without_content_length: true,
@@ -288,6 +301,7 @@ impl Accessor for SftpBackend {
                 list_with_limit: true,
                 list_with_delimiter_slash: true,
 
+                copy: self.copyable,
                 rename: true,
 
                 ..Default::default()

Reply via email to