Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return STAT response as a multi-line in accordance with RFC 959 #381

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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