diff --git a/yama_wormfile_sftp/src/lib.rs b/yama_wormfile_sftp/src/lib.rs index 95c1401..2bae46f 100644 --- a/yama_wormfile_sftp/src/lib.rs +++ b/yama_wormfile_sftp/src/lib.rs @@ -7,11 +7,12 @@ use openssh_sftp_client::error::SftpErrorKind; use openssh_sftp_client::file::{File, TokioCompatFile}; use openssh_sftp_client::fs::{DirEntry, Fs}; use openssh_sftp_client::Error::SftpError; -use openssh_sftp_client::Sftp; +use openssh_sftp_client::{Sftp, SftpOptions}; use ouroboros::self_referencing; use std::fmt::{Debug, Formatter}; use std::io; use std::io::{ErrorKind, SeekFrom}; +use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use std::pin::Pin; use std::sync::Arc; @@ -76,10 +77,16 @@ impl SftpConn { }, sftp_builder: |ssh_child| { Box::pin(async move { + let sftp_opts = SftpOptions::new() + // Don't buffer infinitely when writing files: 32 MiB per file in flight + // will do. + .tokio_compat_file_write_limit( + NonZeroUsize::new(32 * 1024 * 1024).unwrap(), + ); Sftp::new( ssh_child.stdin().take().unwrap(), ssh_child.stdout().take().unwrap(), - Default::default(), + sftp_opts, ) .await .map_err(|e| eyre::Error::from(e))