From 84599e5d8204a8c38220c661e82bd2d9cc4cb112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Tue, 1 Mar 2022 14:40:41 +0100 Subject: [PATCH] cargo fmt --- src/directory_listing.rs | 13 ++++++------- src/main.rs | 3 +-- src/threaded_archiver.rs | 8 ++++---- src/web.rs | 23 ++++++++++++----------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/directory_listing.rs b/src/directory_listing.rs index 57922e3..907dc65 100644 --- a/src/directory_listing.rs +++ b/src/directory_listing.rs @@ -1,10 +1,10 @@ use actix_files::Directory; -use actix_web::{HttpRequest, HttpResponse}; use actix_web::dev::ServiceResponse; -use std::path::Path; +use actix_web::{HttpRequest, HttpResponse}; use percent_encoding::{utf8_percent_encode, CONTROLS}; // NON_ALPHANUMERIC -use v_htmlescape::escape as escape_html_entity; use std::fmt::Write; +use std::path::Path; +use v_htmlescape::escape as escape_html_entity; macro_rules! encode_file_url { ($path:ident) => { @@ -31,9 +31,7 @@ pub fn directory_listing( if dir.is_visible(&entry) { let entry = entry.unwrap(); let p = match entry.path().strip_prefix(&dir.path) { - Ok(p) if cfg!(windows) => { - base.join(p).to_string_lossy().replace("\\", "/") - } + Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace("\\", "/"), Ok(p) => base.join(p).to_string_lossy().into_owned(), Err(_) => continue, }; @@ -66,7 +64,8 @@ pub fn directory_listing( let header = format!( "

Index of {}/

\n\ [.tar of whole directory]", - index_of, if index_of.is_empty() { "_" } else { index_of } + index_of, + if index_of.is_empty() { "_" } else { index_of } ); let footer = format!( diff --git a/src/main.rs b/src/main.rs index 73e5531..ab10c49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ -mod threaded_archiver; mod directory_listing; +mod threaded_archiver; mod web; - #[actix_web::main] async fn main() -> std::io::Result<()> { let app = clap::Command::new(clap::crate_name!()) diff --git a/src/threaded_archiver.rs b/src/threaded_archiver.rs index e6a761e..89bdf05 100644 --- a/src/threaded_archiver.rs +++ b/src/threaded_archiver.rs @@ -13,7 +13,9 @@ type Stream = futures::channel::mpsc::Receiver; type Sender = futures::channel::mpsc::Sender; pub fn stream_tar_in_thread

(path: P) -> Stream - where P: AsRef + Send + 'static { +where + P: AsRef + Send + 'static, +{ let (writer, stream) = StreamWriter::new(64); thread::spawn(move || { @@ -49,9 +51,7 @@ impl io::Write for StreamWriter { } fn flush(&mut self) -> io::Result<()> { - futures::executor::block_on(async move { - self.tx.flush().await.ok() - }); + futures::executor::block_on(async move { self.tx.flush().await.ok() }); Ok(()) } } diff --git a/src/web.rs b/src/web.rs index 3b361c4..593cbab 100644 --- a/src/web.rs +++ b/src/web.rs @@ -1,14 +1,14 @@ -use actix_web::{get, middleware, web, App, Error, HttpServer, HttpRequest, HttpResponse, Responder}; use actix_files::{Files, NamedFile}; +use actix_web::{ + get, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, +}; use futures::StreamExt; use std::path::PathBuf; - pub async fn run(bind_addr: &str, root: &PathBuf) -> std::io::Result<()> { let root_ = root.clone(); let s = HttpServer::new(move || { - let static_files = Files::new("/", &root_) .show_files_listing() .redirect_to_slash_directory() @@ -29,18 +29,20 @@ pub async fn run(bind_addr: &str, root: &PathBuf) -> std::io::Result<()> { } #[get("/{tail:.*}.tar")] -async fn handle_tar(req: HttpRequest, root: web::Data, tail: web::Path) -> impl Responder { +async fn handle_tar( + req: HttpRequest, + root: web::Data, + tail: web::Path, +) -> impl Responder { let relpath = PathBuf::from(tail.trim_end_matches('/')); - let fullpath = root.join(&relpath) - .canonicalize() - .unwrap(); - + let fullpath = root.join(&relpath).canonicalize().unwrap(); // if a .tar already exists, just return it as-is let mut fullpath_tar = fullpath.clone(); fullpath_tar.set_extension("tar"); if fullpath_tar.is_file() { - return NamedFile::open_async(fullpath_tar).await + return NamedFile::open_async(fullpath_tar) + .await .unwrap() .into_response(&req); } @@ -49,8 +51,7 @@ async fn handle_tar(req: HttpRequest, root: web::Data, tail: web::Path< return HttpResponse::NotFound().body("Directory not found\n"); } - let stream = crate::threaded_archiver::stream_tar_in_thread(fullpath) - .map(Ok::<_, Error>); + let stream = crate::threaded_archiver::stream_tar_in_thread(fullpath).map(Ok::<_, Error>); let response = HttpResponse::Ok() .content_type("application/x-tar") .streaming(stream);