Derive Downloads dir for the user

This commit is contained in:
reykfloeter 2019-12-01 11:56:06 +00:00
parent 30671b86f7
commit 233541c71d
1 changed files with 8 additions and 8 deletions

View File

@ -14,6 +14,7 @@
use crate::Config;
use dialog::{backends::Zenity, DialogBox};
use dirs::home_dir;
use std::{
io::{Error, ErrorKind, Result},
path::{PathBuf, MAIN_SEPARATOR},
@ -28,10 +29,15 @@ use tokio::{
use tokio_libtls::prelude::*;
const MAX_COPIES: usize = 1024;
const DOWNLOAD_DIR: &str = "Downloads";
pub(crate) async fn run(config: Config) -> Result<()> {
let (cert, key, ca) = config.load_keys()?;
let mut options = config.load_server_options();
let home = home_dir().unwrap();
let mut download_dir = PathBuf::from(home);
download_dir.push(DOWNLOAD_DIR);
let tls_config = TlsConfigBuilder::new()
.ca_file(ca)
@ -61,11 +67,9 @@ pub(crate) async fn run(config: Config) -> Result<()> {
let (reader, mut writer) = split(tls);
let mut reader = BufReader::new(reader);
// let mut writer = BufWriter::new(writer);
let mut filename = download_dir.clone();
tokio::spawn(async move {
let mut filename = PathBuf::from("/home/reyk/Downloads");
// Read and validate the filename
let line = match read_line(&peer_addr, &mut reader).await {
Ok(s) if !(s.contains(MAIN_SEPARATOR) || s.contains('/') || s.contains('\\')) => s,
@ -133,11 +137,7 @@ pub(crate) async fn run(config: Config) -> Result<()> {
.show_with(&zenity)
.expect("Could not display dialog box");
if choice != dialog::Choice::Yes {
info!(
"{} failed: rejected {}",
peer_addr,
filename.display(),
);
info!("{} failed: rejected {}", peer_addr, filename.display(),);
return;
}
}