Skip to content

Commit

Permalink
Return STAT response as a multi-line in accordance with RFC 959 (#381)
Browse files Browse the repository at this point in the history
Fixes issue #380
  • Loading branch information
robklg authored Sep 24, 2021
1 parent 49deb50 commit 81bde89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/server/controlchan/commands/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
};
use async_trait::async_trait;
use bytes::Bytes;
use std::{io::Read, sync::Arc};
use std::sync::Arc;
use tokio::sync::mpsc::Sender;

#[derive(Debug)]
Expand Down Expand Up @@ -86,19 +86,13 @@ where
let logger = args.logger;

tokio::spawn(async move {
match storage.list_fmt((*user).as_ref().unwrap(), path).await {
Ok(mut cursor) => {
let mut result: String = String::new();
match cursor.read_to_string(&mut result) {
Ok(_) => {
if let Err(err) = tx_success
.send(ControlChanMsg::CommandChannelReply(Reply::new_with_string(ReplyCode::CommandOkay, result)))
.await
{
slog::warn!(logger, "{}", err);
}
}
Err(err) => slog::warn!(logger, "{}", err),
match storage.list_vec((*user).as_ref().unwrap(), path).await {
Ok(lines) => {
if let Err(err) = tx_success
.send(ControlChanMsg::CommandChannelReply(Reply::new_multiline(ReplyCode::CommandOkay, lines)))
.await
{
slog::warn!(logger, "{}", err);
}
}
Err(e) => {
Expand Down
1 change: 1 addition & 0 deletions src/server/controlchan/line_parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct ParseError {
///
/// [ParseError]: ./struct.ParseError.html
#[derive(Clone, Eq, PartialEq, Debug, Display)]
#[allow(clippy::enum_variant_names)]
pub enum ParseErrorKind {
/// The client issued an invalid command (e.g. required parameters are missing).
#[display(fmt = "Invalid command")]
Expand Down
13 changes: 13 additions & 0 deletions src/storage/storage_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ pub trait StorageBackend<User: UserDetail>: Send + Sync + Debug {
Ok(std::io::Cursor::new(file_infos))
}

/// Returns directory listing as a vec of strings used for multi line response in the control channel.
#[tracing_attributes::instrument]
async fn list_vec<P>(&self, user: &User, path: P) -> std::result::Result<Vec<String>, Error>
where
P: AsRef<Path> + Send + Debug,
Self::Metadata: Metadata + 'static,
{
let inlist = self.list(user, path).await?;
let out = inlist.iter().map(|fi| fi.to_string()).collect::<Vec<String>>();

Ok(out)
}

/// Returns some bytes that make up a NLST directory listing (only the basename) that can
/// immediately be sent to the client.
#[allow(clippy::type_complexity)]
Expand Down

0 comments on commit 81bde89

Please sign in to comment.