silver-ymz commented on code in PR #2263:
URL:
https://github.com/apache/incubator-opendal/pull/2263#discussion_r1193342462
##########
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:
Ok. I'll change it. And in `rename` test, only `test_rename_nested` will
fail. Is there a way to bypass the test? Or we need to provide `rename`
function, but set `rename` capability to false.
--
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]