Skip to content

Commit

Permalink
fix Async SSL file uploads not properly closing (#78)
Browse files Browse the repository at this point in the history
* fix Async SSL file uploads not properly closing

* properly map the error instead of using unwrap

* cargo fmt

* fix clippy error

---------

Co-authored-by: Maurits van Riezen <mvriezen@vcn.nl>
  • Loading branch information
mousetail and Maurits van Riezen committed May 18, 2024
1 parent d30849d commit 18bbcc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions suppaftp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pin-project = { version = "^1", optional = true }
# secure
native-tls-crate = { package = "native-tls", version = "^0.2", optional = true }
rustls-crate = { package = "rustls", version = "^0.21", optional = true }
futures-lite = "2.0.0"

[dev-dependencies]
async-attributes = "1.1.2"
Expand Down
9 changes: 7 additions & 2 deletions suppaftp/src/async_ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use std::string::String;
use std::time::Duration;

use async_std::io::prelude::BufReadExt;
use async_std::io::{copy, BufReader, Read, Write, WriteExt};
use async_std::io::{copy, BufReader, Read, Write};
use async_std::net::{TcpListener, TcpStream, ToSocketAddrs};
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use futures_lite::AsyncWriteExt;
// export
pub use data_stream::DataStream;
pub use tls::AsyncNoTlsStream;
Expand Down Expand Up @@ -486,9 +487,13 @@ where
/// Finalize put when using stream
/// This method must be called once the file has been written and
/// `put_with_stream` has been used to write the file
pub async fn finalize_put_stream(&mut self, stream: impl Write) -> FtpResult<()> {
pub async fn finalize_put_stream(&mut self, mut stream: impl Write + Unpin) -> FtpResult<()> {
debug!("Finalizing put stream");
// Drop stream NOTE: must be done first, otherwise server won't return any response
stream
.close()
.await
.map_err(FtpError::ConnectionError)?;
drop(stream);
trace!("Stream dropped");
// Read response
Expand Down

0 comments on commit 18bbcc5

Please sign in to comment.