forked from bolcom/libunftp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dele.rs
67 lines (63 loc) · 2.1 KB
/
dele.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! The RFC 959 Delete (`DELE`) command
//
// This command causes the file specified in the pathname to be
// deleted at the server site. If an extra level of protection
// is desired (such as the query, "Do you really wish to delete?"),
// it should be provided by the user-FTP process.
use crate::{
auth::UserDetail,
server::{
chancomms::ControlChanMsg,
controlchan::{
error::ControlChanError,
handler::{CommandContext, CommandHandler},
Reply,
},
},
storage::{Metadata, StorageBackend},
};
use async_trait::async_trait;
use futures::{channel::mpsc::Sender, prelude::*};
use std::{string::String, sync::Arc};
#[derive(Debug)]
pub struct Dele {
path: String,
}
impl Dele {
pub fn new(path: String) -> Self {
Dele { path }
}
}
#[async_trait]
impl<Storage, User> CommandHandler<Storage, User> for Dele
where
User: UserDetail + 'static,
Storage: StorageBackend<User> + 'static,
Storage::Metadata: Metadata,
{
#[tracing_attributes::instrument]
async fn handle(&self, args: CommandContext<Storage, User>) -> Result<Reply, ControlChanError> {
let session = args.session.lock().await;
let storage = Arc::clone(&session.storage);
let user = session.user.clone();
let path = session.cwd.join(self.path.clone());
let mut tx_success: Sender<ControlChanMsg> = args.tx_control_chan.clone();
let mut tx_fail: Sender<ControlChanMsg> = args.tx_control_chan.clone();
let logger = args.logger;
tokio::spawn(async move {
match storage.del((*user).as_ref().unwrap(), path).await {
Ok(_) => {
if let Err(err) = tx_success.send(ControlChanMsg::DelSuccess).await {
slog::warn!(logger, "{}", err);
}
}
Err(err) => {
if let Err(err) = tx_fail.send(ControlChanMsg::StorageError(err)).await {
slog::warn!(logger, "{}", err);
}
}
}
});
Ok(Reply::none())
}
}