Skip to content

Commit

Permalink
Fix windows paths (#414)
Browse files Browse the repository at this point in the history
* Improve path separator handling on windows

* Add missing import to make tests compile
  • Loading branch information
dani-garcia authored Jun 19, 2022
1 parent 79e85a1 commit a90d3b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/server/controlchan/commands/pwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ where
async fn handle(&self, args: CommandContext<Storage, User>) -> Result<Reply, ControlChanError> {
let session = args.session.lock().await;
// TODO: properly escape double quotes in `cwd`
Ok(Reply::new_with_string(
ReplyCode::DirCreated,
format!("\"{}\"", session.cwd.as_path().display()),
))

let result = format!("\"{}\"", session.cwd.as_path().display());

// On Windows systems, the path will be formatted with Windows style separators ('\')
// Most FTP clients expect normal UNIX separators ('/'), and they have trouble handling
// Windows style separators, so if we are on a Windows host, we replace the separators here.
#[cfg(windows)]
let result = result.replace(std::path::MAIN_SEPARATOR, "/");

Ok(Reply::new_with_string(ReplyCode::DirCreated, result))
}
}
2 changes: 1 addition & 1 deletion src/server/proxy_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ where
mod tests {
use super::ProxyError;
use proxy_protocol::{version1::ProxyAddresses, ProxyHeader};
use std::net::SocketAddrV4;
use std::net::{SocketAddrV4, Ipv4Addr};
use std::time::Duration;
use tokio::io::AsyncWriteExt;
use tokio::time::sleep;
Expand Down

0 comments on commit a90d3b7

Please sign in to comment.