suyanhanx commented on code in PR #2263:
URL:
https://github.com/apache/incubator-opendal/pull/2263#discussion_r1193331688
##########
core/src/services/sftp/backend.rs:
##########
@@ -375,6 +375,49 @@ impl Accessor for SftpBackend {
Ok((RpWrite::new(), SftpWriter::new(file)))
}
+ async fn copy(&self, from: &str, to: &str, _args: OpCopy) ->
Result<RpCopy> {
+ let client = self.connect().await?;
+
+ let mut fs = client.fs();
+ fs.set_cwd(&self.root);
+
+ if let Some((dir, _)) = to.rsplit_once('/') {
+ self.create_dir(dir, OpCreateDir::default()).await?;
+ }
+
+ let src = fs.canonicalize(from).await?;
+ let dst = fs.canonicalize(to).await?;
+ let mut src_file = client.open(&src).await?;
+ let mut dst_file = client.create(dst).await?;
+
+ // if remote sftp server supports copy extension, use it
+ if let Ok(()) = src_file.copy_all_to(&mut dst_file).await {
+ return Ok(RpCopy::default());
+ }
+
+ src_file.close().await?;
+ let buffer = fs.read(&src).await?;
+ dst_file.write_all(&buffer).await?;
+
+ Ok(RpCopy::default())
Review Comment:
We prefer to implement it only when the backend is natively supported.
Return an error then users can handle it themselves. We don't do fallback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]