chitralverma commented on code in PR #7977:
URL: https://github.com/apache/opendal/pull/7977#discussion_r4756951272


##########
core/services/sftp/src/backend.rs:
##########
@@ -197,6 +201,81 @@ impl Builder for SftpBuilder {
     }
 }
 
+/// Copies a remote file through the client, keeping several reads and writes
+/// in flight.
+///
+/// SFTP has no server-side copy, so the payload has to make the round trip.
+async fn stream_copy(

Review Comment:
   04c34d691 removes the streamed copy. `copy` sends the server-side 
`copy-data` extension like the openssh version did, and returns `Unsupported` 
when the server lacks it. Both handles are opened in tasks that own them, so a 
copy cancelled at any point closes them.
   
   *This comment is AI assisted.*



##########
core/services/sftp/src/core.rs:
##########
@@ -153,28 +511,115 @@ impl ManageObject for Manager {
         o: &mut Self::Object,
         _: &ObjectStatus,
     ) -> Result<(), Self::Error> {
-        match o.fs().metadata("./").await {
+        match o.session.stat(".").await {
             Ok(_) => Ok(()),
             Err(e) => Err(parse_sftp_error(e)),
         }
     }
 }
 
+fn clamp_chunk(len: u64) -> u32 {
+    len.min(MAX_CHUNK_SIZE as u64).max(1) as u32
+}
+
+/// Releases a server-side handle without awaiting the reply.
+///
+/// Handles are remote resources, so abandoning a reader, writer, or lister
+/// early must not leak them. `Drop` cannot await, so the close is dispatched
+/// onto the current runtime. Without a runtime the session is already being
+/// torn down, and the server releases the handle along with the channel.
+pub fn close_handle_detached(session: Arc<RawSftpSession>, handle: String) {
+    if let Ok(runtime) = tokio::runtime::Handle::try_current() {
+        runtime.spawn(async move {
+            if let Err(err) = session.close(handle).await {
+                debug!("sftp failed to close handle: {err}");
+            }
+        });
+    }
+}
+
+fn default_user() -> Option<String> {
+    std::env::var("USER")
+        .or_else(|_| std::env::var("USERNAME"))
+        .ok()
+        .filter(|v| !v.is_empty())
+}
+
+fn default_key_paths() -> Vec<std::path::PathBuf> {
+    let Some(home) = std::env::home_dir() else {
+        return Vec::new();
+    };
+    let ssh = home.join(".ssh");
+
+    ["id_ed25519", "id_ecdsa", "id_rsa"]
+        .iter()
+        .map(|name| ssh.join(name))
+        .collect()
+}
+
+/// Splits an endpoint into its user, host, and port parts.
+///
+/// Accepts both `[user@]host[:port]` and `ssh://[user@]host[:port]`, and
+/// defaults the port to 22.
+fn parse_endpoint(endpoint: &str) -> Result<(Option<String>, String, u16)> {

Review Comment:
   04c34d691: `SshEndpoint::parse` uses `url` and runs in `build()`, so a bad 
endpoint returns `ConfigInvalid` there. It accepts `[user@]host[:port]` and 
`ssh://...`, and rejects unbracketed IPv6, passwords, and paths.
   
   *This comment is AI assisted.*



##########
core/services/sftp/src/lister.rs:
##########
@@ -15,75 +15,143 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::pin::Pin;
+use std::collections::VecDeque;
 
-use futures::StreamExt;
-use openssh_sftp_client::fs::DirEntry;
-use openssh_sftp_client::fs::ReadDir;
+use russh_sftp::protocol::{FileAttributes, FileMode};
 
+use super::core::SftpSessionRef;
+use super::core::close_handle_detached;
+use super::core::is_eof;
 use super::core::parse_sftp_error;
 use super::core::to_metadata;
 use opendal_core::Result;
 use opendal_core::raw::oio;
 use opendal_core::raw::oio::Entry;
 
+/// Lists a remote directory one `SSH_FXP_READDIR` batch at a time.
+///
+/// Entries are yielded as they arrive rather than buffering the whole
+/// directory, which keeps memory flat for large directories.
 pub struct SftpLister {
-    dir: Pin<Box<ReadDir>>,
+    /// Keeps the session alive while the directory handle is open.
+    conn: SftpSessionRef,
+    handle: String,
     prefix: String,
+    buffer: VecDeque<(String, FileAttributes)>,

Review Comment:
   04c34d691: a listing must return the directory itself 
(`test_list_empty_dir`). The lister takes it from the `.` entry, as on `main`. 
OpenSSH for Windows sends no `.`, so in that case the lister returns a plain 
directory entry after the last batch.
   
   *This comment is AI assisted.*



-- 
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]

Reply via email to