From a389db173b8b6f38c8330ddecf00023c72c8ee86 Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Thu, 25 Mar 2021 21:06:08 -0700 Subject: Generate completions with `miniserve --print-completions ` This patch adds a `--print-completions` option to generate shell completion files at runtime. This ensures the completions are always up to date. Fixes #377. --- src/args.rs | 10 ++++++---- src/main.rs | 16 ++++++++++++---- tests/cli.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/args.rs b/src/args.rs index 909a88f..d6cfc69 100644 --- a/src/args.rs +++ b/src/args.rs @@ -21,7 +21,7 @@ const ROUTE_ALPHABET: [char; 16] = [ about, global_settings = &[structopt::clap::AppSettings::ColoredHelp], )] -struct CliArgs { +pub struct CliArgs { /// Be verbose, includes emitting access logs #[structopt(short = "v", long = "verbose")] verbose: bool, @@ -131,6 +131,10 @@ struct CliArgs { /// Hide version footer #[structopt(short = "F", long = "hide-version-footer")] hide_version_footer: bool, + + /// Generate completion file for a shell + #[structopt(long = "print-completions", value_name = "shell")] + pub print_completions: Option, } /// Checks wether an interface is valid, i.e. it can be parsed into an IP address @@ -205,9 +209,7 @@ pub fn parse_header(src: &str) -> Result { } /// Parses the command line arguments -pub fn parse_args() -> crate::MiniserveConfig { - let args = CliArgs::from_args(); - +pub fn parse_args(args: CliArgs) -> crate::MiniserveConfig { let interfaces = if !args.interfaces.is_empty() { args.interfaces } else { diff --git a/src/main.rs b/src/main.rs index 17ab204..747a705 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use std::thread; use std::time::Duration; use structopt::clap::crate_version; +use structopt::StructOpt; use yansi::{Color, Paint}; mod archive; @@ -101,20 +102,27 @@ pub struct MiniserveConfig { } fn main() { - match run() { + let args = args::CliArgs::from_args(); + + if let Some(shell) = args.print_completions { + args::CliArgs::clap().gen_completions_to("miniserve", shell, &mut std::io::stdout()); + return; + } + + let miniserve_config = args::parse_args(args); + + match run(miniserve_config) { Ok(()) => (), Err(e) => errors::log_error_chain(e.to_string()), } } #[actix_web::main(miniserve)] -async fn run() -> Result<(), ContextualError> { +async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { if cfg!(windows) && !Paint::enable_windows_ascii() { Paint::disable(); } - let miniserve_config = args::parse_args(); - let log_level = if miniserve_config.verbose { simplelog::LevelFilter::Info } else { diff --git a/tests/cli.rs b/tests/cli.rs index e09473d..f88b284 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -3,7 +3,7 @@ mod fixtures; use assert_cmd::prelude::*; use fixtures::Error; use std::process::Command; -use structopt::clap::{crate_name, crate_version}; +use structopt::clap::{crate_name, crate_version, Shell}; #[test] /// Show help and exit. @@ -27,3 +27,29 @@ fn version_shows() -> Result<(), Error> { Ok(()) } + +#[test] +/// Print completions and exit. +fn print_completions() -> Result<(), Error> { + for shell in &Shell::variants() { + Command::cargo_bin("miniserve")? + .arg("--print-completions") + .arg(&shell) + .assert() + .success(); + } + + Ok(()) +} + +#[test] +/// Print completions rejects invalid shells. +fn print_completions_invalid_shell() -> Result<(), Error> { + Command::cargo_bin("miniserve")? + .arg("--print-completions") + .arg("fakeshell") + .assert() + .failure(); + + Ok(()) +} -- cgit v1.2.3 From b29d538b8f4fa9568b3bfcf6793724390fd24229 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:08:34 +0200 Subject: Add CHANGELOG entry for shell completions --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a126f26..5a84fb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +- Add `--print-completions` to print shell completions for various supported shells [#482](https://github.com/svenstaro/miniserve/pull/482) (thanks @rouge8) ## [0.12.1] - 2021-03-27 - Fix QR code not showing when using both `--random-route` and `--qrcode` [#480](https://github.com/svenstaro/miniserve/pull/480) (thanks @rouge8) -- cgit v1.2.3 From 26b0a519d226f555674db481f3a3cd2fc52a9961 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:16:39 +0200 Subject: Refactor and separate out arg handling and config handling --- src/args.rs | 107 ++++++++++++------------------------------------------------ src/main.rs | 78 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 91 deletions(-) diff --git a/src/args.rs b/src/args.rs index d6cfc69..169b56f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,7 +1,6 @@ use bytes::Bytes; use http::header::{HeaderMap, HeaderName, HeaderValue}; -use port_check::free_local_port; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::net::IpAddr; use std::path::PathBuf; use structopt::StructOpt; @@ -9,11 +8,6 @@ use crate::auth; use crate::errors::ContextualError; use crate::renderer; -/// Possible characters for random routes -const ROUTE_ALPHABET: [char; 16] = [ - '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', -]; - #[derive(StructOpt)] #[structopt( name = "miniserve", @@ -24,22 +18,22 @@ const ROUTE_ALPHABET: [char; 16] = [ pub struct CliArgs { /// Be verbose, includes emitting access logs #[structopt(short = "v", long = "verbose")] - verbose: bool, + pub verbose: bool, /// Which path to serve #[structopt(name = "PATH", parse(from_os_str))] - path: Option, + pub path: Option, /// The name of a directory index file to serve, like "index.html" /// /// Normally, when miniserve serves a directory, it creates a listing for that directory. /// However, if a directory contains this file, miniserve will serve that file instead. #[structopt(long, parse(from_os_str), name = "index_file")] - index: Option, + pub index: Option, /// Port to use #[structopt(short = "p", long = "port", default_value = "8080")] - port: u16, + pub port: u16, /// Interface to listen on #[structopt( @@ -48,7 +42,7 @@ pub struct CliArgs { parse(try_from_str = parse_interface), number_of_values = 1, )] - interfaces: Vec, + pub interfaces: Vec, /// Set authentication. Currently supported formats: /// username:password, username:sha256:hash, username:sha512:hash @@ -59,19 +53,19 @@ pub struct CliArgs { parse(try_from_str = parse_auth), number_of_values = 1, )] - auth: Vec, + pub auth: Vec, /// Generate a random 6-hexdigit route #[structopt(long = "random-route")] - random_route: bool, + pub random_route: bool, /// Do not follow symbolic links #[structopt(short = "P", long = "no-symlinks")] - no_symlinks: bool, + pub no_symlinks: bool, /// Show hidden files #[structopt(short = "H", long = "hidden")] - hidden: bool, + pub hidden: bool, /// Default color scheme #[structopt( @@ -81,7 +75,7 @@ pub struct CliArgs { possible_values = &renderer::THEME_SLUGS, case_insensitive = true, )] - color_scheme: String, + pub color_scheme: String, /// Default color scheme #[structopt( @@ -91,46 +85,46 @@ pub struct CliArgs { possible_values = &renderer::THEME_SLUGS, case_insensitive = true, )] - color_scheme_dark: String, + pub color_scheme_dark: String, /// Enable QR code display #[structopt(short = "q", long = "qrcode")] - qrcode: bool, + pub qrcode: bool, /// Enable file uploading #[structopt(short = "u", long = "upload-files")] - file_upload: bool, + pub file_upload: bool, /// Enable overriding existing files during file upload #[structopt(short = "o", long = "overwrite-files")] - overwrite_files: bool, + pub overwrite_files: bool, /// Enable tar archive generation #[structopt(short = "r", long = "enable-tar")] - enable_tar: bool, + pub enable_tar: bool, /// Enable zip archive generation /// /// WARNING: Zipping large directories can result in out-of-memory exception /// because zip generation is done in memory and cannot be sent on the fly #[structopt(short = "z", long = "enable-zip")] - enable_zip: bool, + pub enable_zip: bool, /// List directories first #[structopt(short = "D", long = "dirs-first")] - dirs_first: bool, + pub dirs_first: bool, /// Shown instead of host in page title and heading #[structopt(short = "t", long = "title")] - title: Option, + pub title: Option, /// Set custom header for responses #[structopt(long = "header", parse(try_from_str = parse_header), number_of_values = 1)] - header: Vec, + pub header: Vec, /// Hide version footer #[structopt(short = "F", long = "hide-version-footer")] - hide_version_footer: bool, + pub hide_version_footer: bool, /// Generate completion file for a shell #[structopt(long = "print-completions", value_name = "shell")] @@ -208,65 +202,6 @@ pub fn parse_header(src: &str) -> Result { Ok(header_map) } -/// Parses the command line arguments -pub fn parse_args(args: CliArgs) -> crate::MiniserveConfig { - let interfaces = if !args.interfaces.is_empty() { - args.interfaces - } else { - vec![ - IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), - IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), - ] - }; - - let random_route = if args.random_route { - Some(nanoid::nanoid!(6, &ROUTE_ALPHABET)) - } else { - None - }; - - // Generate some random routes for the favicon and css so that they are very unlikely to conflict with - // real files. - let favicon_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); - let css_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); - - let default_color_scheme = args.color_scheme; - let default_color_scheme_dark = args.color_scheme_dark; - - let path_explicitly_chosen = args.path.is_some() || args.index.is_some(); - - let port = match args.port { - 0 => free_local_port().expect("no free ports available"), - _ => args.port, - }; - - crate::MiniserveConfig { - verbose: args.verbose, - path: args.path.unwrap_or_else(|| PathBuf::from(".")), - port, - interfaces, - auth: args.auth, - path_explicitly_chosen, - no_symlinks: args.no_symlinks, - show_hidden: args.hidden, - random_route, - favicon_route, - css_route, - default_color_scheme, - default_color_scheme_dark, - index: args.index, - overwrite_files: args.overwrite_files, - show_qrcode: args.qrcode, - file_upload: args.file_upload, - tar_enabled: args.enable_tar, - zip_enabled: args.enable_zip, - dirs_first: args.dirs_first, - title: args.title, - header: args.header, - hide_version_footer: args.hide_version_footer, - } -} - #[rustfmt::skip] #[cfg(test)] mod tests { diff --git a/src/main.rs b/src/main.rs index 747a705..a6410a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,9 @@ +use std::io; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::thread; +use std::time::Duration; +use std::{io::Write, path::PathBuf}; + use actix_web::web; use actix_web::{ http::{header::ContentType, StatusCode}, @@ -6,10 +12,6 @@ use actix_web::{ use actix_web::{middleware, App, HttpRequest, HttpResponse}; use actix_web_httpauth::middleware::HttpAuthentication; use http::header::HeaderMap; -use std::io::{self, Write}; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use std::thread; -use std::time::Duration; use structopt::clap::crate_version; use structopt::StructOpt; use yansi::{Color, Paint}; @@ -25,6 +27,11 @@ mod renderer; use crate::errors::ContextualError; +/// Possible characters for random routes +const ROUTE_ALPHABET: [char; 16] = [ + '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', +]; + #[derive(Clone)] /// Configuration of the Miniserve application pub struct MiniserveConfig { @@ -101,6 +108,67 @@ pub struct MiniserveConfig { pub hide_version_footer: bool, } +impl MiniserveConfig { + /// Parses the command line arguments + fn from_args(args: args::CliArgs) -> Self { + let interfaces = if !args.interfaces.is_empty() { + args.interfaces + } else { + vec![ + IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), + IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), + ] + }; + + let random_route = if args.random_route { + Some(nanoid::nanoid!(6, &ROUTE_ALPHABET)) + } else { + None + }; + + // Generate some random routes for the favicon and css so that they are very unlikely to conflict with + // real files. + let favicon_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); + let css_route = nanoid::nanoid!(10, &ROUTE_ALPHABET); + + let default_color_scheme = args.color_scheme; + let default_color_scheme_dark = args.color_scheme_dark; + + let path_explicitly_chosen = args.path.is_some() || args.index.is_some(); + + let port = match args.port { + 0 => port_check::free_local_port().expect("no free ports available"), + _ => args.port, + }; + + crate::MiniserveConfig { + verbose: args.verbose, + path: args.path.unwrap_or_else(|| PathBuf::from(".")), + port, + interfaces, + auth: args.auth, + path_explicitly_chosen, + no_symlinks: args.no_symlinks, + show_hidden: args.hidden, + random_route, + favicon_route, + css_route, + default_color_scheme, + default_color_scheme_dark, + index: args.index, + overwrite_files: args.overwrite_files, + show_qrcode: args.qrcode, + file_upload: args.file_upload, + tar_enabled: args.enable_tar, + zip_enabled: args.enable_zip, + dirs_first: args.dirs_first, + title: args.title, + header: args.header, + hide_version_footer: args.hide_version_footer, + } + } +} + fn main() { let args = args::CliArgs::from_args(); @@ -109,7 +177,7 @@ fn main() { return; } - let miniserve_config = args::parse_args(args); + let miniserve_config = MiniserveConfig::from_args(args); match run(miniserve_config) { Ok(()) => (), -- cgit v1.2.3 From 531c9e0351035b23ae0c6088807358338c20b974 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:19:27 +0200 Subject: Print supported shells for completions in help command --- src/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/args.rs b/src/args.rs index 169b56f..81e49dc 100644 --- a/src/args.rs +++ b/src/args.rs @@ -127,7 +127,7 @@ pub struct CliArgs { pub hide_version_footer: bool, /// Generate completion file for a shell - #[structopt(long = "print-completions", value_name = "shell")] + #[structopt(long = "print-completions", value_name = "shell", possible_values = &structopt::clap::Shell::variants())] pub print_completions: Option, } -- cgit v1.2.3 From dfe2b2460c33794ca91cf614cd4ead1382a1199a Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:28:20 +0200 Subject: Better message for when provided index file doesn't exist --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index a6410a6..8f29dc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use actix_web::{ use actix_web::{middleware, App, HttpRequest, HttpResponse}; use actix_web_httpauth::middleware::HttpAuthentication; use http::header::HeaderMap; +use log::error; use structopt::clap::crate_version; use structopt::StructOpt; use yansi::{Color, Paint}; @@ -251,9 +252,9 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { if let Some(index_path) = &miniserve_config.index { let has_index: std::path::PathBuf = [&canon_path, index_path].iter().collect(); if !has_index.exists() { - println!( - "{warning} The provided index file could not be found.", - warning = Color::RGB(255, 192, 0).paint("Notice:").bold() + error!( + "The file '{}' provided for option --index could not be found.", + index_path.to_string_lossy() ); } } -- cgit v1.2.3 From 31b5b9faf3cacb68d89fb2509368e472636a9cb4 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:30:29 +0200 Subject: Change default log level to Warn --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8f29dc6..1b896da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,7 +195,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { let log_level = if miniserve_config.verbose { simplelog::LevelFilter::Info } else { - simplelog::LevelFilter::Error + simplelog::LevelFilter::Warn }; if simplelog::TermLogger::init( -- cgit v1.2.3 From d1f1ff93c7d667614bf50e877eb1eef7eed9132a Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:44:52 +0200 Subject: Fix tests --- tests/serve_request.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/serve_request.rs b/tests/serve_request.rs index 95449f5..6477bc2 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -185,17 +185,18 @@ fn serves_requests_custom_index_notice(tmpdir: TempDir, port: u16) -> Result<(), .arg(port.to_string()) .arg(tmpdir.path()) .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn()?; sleep(Duration::from_secs(1)); child.kill()?; let output = child.wait_with_output().expect("Failed to read stdout"); - let all_text = String::from_utf8(output.stdout); + let all_text = String::from_utf8(output.stderr); assert!(all_text .unwrap() - .contains("The provided index file could not be found")); + .contains("The file 'not.html' provided for option --index could not be found.")); Ok(()) } -- cgit v1.2.3 From 3c5a2de4308975af2ba3a831b638705c424fd2f8 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:46:06 +0200 Subject: Change start message without arguments to be a bit more clear --- CHANGELOG.md | 2 ++ src/main.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a84fb2..09479d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +- Change default log level to `Warn` +- Change start messages a bit to be more clear - Add `--print-completions` to print shell completions for various supported shells [#482](https://github.com/svenstaro/miniserve/pull/482) (thanks @rouge8) ## [0.12.1] - 2021-03-27 diff --git a/src/main.rs b/src/main.rs index 1b896da..5fadb07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use actix_web::{ use actix_web::{middleware, App, HttpRequest, HttpResponse}; use actix_web_httpauth::middleware::HttpAuthentication; use http::header::HeaderMap; -use log::error; +use log::{error, warn}; use structopt::clap::crate_version; use structopt::StructOpt; use yansi::{Color, Paint}; @@ -266,9 +266,9 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { version = crate_version!() ); if !miniserve_config.path_explicitly_chosen { - println!("{warning} miniserve has been invoked without an explicit path so it will serve the current directory.", warning=Color::RGB(255, 192, 0).paint("Notice:").bold()); - println!( - " Invoke with -h|--help to see options or invoke as `miniserve .` to hide this advice." + warn!("miniserve has been invoked without an explicit path so it will serve the current directory after a short delay."); + warn!( + "Invoke with -h|--help to see options or invoke as `miniserve .` to hide this advice." ); print!("Starting server in "); io::stdout() -- cgit v1.2.3 From 906af1587144dd4b3caecacdff5ea834012cffa4 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 22:41:07 +0200 Subject: Refuse to start without explicit path if not attached to interactive terminal --- CHANGELOG.md | 7 ++++++- Cargo.lock | 1 + Cargo.toml | 1 + src/archive.rs | 27 ++++++++++++++++++--------- src/errors.rs | 52 +++++++++++++++++++++++++++++----------------------- src/file_upload.rs | 4 +--- src/main.rs | 16 +++++++++++++--- 7 files changed, 69 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09479d2..f58c1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate - Change default log level to `Warn` -- Change start messages a bit to be more clear +- Change some messages a bit to be more clear - Add `--print-completions` to print shell completions for various supported shells [#482](https://github.com/svenstaro/miniserve/pull/482) (thanks @rouge8) +- Don't print some messages if not attached to an interactive terminal +- Refuse to start if not attached to interactive terminal and no explicit path is provided + + This is a security consideration as you wouldn't want to run miniserve without an explicit path + as a service. You could end up serving `/` or `/root` in case those working directories are set. ## [0.12.1] - 2021-03-27 - Fix QR code not showing when using both `--random-route` and `--qrcode` [#480](https://github.com/svenstaro/miniserve/pull/480) (thanks @rouge8) diff --git a/Cargo.lock b/Cargo.lock index df4bb1d..2656398 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1522,6 +1522,7 @@ dependencies = [ "alphanumeric-sort", "assert_cmd", "assert_fs", + "atty", "bytes 1.0.1", "bytesize", "chrono", diff --git a/Cargo.toml b/Cargo.toml index d02617e..56ccd1e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ mime = "0.3" httparse = "1" http = "0.2.3" bytes = "1" +atty = "0.2" [dev-dependencies] assert_cmd = "1" diff --git a/src/archive.rs b/src/archive.rs index 894ee3f..4df3a31 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -220,15 +220,18 @@ where let mut buffer = Vec::new(); while !paths_queue.is_empty() { let next = paths_queue.pop().ok_or_else(|| { - ContextualError::CustomError("Could not get path from queue".to_string()) + ContextualError::ArchiveCreationDetailError("Could not get path from queue".to_string()) })?; let current_dir = next.as_path(); let directory_entry_iterator = std::fs::read_dir(current_dir) .map_err(|e| ContextualError::IoError("Could not read directory".to_string(), e))?; - let zip_directory = - Path::new(zip_root_folder_name).join(current_dir.strip_prefix(directory).map_err( - |_| ContextualError::CustomError("Could not append base directory".to_string()), - )?); + let zip_directory = Path::new(zip_root_folder_name).join( + current_dir.strip_prefix(directory).map_err(|_| { + ContextualError::ArchiveCreationDetailError( + "Could not append base directory".to_string(), + ) + })?, + ); for entry in directory_entry_iterator { let entry_path = entry @@ -259,10 +262,14 @@ where zip_writer .start_file(relative_path.to_string_lossy(), options) .map_err(|_| { - ContextualError::CustomError("Could not add file path to ZIP".to_string()) + ContextualError::ArchiveCreationDetailError( + "Could not add file path to ZIP".to_string(), + ) })?; zip_writer.write(buffer.as_ref()).map_err(|_| { - ContextualError::CustomError("Could not write file to ZIP".to_string()) + ContextualError::ArchiveCreationDetailError( + "Could not write file to ZIP".to_string(), + ) })?; buffer.clear(); } else if entry_metadata.is_dir() { @@ -270,7 +277,7 @@ where zip_writer .add_directory(relative_path.to_string_lossy(), options) .map_err(|_| { - ContextualError::CustomError( + ContextualError::ArchiveCreationDetailError( "Could not add directory path to ZIP".to_string(), ) })?; @@ -280,7 +287,9 @@ where } zip_writer.finish().map_err(|_| { - ContextualError::CustomError("Could not finish writing ZIP archive".to_string()) + ContextualError::ArchiveCreationDetailError( + "Could not finish writing ZIP archive".to_string(), + ) })?; Ok(()) } diff --git a/src/errors.rs b/src/errors.rs index 3287fc3..f079657 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,65 +2,78 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum ContextualError { - /// Fully customized errors, not inheriting from any error - #[error("{0}")] - CustomError(String), - /// Any kind of IO errors #[error("{0}\ncaused by: {1}")] IoError(String, std::io::Error), - /// MultipartError, which might occur during file upload, when processing the multipart request fails + /// Might occur during file upload, when processing the multipart request fails #[error("Failed to process multipart request\ncaused by: {0}")] MultipartError(actix_multipart::MultipartError), + /// Might occur during file upload + #[error("File already exists, and the overwrite_files option has not been set")] + DuplicateFileError, + /// Any error related to an invalid path (failed to retrieve entry name, unexpected entry type, etc) #[error("Invalid path\ncaused by: {0}")] InvalidPathError(String), - /// This error might occur if the HTTP credential string does not respect the expected format + /// Might occur if the HTTP credential string does not respect the expected format #[error("Invalid format for credentials string. Expected username:password, username:sha256:hash or username:sha512:hash")] InvalidAuthFormat, - /// This error might occure if the hash method is neither sha256 nor sha512 + /// Might occure if the hash method is neither sha256 nor sha512 #[error("{0} is not a valid hashing method. Expected sha256 or sha512")] InvalidHashMethod(String), - /// This error might occur if the HTTP auth hash password is not a valid hex code + /// Might occur if the HTTP auth hash password is not a valid hex code #[error("Invalid format for password hash. Expected hex code")] InvalidPasswordHash, - /// This error might occur if the HTTP auth password exceeds 255 characters + /// Might occur if the HTTP auth password exceeds 255 characters #[error("HTTP password length exceeds 255 characters")] PasswordTooLongError, - /// This error might occur if the user has unsufficient permissions to create an entry in a given directory + /// Might occur if the user has unsufficient permissions to create an entry in a given directory #[error("Insufficient permissions to create file in {0}")] InsufficientPermissionsError(String), - /// Any error related to parsing. + /// Any error related to parsing #[error("Failed to parse {0}\ncaused by: {1}")] ParseError(String, String), - /// This error might occur when the creation of an archive fails + /// Might occur when the creation of an archive fails #[error("An error occured while creating the {0}\ncaused by: {1}")] ArchiveCreationError(String, Box), - /// This error might occur when the HTTP authentication fails + /// More specific archive creation failure reason + #[error("{0}")] + ArchiveCreationDetailError(String), + + /// Might occur when the HTTP authentication fails #[error("An error occured during HTTP authentication\ncaused by: {0}")] HttpAuthenticationError(Box), - /// This error might occur when the HTTP credentials are not correct + /// Might occur when the HTTP credentials are not correct #[error("Invalid credentials for HTTP authentication")] InvalidHttpCredentials, - /// This error might occur when an HTTP request is invalid + /// Might occur when an HTTP request is invalid #[error("Invalid HTTP request\ncaused by: {0}")] InvalidHttpRequestError(String), - /// This error might occur when trying to access a page that does not exist + /// Might occur when trying to access a page that does not exist #[error("Route {0} could not be found")] RouteNotFoundError(String), + + /// In case miniserve was invoked without an interactive terminal and without an explicit path + #[error("Refusing to start as no explicit serve path was set and no interactive terminal was attached +Please set an explicit serve path like: `miniserve /my/path`")] + NoExplicitPathAndNoTerminal, + + /// In case miniserve was invoked with --no-symlinks but the serve path is a symlink + #[error("The -P|--no-symlinks option was provided but the serve path '{0}' is a symlink")] + NoSymlinksOptionWithSymlinkServePath(String), } pub fn log_error_chain(description: String) { @@ -68,10 +81,3 @@ pub fn log_error_chain(description: String) { log::error!("{}", cause); } } - -/// This makes creating CustomErrors easier -impl From for ContextualError { - fn from(msg: String) -> ContextualError { - ContextualError::CustomError(msg) - } -} diff --git a/src/file_upload.rs b/src/file_upload.rs index 785d72f..93b7109 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -20,9 +20,7 @@ fn save_file( overwrite_files: bool, ) -> Pin>>> { if !overwrite_files && file_path.exists() { - return Box::pin(future::err(ContextualError::CustomError( - "File already exists, and the overwrite_files option has not been set".to_string(), - ))); + return Box::pin(future::err(ContextualError::DuplicateFileError)); } let mut file = match std::fs::File::create(&file_path) { diff --git a/src/main.rs b/src/main.rs index 5fadb07..7cd4d3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,8 +220,8 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { .is_symlink(); if is_symlink { - return Err(ContextualError::from( - "The no-symlinks option cannot be used with a symlink path".to_string(), + return Err(ContextualError::NoSymlinksOptionWithSymlinkServePath( + miniserve_config.path.to_string_lossy().to_string(), )); } } @@ -266,6 +266,14 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { version = crate_version!() ); if !miniserve_config.path_explicitly_chosen { + // If the path to serve has NOT been explicitly chosen and if this is NOT an interactive + // terminal, we should refuse to start for security reasons. This would be the case when + // running miniserve as a service but forgetting to set the path. This could be pretty + // dangerous if given with an undesired context path (for instance /root or /). + if !atty::is(atty::Stream::Stdout) { + return Err(ContextualError::NoExplicitPathAndNoTerminal); + } + warn!("miniserve has been invoked without an explicit path so it will serve the current directory after a short delay."); warn!( "Invoke with -h|--help to see options or invoke as `miniserve .` to hide this advice." @@ -361,7 +369,9 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { addresses = addresses, ); - println!("\nQuit by pressing CTRL-C"); + if atty::is(atty::Stream::Stdout) { + println!("\nQuit by pressing CTRL-C"); + } srv.await .map_err(|e| ContextualError::IoError("".to_owned(), e)) -- cgit v1.2.3 From 9b278a471a7c9f0587ee421335a2f675afe90eb7 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 22:46:32 +0200 Subject: Bump deps --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- src/main.rs | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2656398..028ea33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project 0.4.27", + "pin-project 0.4.28", "tokio 0.2.25", "tokio-util 0.3.1", ] @@ -187,7 +187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb" dependencies = [ "futures-util", - "pin-project 0.4.27", + "pin-project 0.4.28", ] [[package]] @@ -247,7 +247,7 @@ dependencies = [ "futures-sink", "futures-util", "log", - "pin-project 0.4.27", + "pin-project 0.4.28", "slab", ] @@ -663,9 +663,9 @@ checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" [[package]] name = "const_fn" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" +checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" [[package]] name = "convert_case" @@ -1860,11 +1860,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f" dependencies = [ - "pin-project-internal 0.4.27", + "pin-project-internal 0.4.28", ] [[package]] @@ -1878,9 +1878,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e" dependencies = [ "proc-macro2", "quote", @@ -2569,9 +2569,9 @@ dependencies = [ [[package]] name = "simplelog" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc0ffd69814a9b251d43afcabf96dad1b29f5028378056257be9e3fecc9f720" +checksum = "59d0fe306a0ced1c88a58042dc22fc2ddd000982c26d75f6aa09a394547c41e0" dependencies = [ "chrono", "log", diff --git a/Cargo.toml b/Cargo.toml index 56ccd1e..2bc1481 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ panic = 'abort' [dependencies] yansi = "0.5" actix-web = "3" -simplelog = "0.9" +simplelog = "0.10" percent-encoding = "2" port_check = "0.1" bytesize = "1.0.0" diff --git a/src/main.rs b/src/main.rs index 7cd4d3e..84a4cb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,6 +202,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> { log_level, simplelog::Config::default(), simplelog::TerminalMode::Mixed, + simplelog::ColorChoice::Auto, ) .is_err() { -- cgit v1.2.3 From 4f060be689942f4b9b226e997da6a678f05d5442 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 22:52:12 +0200 Subject: Don't explicitly specify all the patch versions This should in theory allow us to have more overlaps between sub-dependencies and thus reduce binary size. --- Cargo.lock | 17 ++++++++--------- Cargo.toml | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 028ea33..8b37154 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,7 +618,7 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time 0.1.44", + "time 0.1.43", "winapi 0.3.9", ] @@ -1009,7 +1009,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -2859,12 +2859,11 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", "winapi 0.3.9", ] @@ -3268,9 +3267,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" @@ -3464,7 +3463,7 @@ dependencies = [ "log", "mac", "markup5ever", - "time 0.1.44", + "time 0.1.43", ] [[package]] @@ -3484,5 +3483,5 @@ dependencies = [ "crc32fast", "flate2", "thiserror", - "time 0.1.44", + "time 0.1.43", ] diff --git a/Cargo.toml b/Cargo.toml index 2bc1481..0c685c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,31 +22,31 @@ actix-web = "3" simplelog = "0.10" percent-encoding = "2" port_check = "0.1" -bytesize = "1.0.0" +bytesize = "1" nanoid = "0.3" alphanumeric-sort = "1" structopt = "0.3" -chrono = "0.4.19" -chrono-humanize = "0.1.2" -maud = { version = "0.22.2", features = ["actix-web"] } +chrono = "0.4" +chrono-humanize = "0.1" +maud = { version = "0.22", features = ["actix-web"] } serde = { version = "1", features = ["derive"] } -tar = "0.4.33" -futures = "0.3.13" +tar = "0.4" +futures = "0.3" libflate = "1" thiserror = "1" -log = "0.4.14" -strum = "0.20.0" -strum_macros = "0.20.1" +log = "0.4" +strum = "0.20" +strum_macros = "0.20" sha2 = "0.9" -hex = "0.4.3" +hex = "0.4" zip = "0.5.11" qrcodegen = "1" actix-files = "0.5" -actix-multipart = "0.3.0" -actix-web-httpauth = "0.5.1" +actix-multipart = "0.3" +actix-web-httpauth = "0.5" mime = "0.3" httparse = "1" -http = "0.2.3" +http = "0.2" bytes = "1" atty = "0.2" @@ -61,4 +61,4 @@ pretty_assertions = "0.7" url = "2" [build-dependencies] -grass = "0.10.4" +grass = "0.10" -- cgit v1.2.3 From 8bdc098f0bd53ca2f5fe98fa90d61b3f68273f96 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 22:54:46 +0200 Subject: Update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9e1eb7e..714f260 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,9 @@ Sometimes this is just a more practical and quick way than doing things properly -p, --port Port to use [default: 8080] + --print-completions + Generate completion file for a shell [possible values: zsh, bash, fish, + powershell, elvish] -t, --title Shown instead of host in page title and heading -- cgit v1.2.3 From d7d985037f19263abd5b5861757cc94fee1989ad Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 28 Mar 2021 23:14:41 +0200 Subject: Update features list --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 714f260..9796886 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,10 @@ Sometimes this is just a more practical and quick way than doing things properly - Mega fast and highly parallel (thanks to [Rust](https://www.rust-lang.org/) and [Actix](https://actix.rs/)) - Folder download (compressed on the fly as `.tar.gz` or `.zip`) - File uploading -- Pretty themes +- Pretty themes (with light and dark theme support) - Scan QR code for quick access +- Shell completions +- Sane and secure defaults ## Usage -- cgit v1.2.3 From b0a84c74ddbd50f760a002e470cfdb815a1bdd1a Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 28 Mar 2021 23:15:23 +0200 Subject: Add README instructions for using shell completions --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 9796886..5503f4d 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,19 @@ Alternatively install with [Homebrew](https://brew.sh/). docker run -v /tmp:/tmp -p 8080:8080 --rm -it svenstaro/miniserve /tmp +## Shell completions + +If you'd like to make use of the built-in shell completion support, you need to run `miniserve +--print-completions <your-shell>` and put the completions in the correct place for your shell. A +few examples with common paths are provided below: + + # For bash + miniserve --print-completions bash > ~/.local/share/bash-completion/miniserve + # For zsh + miniserve --print-completions zsh > /usr/local/share/zsh/site-functions/_miniserve + # For fish + miniserve --print-completions fish > ~/.config/fish/completions/miniserve.fish + ## Binding behavior For convenience reasons, miniserve will try to bind on all interfaces by default (if no `-i` is provided). -- cgit v1.2.3 From ae54ca44f52651e5931641aba1a5074218905c96 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 28 Mar 2021 23:16:22 +0200 Subject: (cargo-release) version 0.13.0 --- CHANGELOG.md | 5 ++++- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f58c1c6..693ff97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). <!-- next-header --> ## [Unreleased] - ReleaseDate + +## [0.13.0] - 2021-03-28 - Change default log level to `Warn` - Change some messages a bit to be more clear - Add `--print-completions` to print shell completions for various supported shells [#482](https://github.com/svenstaro/miniserve/pull/482) (thanks @rouge8) @@ -81,7 +83,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Some theme related bug fixes (thanks @boastful-squirrel) <!-- next-url --> -[Unreleased]: https://github.com/svenstaro/miniserve/compare/v0.12.1...HEAD +[Unreleased]: https://github.com/svenstaro/miniserve/compare/v0.13.0...HEAD +[0.13.0]: https://github.com/svenstaro/miniserve/compare/v0.12.1...v0.13.0 [0.12.1]: https://github.com/svenstaro/miniserve/compare/v0.12.0...v0.12.1 [0.12.0]: https://github.com/svenstaro/miniserve/compare/v0.11.0...v0.12.0 [0.11.0]: https://github.com/svenstaro/miniserve/compare/v0.10.4...v0.11.0 diff --git a/Cargo.lock b/Cargo.lock index 8b37154..9d4b63a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1513,7 +1513,7 @@ dependencies = [ [[package]] name = "miniserve" -version = "0.12.2-alpha.0" +version = "0.13.0" dependencies = [ "actix-files", "actix-multipart", diff --git a/Cargo.toml b/Cargo.toml index 0c685c5..f2e54bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miniserve" -version = "0.12.2-alpha.0" +version = "0.13.0" description = "For when you really just want to serve some files over HTTP right now!" authors = ["Sven-Hendrik Haase <svenstaro@gmail.com>", "Boastful Squirrel <boastful.squirrel@gmail.com>"] repository = "https://github.com/svenstaro/miniserve" diff --git a/README.md b/README.md index 5503f4d..0ad41a0 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Sometimes this is just a more practical and quick way than doing things properly ## Usage - miniserve 0.12.1 + miniserve 0.13.0 Sven-Hendrik Haase <svenstaro@gmail.com>, Boastful Squirrel <boastful.squirrel@gmail.com> For when you really just want to serve some files over HTTP right now! -- cgit v1.2.3 From 4719779182d6dcec2f3134436b57a9f0832a4a20 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 28 Mar 2021 23:17:00 +0200 Subject: (cargo-release) start next development iteration 0.13.1-alpha.0 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d4b63a..55dbfc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1513,7 +1513,7 @@ dependencies = [ [[package]] name = "miniserve" -version = "0.13.0" +version = "0.13.1-alpha.0" dependencies = [ "actix-files", "actix-multipart", diff --git a/Cargo.toml b/Cargo.toml index f2e54bc..1a5f83e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "miniserve" -version = "0.13.0" +version = "0.13.1-alpha.0" description = "For when you really just want to serve some files over HTTP right now!" authors = ["Sven-Hendrik Haase <svenstaro@gmail.com>", "Boastful Squirrel <boastful.squirrel@gmail.com>"] repository = "https://github.com/svenstaro/miniserve" -- cgit v1.2.3 From 62a20725ed6c64f301800deba1fae575fc7873fb Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Tue, 30 Mar 2021 01:59:57 +0200 Subject: Bump deps --- Cargo.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55dbfc1..353d394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1316,9 +1316,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "js-sys" -version = "0.3.49" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821" +checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" dependencies = [ "wasm-bindgen", ] @@ -2756,9 +2756,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.65" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663" +checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" dependencies = [ "proc-macro2", "quote", @@ -3273,9 +3273,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe" +checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" dependencies = [ "cfg-if 1.0.0", "serde", @@ -3285,9 +3285,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" +checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" dependencies = [ "bumpalo", "lazy_static", @@ -3300,9 +3300,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468" +checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3312,9 +3312,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b" +checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3322,9 +3322,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d" +checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" dependencies = [ "proc-macro2", "quote", @@ -3335,15 +3335,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa" +checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" [[package]] name = "web-sys" -version = "0.3.49" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310" +checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" dependencies = [ "js-sys", "wasm-bindgen", -- cgit v1.2.3 From dd6ca41fcaa1f67875dbe3e9c6a047813075e391 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Tue, 6 Apr 2021 20:15:04 +0300 Subject: Fix percent encoding for URL Use proper percent-encoding charset for each context. --- src/listing.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/listing.rs b/src/listing.rs index 66aea6b..2a62fd6 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -4,7 +4,7 @@ use actix_web::http::StatusCode; use actix_web::web::Query; use actix_web::{HttpRequest, HttpResponse, Result}; use bytesize::ByteSize; -use percent_encoding::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS}; +use percent_encoding::{percent_decode_str, utf8_percent_encode}; use qrcodegen::{QrCode, QrCodeEcc}; use serde::Deserialize; use std::io; @@ -15,8 +15,17 @@ use strum_macros::{Display, EnumString}; use crate::archive::CompressionMethod; use crate::errors::{self, ContextualError}; use crate::renderer; - -const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`'); +use percent_encode_sets::{PATH, PATH_SEGMENT}; + +/// "percent-encode sets" as defined by WHATWG specs: +/// https://url.spec.whatwg.org/#percent-encoded-bytes +mod percent_encode_sets { + use percent_encoding::{AsciiSet, CONTROLS}; + const BASE: &AsciiSet = &CONTROLS.add(b'%'); + pub const QUERY: &AsciiSet = &BASE.add(b' ').add(b'"').add(b'#').add(b'<').add(b'>'); + pub const PATH: &AsciiSet = &QUERY.add(b'?').add(b'`').add(b'{').add(b'}'); + pub const PATH_SEGMENT: &AsciiSet = &PATH.add(b'/'); +} /// Query parameters #[derive(Deserialize)] @@ -213,7 +222,7 @@ pub fn directory_listing( Component::Normal(s) => { name = s.to_string_lossy().to_string(); link_accumulator - .push_str(&(utf8_percent_encode(&name, FRAGMENT).to_string() + "/")); + .push_str(&(utf8_percent_encode(&name, PATH_SEGMENT).to_string() + "/")); } _ => name = "".to_string(), }; @@ -256,7 +265,7 @@ pub fn directory_listing( Err(_) => continue, }; // show file url as relative to static path - let file_url = utf8_percent_encode(&p.to_string_lossy(), FRAGMENT).to_string(); + let file_url = utf8_percent_encode(&p.to_string_lossy(), PATH).to_string(); let file_name = entry.file_name().to_string_lossy().to_string(); // if file is a directory, add '/' to the end of the name -- cgit v1.2.3 From 58f40d8314821624ab55aa45493cedd407ee0376 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Tue, 6 Apr 2021 20:16:59 +0300 Subject: Test URL encoding for special characters --- tests/fixtures/mod.rs | 3 +++ tests/serve_request.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index 7efbe5e..1cf6c59 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -16,6 +16,9 @@ pub static FILES: &[&str] = &[ "test \" \' & < >.csv", "😀.data", "⎙.mp4", + "#[]{}()@!$&'`+,;= %20.test", + #[cfg(unix)] + ":?#[]{}<>()@!$&'`|*+,;= %20.test", ]; /// Hidden files for testing purpose diff --git a/tests/serve_request.rs b/tests/serve_request.rs index 6477bc2..25c5574 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -49,6 +49,12 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( for &file in FILES { let f = parsed.find(|x: &Node| x.text() == file).next().unwrap(); + reqwest::blocking::get(format!( + "http://localhost:{}/{}", + port, + f.attr("href").unwrap() + ))? + .error_for_status()?; assert_eq!( format!("/{}", file), percent_encoding::percent_decode_str(f.attr("href").unwrap()).decode_utf8_lossy(), -- cgit v1.2.3 From fd50bff64652767ceef08c3fdcfdc53def1111c7 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 7 Apr 2021 04:16:30 +0000 Subject: Bump nanoid from 0.3.0 to 0.4.0 Bumps [nanoid](https://github.com/nikolay-govorov/nanoid) from 0.3.0 to 0.4.0. - [Release notes](https://github.com/nikolay-govorov/nanoid/releases) - [Changelog](https://github.com/nikolay-govorov/nanoid/blob/master/CHANGELOG.md) - [Commits](https://github.com/nikolay-govorov/nanoid/compare/v0.3.0...v0.4.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 160 +++++-------------------------------------------------------- Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 149 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 353d394..ecbb868 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,12 +407,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.1" @@ -646,15 +640,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "codemap" version = "0.1.3" @@ -711,7 +696,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ - "autocfg 1.0.1", + "autocfg", "cfg-if 1.0.0", "lazy_static", ] @@ -847,12 +832,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -1102,7 +1081,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" dependencies = [ "ahash", - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -1268,7 +1247,7 @@ version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown 0.9.1", ] @@ -1633,11 +1612,11 @@ dependencies = [ [[package]] name = "nanoid" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" +checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8" dependencies = [ - "rand 0.6.5", + "rand 0.8.3", ] [[package]] @@ -1688,7 +1667,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d0a3d5e207573f948a9e5376662aa743a2ea13f7c50a554d7af443a73fbfeba" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] @@ -1699,7 +1678,7 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] @@ -1709,7 +1688,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-bigint", "num-integer", "num-traits", @@ -1721,7 +1700,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -2047,25 +2026,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg 0.1.2", - "rand_xorshift", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" @@ -2077,7 +2037,7 @@ dependencies = [ "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc 0.2.0", - "rand_pcg 0.2.1", + "rand_pcg", ] [[package]] @@ -2092,16 +2052,6 @@ dependencies = [ "rand_hc 0.3.0", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -2122,21 +2072,6 @@ dependencies = [ "rand_core 0.6.2", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2155,15 +2090,6 @@ dependencies = [ "getrandom 0.2.2", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -2182,50 +2108,6 @@ dependencies = [ "rand_core 0.6.2", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - [[package]] name = "rand_pcg" version = "0.2.1" @@ -2235,24 +2117,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.5" @@ -2946,7 +2810,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" dependencies = [ - "autocfg 1.0.1", + "autocfg", "bytes 1.0.1", "libc", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 1a5f83e..0a73dc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ simplelog = "0.10" percent-encoding = "2" port_check = "0.1" bytesize = "1" -nanoid = "0.3" +nanoid = "0.4" alphanumeric-sort = "1" structopt = "0.3" chrono = "0.4" -- cgit v1.2.3 From c770b671faccb862304dc594f31bfd88f4c71973 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 04:14:50 +0000 Subject: Bump httparse from 1.3.5 to 1.3.6 Bumps [httparse](https://github.com/seanmonstar/httparse) from 1.3.5 to 1.3.6. - [Release notes](https://github.com/seanmonstar/httparse/releases) - [Commits](https://github.com/seanmonstar/httparse/compare/v1.3.5...v1.3.6) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecbb868..7952a18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1163,9 +1163,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.5" +version = "1.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" +checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" [[package]] name = "httpdate" -- cgit v1.2.3 From 3550168a0185a26274b3d7ff132182b13779ca3e Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 8 Apr 2021 04:15:16 +0000 Subject: Bump http from 0.2.3 to 0.2.4 Bumps [http](https://github.com/hyperium/http) from 0.2.3 to 0.2.4. - [Release notes](https://github.com/hyperium/http/releases) - [Changelog](https://github.com/hyperium/http/blob/master/CHANGELOG.md) - [Commits](https://github.com/hyperium/http/compare/v0.2.3...v0.2.4) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecbb868..21d81c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1141,9 +1141,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ "bytes 1.0.1", "fnv", -- cgit v1.2.3 From 1beb4c992393b774b11cc3bad444c104dd263562 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Thu, 8 Apr 2021 09:45:37 +0300 Subject: Avoid double-encoding file URL Now that the '%' char itself is accepted in the file name and is encoded into '%25', this exposed a previously silent bug: `base` is already percent-encoded but it is encoded again when setting `file_url`. This produces erroneous URLs such as: '/%2523/x.y' instead of '/%23/x.y' for the path '/#/x.y' --- src/listing.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/listing.rs b/src/listing.rs index 2a62fd6..8c01b4b 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -15,7 +15,7 @@ use strum_macros::{Display, EnumString}; use crate::archive::CompressionMethod; use crate::errors::{self, ContextualError}; use crate::renderer; -use percent_encode_sets::{PATH, PATH_SEGMENT}; +use percent_encode_sets::PATH_SEGMENT; /// "percent-encode sets" as defined by WHATWG specs: /// https://url.spec.whatwg.org/#percent-encoded-bytes @@ -260,13 +260,12 @@ pub fn directory_listing( for entry in dir.path.read_dir()? { if dir.is_visible(&entry) || show_hidden { let entry = entry?; - let p = match entry.path().strip_prefix(&dir.path) { - Ok(p) => base.join(p), - Err(_) => continue, - }; // show file url as relative to static path - let file_url = utf8_percent_encode(&p.to_string_lossy(), PATH).to_string(); let file_name = entry.file_name().to_string_lossy().to_string(); + let file_url = base + .join(&utf8_percent_encode(&file_name, PATH_SEGMENT).to_string()) + .to_string_lossy() + .to_string(); // if file is a directory, add '/' to the end of the name if let Ok(metadata) = entry.metadata() { -- cgit v1.2.3 From 8b35b83a930405251f00579860789715fdfb85d1 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Fri, 9 Apr 2021 14:34:48 +0300 Subject: Fix breadcrumbs for RTL languages --- src/renderer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer.rs b/src/renderer.rs index c9ec9cd..b193c6f 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -80,14 +80,14 @@ pub fn page( (color_scheme_selector(show_qrcode)) div.container { span#top { } - h1.title { + h1.title dir="ltr" { @for el in breadcrumbs { @if el.link == "." { // wrapped in span so the text doesn't shift slightly when it turns into a link - span { (el.name) } + span { bdi { (el.name) } } } @else { a.directory href=(parametrized_link(&el.link, sort_method, sort_order)) { - (el.name) + bdi { (el.name) } } } "/" -- cgit v1.2.3 From 32a88fe41457acc8f1525a951dbe40d39ffe8ce3 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Fri, 9 Apr 2021 14:52:03 +0300 Subject: Fix breadcrumbs mess on mobile On mobile devices, 'display: block' is set for '.directory' class. While this neccessary to make the whole row for directories entry clickable, it distorts the links in breadcrumbs. --- data/style.scss | 5 +++++ src/renderer.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/data/style.scss b/data/style.scss index 9bfbeaf..7d8a73d 100644 --- a/data/style.scss +++ b/data/style.scss @@ -42,6 +42,11 @@ body { word-break: break-word; } +.title a { + font-weight: bold; + color: var(--directory_link_color); +} + .footer { text-align: center; padding-top: 1.5rem; diff --git a/src/renderer.rs b/src/renderer.rs index b193c6f..c99ea67 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -86,7 +86,7 @@ pub fn page( // wrapped in span so the text doesn't shift slightly when it turns into a link span { bdi { (el.name) } } } @else { - a.directory href=(parametrized_link(&el.link, sort_method, sort_order)) { + a href=(parametrized_link(&el.link, sort_method, sort_order)) { bdi { (el.name) } } } -- cgit v1.2.3 From 2bae301ed8efcf4239849a45b94cdc42e398b905 Mon Sep 17 00:00:00 2001 From: Dean Li <deantvv@gmail.com> Date: Sun, 11 Apr 2021 11:00:16 +0800 Subject: Separate tar archive and tar flags It used to have one flag (-r) to enable both tar archive and tar. Now it has two flags [ -r: for tar, -g: for tar archive]. Related to #451 --- src/archive.rs | 9 +++++++-- src/args.rs | 6 +++++- src/listing.rs | 4 +++- src/main.rs | 8 +++++++- src/renderer.rs | 5 +++-- tests/archive.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 4df3a31..28d26b5 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -53,10 +53,15 @@ impl CompressionMethod { } } - pub fn is_enabled(self, tar_enabled: bool, zip_enabled: bool) -> bool { + pub fn is_enabled( + self, + tar_enabled: bool, + tar_archive_enabled: bool, + zip_enabled: bool, + ) -> bool { match self { - CompressionMethod::TarGz => tar_enabled, CompressionMethod::Tar => tar_enabled, + CompressionMethod::TarGz => tar_archive_enabled, CompressionMethod::Zip => zip_enabled, } } diff --git a/src/args.rs b/src/args.rs index 81e49dc..bf30254 100644 --- a/src/args.rs +++ b/src/args.rs @@ -99,10 +99,14 @@ pub struct CliArgs { #[structopt(short = "o", long = "overwrite-files")] pub overwrite_files: bool, - /// Enable tar archive generation + /// Enable tar generation #[structopt(short = "r", long = "enable-tar")] pub enable_tar: bool, + /// Enable tar archive generation + #[structopt(short = "g", long = "enable-tar-archive")] + pub enable_tar_archive: bool, + /// Enable zip archive generation /// /// WARNING: Zipping large directories can result in out-of-memory exception diff --git a/src/listing.rs b/src/listing.rs index 66aea6b..868817c 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -158,6 +158,7 @@ pub fn directory_listing( show_qrcode: bool, upload_route: String, tar_enabled: bool, + tar_archive_enabled: bool, zip_enabled: bool, dirs_first: bool, hide_version_footer: bool, @@ -330,7 +331,7 @@ pub fn directory_listing( } if let Some(compression_method) = query_params.download { - if !compression_method.is_enabled(tar_enabled, zip_enabled) { + if !compression_method.is_enabled(tar_enabled, tar_archive_enabled, zip_enabled) { return Ok(ServiceResponse::new( req.clone(), HttpResponse::Forbidden() @@ -413,6 +414,7 @@ pub fn directory_listing( &encoded_dir, breadcrumbs, tar_enabled, + tar_archive_enabled, zip_enabled, hide_version_footer, ) diff --git a/src/main.rs b/src/main.rs index 84a4cb8..a00ac3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,9 +90,12 @@ pub struct MiniserveConfig { /// Enable upload to override existing files pub overwrite_files: bool, - /// If false, creation of tar archives is disabled + /// If false, creation of tar is disabled pub tar_enabled: bool, + /// If false, creation of tar archives is disabled + pub tar_archive_enabled: bool, + /// If false, creation of zip archives is disabled pub zip_enabled: bool, @@ -161,6 +164,7 @@ impl MiniserveConfig { show_qrcode: args.qrcode, file_upload: args.file_upload, tar_enabled: args.enable_tar, + tar_archive_enabled: args.enable_tar_archive, zip_enabled: args.enable_zip, dirs_first: args.dirs_first, title: args.title, @@ -411,6 +415,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { let show_qrcode = conf.show_qrcode; let file_upload = conf.file_upload; let tar_enabled = conf.tar_enabled; + let tar_archive_enabled = conf.tar_archive_enabled; let zip_enabled = conf.zip_enabled; let dirs_first = conf.dirs_first; let hide_version_footer = conf.hide_version_footer; @@ -453,6 +458,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { show_qrcode, u_r.clone(), tar_enabled, + tar_archive_enabled, zip_enabled, dirs_first, hide_version_footer, diff --git a/src/renderer.rs b/src/renderer.rs index c9ec9cd..71a929a 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -26,6 +26,7 @@ pub fn page( encoded_dir: &str, breadcrumbs: Vec<Breadcrumb>, tar_enabled: bool, + tar_archive_enabled: bool, zip_enabled: bool, hide_version_footer: bool, ) -> Markup { @@ -94,10 +95,10 @@ pub fn page( } } div.toolbar { - @if tar_enabled || zip_enabled { + @if tar_enabled || tar_archive_enabled || zip_enabled { div.download { @for compression_method in CompressionMethod::iter() { - @if compression_method.is_enabled(tar_enabled, zip_enabled) { + @if compression_method.is_enabled(tar_enabled, tar_archive_enabled, zip_enabled) { (archive_button(compression_method, sort_method, sort_order)) } } diff --git a/tests/archive.rs b/tests/archive.rs index c170bc3..6a7f8bf 100644 --- a/tests/archive.rs +++ b/tests/archive.rs @@ -51,3 +51,44 @@ fn archives_are_disabled(tmpdir: TempDir, port: u16) -> Result<(), Error> { Ok(()) } + +#[rstest] +fn test_tar_archives(tmpdir: TempDir, port: u16) -> Result<(), Error> { + let mut child = Command::cargo_bin("miniserve")? + .arg(tmpdir.path()) + .arg("-p") + .arg(port.to_string()) + .arg("-g") + .stdout(Stdio::null()) + .spawn()?; + + sleep(Duration::from_secs(1)); + + // Ensure the links to the tar archive exists and tar not exists + let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())? + .error_for_status()?; + let parsed = Document::from_read(body)?; + assert!(parsed.find(Text).any(|x| x.text() == "Download .tar.gz")); + assert!(parsed.find(Text).all(|x| x.text() != "Download .tar")); + + // Try to download, only tar_gz should works + assert_eq!( + reqwest::blocking::get(format!("http://localhost:{}/?download=tar_gz", port).as_str())? + .status(), + StatusCode::OK + ); + assert_eq!( + reqwest::blocking::get(format!("http://localhost:{}/?download=tar", port).as_str())? + .status(), + StatusCode::FORBIDDEN + ); + assert_eq!( + reqwest::blocking::get(format!("http://localhost:{}/?download=zip", port).as_str())? + .status(), + StatusCode::FORBIDDEN + ); + + child.kill()?; + + Ok(()) +} -- cgit v1.2.3 From c27ece58137ccbae938bc3e000922b8a78ff0503 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 12 Apr 2021 04:15:21 +0000 Subject: Bump futures from 0.3.13 to 0.3.14 Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.13 to 0.3.14. - [Release notes](https://github.com/rust-lang/futures-rs/releases) - [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.13...0.3.14) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b8fca9..342a033 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -860,9 +860,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1" +checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" dependencies = [ "futures-channel", "futures-core", @@ -875,9 +875,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" +checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" dependencies = [ "futures-core", "futures-sink", @@ -885,15 +885,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" +checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" [[package]] name = "futures-executor" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1" +checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" dependencies = [ "futures-core", "futures-task", @@ -902,15 +902,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" +checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" [[package]] name = "futures-macro" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7" +checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -920,21 +920,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" +checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" [[package]] name = "futures-task" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" +checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" [[package]] name = "futures-util" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" +checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" dependencies = [ "futures-channel", "futures-core", -- cgit v1.2.3 From 5ccb4712583b1106ab07eae7b7fe094de57684dc Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 13 Apr 2021 04:16:03 +0000 Subject: Bump reqwest from 0.11.2 to 0.11.3 Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.11.2 to 0.11.3. - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](https://github.com/seanmonstar/reqwest/compare/v0.11.2...v0.11.3) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 342a033..7f04af4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2163,9 +2163,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" +checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" dependencies = [ "base64", "bytes 1.0.1", -- cgit v1.2.3 From 3b72934e4142ebe27dce125bb60d0317b00a383f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 16 Apr 2021 04:15:32 +0000 Subject: Bump pretty_assertions from 0.7.1 to 0.7.2 Bumps [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) from 0.7.1 to 0.7.2. - [Release notes](https://github.com/colin-kiegel/rust-pretty-assertions/releases) - [Changelog](https://github.com/colin-kiegel/rust-pretty-assertions/blob/main/CHANGELOG.md) - [Commits](https://github.com/colin-kiegel/rust-pretty-assertions/compare/v0.7.1...v0.7.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f04af4..96934c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1950,9 +1950,9 @@ dependencies = [ [[package]] name = "pretty_assertions" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f297542c27a7df8d45de2b0e620308ab883ad232d06c14b76ac3e144bda50184" +checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b" dependencies = [ "ansi_term 0.12.1", "ctor", -- cgit v1.2.3 From c11ff4e9a72248a8a8131bd7d4cb25bd6ae05841 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 04:52:22 +0200 Subject: Group actix deps together --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a73dc1..cc264ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,12 @@ codegen-units = 1 panic = 'abort' [dependencies] -yansi = "0.5" actix-web = "3" +actix-files = "0.5" +actix-multipart = "0.3" +actix-web-httpauth = "0.5" +maud = { version = "0.22", features = ["actix-web"] } +yansi = "0.5" simplelog = "0.10" percent-encoding = "2" port_check = "0.1" @@ -28,7 +32,6 @@ alphanumeric-sort = "1" structopt = "0.3" chrono = "0.4" chrono-humanize = "0.1" -maud = { version = "0.22", features = ["actix-web"] } serde = { version = "1", features = ["derive"] } tar = "0.4" futures = "0.3" @@ -41,9 +44,6 @@ sha2 = "0.9" hex = "0.4" zip = "0.5.11" qrcodegen = "1" -actix-files = "0.5" -actix-multipart = "0.3" -actix-web-httpauth = "0.5" mime = "0.3" httparse = "1" http = "0.2" -- cgit v1.2.3 From 8e54fc6aa4ab70e35828349751def0651069f318 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 04:52:30 +0200 Subject: Bump deps --- Cargo.lock | 135 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96934c0..9629fc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,7 +93,7 @@ dependencies = [ "log", "mime", "percent-encoding", - "pin-project 1.0.6", + "pin-project 1.0.7", "rand 0.7.3", "regex", "serde", @@ -279,7 +279,7 @@ dependencies = [ "fxhash", "log", "mime", - "pin-project 1.0.6", + "pin-project 1.0.7", "regex", "serde", "serde_json", @@ -312,6 +312,12 @@ dependencies = [ "futures-util", ] +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "adler32" version = "1.2.0" @@ -387,9 +393,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.48" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf" +checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" dependencies = [ "proc-macro2", "quote", @@ -648,9 +654,9 @@ checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" [[package]] name = "const_fn" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "076a6803b0dacd6a88cfe64deba628b01533ff5ef265687e6938280c1afd0a28" +checksum = "402da840495de3f976eaefc3485b7f5eb5b0bf9761f9a47be27fe975b3b8c2ec" [[package]] name = "convert_case" @@ -797,11 +803,11 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.14" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfff41391129e0a856d6d822600b8d71179d46879e310417eb9c762eb178b42" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "crc32fast", "libc", "miniz_oxide", @@ -1069,8 +1075,8 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.4.0", - "tokio-util 0.6.5", + "tokio 1.5.0", + "tokio-util 0.6.6", "tracing", ] @@ -1163,9 +1169,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.6" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" +checksum = "4a1ce40d6fc9764887c2fdc7305c3dcc429ba11ff981c1509416afd5697e4437" [[package]] name = "httpdate" @@ -1189,9 +1195,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.6", + "pin-project 1.0.7", "socket2 0.4.0", - "tokio 1.4.0", + "tokio 1.5.0", "tower-service", "tracing", "want", @@ -1207,16 +1213,16 @@ dependencies = [ "hyper", "log", "rustls", - "tokio 1.4.0", + "tokio 1.5.0", "tokio-rustls", "webpki", ] [[package]] name = "idna" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" dependencies = [ "matches", "unicode-bidi", @@ -1335,27 +1341,29 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" [[package]] name = "libflate" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158ae2ca09a761eaf6050894f5a6f013f2773dafe24f67bfa73a7504580e2916" +checksum = "6d87eae36b3f680f7f01645121b782798b56ef33c53f83d1c66ba3a22b60bfe3" dependencies = [ "adler32", "crc32fast", "libflate_lz77", - "rle-decode-fast", ] [[package]] name = "libflate_lz77" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3286f09f7d4926fc486334f28d8d2e6ebe4f7f9994494b6dab27ddfad2c9b11b" +checksum = "39a734c0493409afcd49deee13c006a04e3586b9761a03543c6272c9c51f2f5a" +dependencies = [ + "rle-decode-fast", +] [[package]] name = "linked-hash-map" @@ -1365,9 +1373,9 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "lock_api" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" dependencies = [ "scopeguard", ] @@ -1539,11 +1547,12 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.3.7" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ - "adler32", + "adler", + "autocfg", ] [[package]] @@ -1848,11 +1857,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc174859768806e91ae575187ada95c91a29e96a98dc5d2cd9a1fed039501ba6" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" dependencies = [ - "pin-project-internal 1.0.6", + "pin-project-internal 1.0.7", ] [[package]] @@ -1868,9 +1877,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a490329918e856ed1b083f244e3bfe2d8c4f336407e4ea9e1a9f479ff09049e5" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" dependencies = [ "proc-macro2", "quote", @@ -1998,9 +2007,9 @@ checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -2119,9 +2128,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" dependencies = [ "bitflags", ] @@ -2187,7 +2196,7 @@ dependencies = [ "rustls", "serde", "serde_urlencoded", - "tokio 1.4.0", + "tokio 1.5.0", "tokio-rustls", "url", "wasm-bindgen", @@ -2261,9 +2270,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.19.0" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ "base64", "log", @@ -2295,9 +2304,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "sct" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" +checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" dependencies = [ "ring", "untrusted", @@ -2620,9 +2629,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" +checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" dependencies = [ "proc-macro2", "quote", @@ -2771,9 +2780,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" dependencies = [ "tinyvec_macros", ] @@ -2806,9 +2815,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134af885d758d645f0f0505c9a8b3f9bf8a348fd822e112ab5248138348f1722" +checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" dependencies = [ "autocfg", "bytes 1.0.1", @@ -2826,7 +2835,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ "rustls", - "tokio 1.4.0", + "tokio 1.5.0", "webpki", ] @@ -2846,16 +2855,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5143d049e85af7fbc36f5454d990e62c2df705b3589f123b71f441b6b59f443f" +checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" dependencies = [ "bytes 1.0.1", "futures-core", "futures-sink", "log", "pin-project-lite 0.2.6", - "tokio 1.4.0", + "tokio 1.5.0", ] [[package]] @@ -2891,7 +2900,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ - "pin-project 1.0.6", + "pin-project 1.0.7", "tracing", ] @@ -2985,9 +2994,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" dependencies = [ "matches", ] @@ -3039,9 +3048,9 @@ dependencies = [ [[package]] name = "utf-8" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "v_escape" @@ -3225,9 +3234,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.21.0" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82015b7e0b8bad8185994674a13a93306bea76cf5a16c5a181382fd3a5ec2376" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" dependencies = [ "webpki", ] @@ -3338,9 +3347,9 @@ checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" [[package]] name = "zip" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8264fcea9b7a036a4a5103d7153e988dbc2ebbafb34f68a3c2d404b6b82d74b6" +checksum = "9c83dc9b784d252127720168abd71ea82bf8c3d96b17dc565b5e2a02854f2b27" dependencies = [ "byteorder", "bzip2", -- cgit v1.2.3 From 619c89a97d72254b3aa6850f2a21963ec2081544 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 05:04:19 +0200 Subject: Add CHANGELOG entry for breadcrumbs RTL fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 693ff97..04358eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). <!-- next-header --> ## [Unreleased] - ReleaseDate +- Fix breadcrumbs for right-to-left languages [#489](https://github.com/svenstaro/miniserve/pull/489) (thanks @aliemjay) ## [0.13.0] - 2021-03-28 - Change default log level to `Warn` -- cgit v1.2.3 From 422cbb37285a6e89a1e71ee9e5a3bbe26e21cb6d Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> Date: Sun, 18 Apr 2021 06:21:37 +0300 Subject: Wrap breadcrumbs at any char This would make a good use of space in mobile view. --- data/style.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/style.scss b/data/style.scss index 7d8a73d..b901ef6 100644 --- a/data/style.scss +++ b/data/style.scss @@ -39,7 +39,7 @@ body { } .title { - word-break: break-word; + word-break: break-all; } .title a { -- cgit v1.2.3 From c9506c72ff368867982d138a686648fa302b116d Mon Sep 17 00:00:00 2001 From: Dean Li <deantvv@gmail.com> Date: Sun, 18 Apr 2021 11:22:52 +0800 Subject: Change naming of uncompressed/compressed tarballs Use following terminology: uncompressed tarballs => `uncompressed tar archives` compressed ones => `gz-compressed tar archives` --- src/archive.rs | 9 ++------- src/args.rs | 8 ++++---- src/listing.rs | 6 +++--- src/main.rs | 12 ++++++------ src/renderer.rs | 6 +++--- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index 28d26b5..e53aea8 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -53,15 +53,10 @@ impl CompressionMethod { } } - pub fn is_enabled( - self, - tar_enabled: bool, - tar_archive_enabled: bool, - zip_enabled: bool, - ) -> bool { + pub fn is_enabled(self, tar_enabled: bool, tar_gz_enabled: bool, zip_enabled: bool) -> bool { match self { + CompressionMethod::TarGz => tar_gz_enabled, CompressionMethod::Tar => tar_enabled, - CompressionMethod::TarGz => tar_archive_enabled, CompressionMethod::Zip => zip_enabled, } } diff --git a/src/args.rs b/src/args.rs index bf30254..819618f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -99,13 +99,13 @@ pub struct CliArgs { #[structopt(short = "o", long = "overwrite-files")] pub overwrite_files: bool, - /// Enable tar generation + /// Enable uncompressed tar archive generation #[structopt(short = "r", long = "enable-tar")] pub enable_tar: bool, - /// Enable tar archive generation - #[structopt(short = "g", long = "enable-tar-archive")] - pub enable_tar_archive: bool, + /// Enable gz-compressed tar archive generation + #[structopt(short = "g", long = "enable-tar-gz")] + pub enable_tar_gz: bool, /// Enable zip archive generation /// diff --git a/src/listing.rs b/src/listing.rs index 868817c..cff4f9a 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -158,7 +158,7 @@ pub fn directory_listing( show_qrcode: bool, upload_route: String, tar_enabled: bool, - tar_archive_enabled: bool, + tar_gz_enabled: bool, zip_enabled: bool, dirs_first: bool, hide_version_footer: bool, @@ -331,7 +331,7 @@ pub fn directory_listing( } if let Some(compression_method) = query_params.download { - if !compression_method.is_enabled(tar_enabled, tar_archive_enabled, zip_enabled) { + if !compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { return Ok(ServiceResponse::new( req.clone(), HttpResponse::Forbidden() @@ -414,7 +414,7 @@ pub fn directory_listing( &encoded_dir, breadcrumbs, tar_enabled, - tar_archive_enabled, + tar_gz_enabled, zip_enabled, hide_version_footer, ) diff --git a/src/main.rs b/src/main.rs index a00ac3c..f174d57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,11 +90,11 @@ pub struct MiniserveConfig { /// Enable upload to override existing files pub overwrite_files: bool, - /// If false, creation of tar is disabled + /// If false, creation of uncompressed tar archives is disabled pub tar_enabled: bool, - /// If false, creation of tar archives is disabled - pub tar_archive_enabled: bool, + /// If false, creation of gz-compressed tar archives is disabled + pub tar_gz_enabled: bool, /// If false, creation of zip archives is disabled pub zip_enabled: bool, @@ -164,7 +164,7 @@ impl MiniserveConfig { show_qrcode: args.qrcode, file_upload: args.file_upload, tar_enabled: args.enable_tar, - tar_archive_enabled: args.enable_tar_archive, + tar_gz_enabled: args.enable_tar_gz, zip_enabled: args.enable_zip, dirs_first: args.dirs_first, title: args.title, @@ -415,7 +415,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { let show_qrcode = conf.show_qrcode; let file_upload = conf.file_upload; let tar_enabled = conf.tar_enabled; - let tar_archive_enabled = conf.tar_archive_enabled; + let tar_gz_enabled = conf.tar_gz_enabled; let zip_enabled = conf.zip_enabled; let dirs_first = conf.dirs_first; let hide_version_footer = conf.hide_version_footer; @@ -458,7 +458,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { show_qrcode, u_r.clone(), tar_enabled, - tar_archive_enabled, + tar_gz_enabled, zip_enabled, dirs_first, hide_version_footer, diff --git a/src/renderer.rs b/src/renderer.rs index 71a929a..5cb5452 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -26,7 +26,7 @@ pub fn page( encoded_dir: &str, breadcrumbs: Vec<Breadcrumb>, tar_enabled: bool, - tar_archive_enabled: bool, + tar_gz_enabled: bool, zip_enabled: bool, hide_version_footer: bool, ) -> Markup { @@ -95,10 +95,10 @@ pub fn page( } } div.toolbar { - @if tar_enabled || tar_archive_enabled || zip_enabled { + @if tar_enabled || tar_gz_enabled || zip_enabled { div.download { @for compression_method in CompressionMethod::iter() { - @if compression_method.is_enabled(tar_enabled, tar_archive_enabled, zip_enabled) { + @if compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { (archive_button(compression_method, sort_method, sort_order)) } } -- cgit v1.2.3 From 464b97b3d2c52761c458a016b2763c52a667e666 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 05:24:17 +0200 Subject: Add CHANGELOG entry for fixed URL percent encoding for special characters --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04358eb..25b0a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate - Fix breadcrumbs for right-to-left languages [#489](https://github.com/svenstaro/miniserve/pull/489) (thanks @aliemjay) +- Fix URL percent encoding for special characters [#485](https://github.com/svenstaro/miniserve/pull/485) (thanks @aliemjay) ## [0.13.0] - 2021-03-28 - Change default log level to `Warn` -- cgit v1.2.3 From a24fbbbce3ba6d81ceb4bbdfc506bd52f6814ddc Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 05:40:31 +0200 Subject: Add CHANGELOG entry for wrapping breadcrumbs at any char --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b0a80..46357c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate - Fix breadcrumbs for right-to-left languages [#489](https://github.com/svenstaro/miniserve/pull/489) (thanks @aliemjay) - Fix URL percent encoding for special characters [#485](https://github.com/svenstaro/miniserve/pull/485) (thanks @aliemjay) +- Wrap breadcrumbs at any char [#496](https://github.com/svenstaro/miniserve/pull/496) (thanks @aliemjay) ## [0.13.0] - 2021-03-28 - Change default log level to `Warn` -- cgit v1.2.3 From c249118d6c0fef71354b2e8231dfa31ddd1b1f22 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 05:43:32 +0200 Subject: Add CHANGELOG entry for separate flags for .tar and .tar.gz archives --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46357c9..488ba6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix breadcrumbs for right-to-left languages [#489](https://github.com/svenstaro/miniserve/pull/489) (thanks @aliemjay) - Fix URL percent encoding for special characters [#485](https://github.com/svenstaro/miniserve/pull/485) (thanks @aliemjay) - Wrap breadcrumbs at any char [#496](https://github.com/svenstaro/miniserve/pull/496) (thanks @aliemjay) +- Add separate flags for compressed and uncompressed tar archives [#492](https://github.com/svenstaro/miniserve/pull/492) (thanks @deantvv) ## [0.13.0] - 2021-03-28 - Change default log level to `Warn` -- cgit v1.2.3 From 755983d3d7985833fb4fb1b4510b9c677771dd79 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase <svenstaro@gmail.com> Date: Sun, 18 Apr 2021 05:43:58 +0200 Subject: Update README for separate .tar and .tar.gz flags --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ad41a0..6aa1782 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,10 @@ Sometimes this is just a more practical and quick way than doing things properly List directories first -r, --enable-tar - Enable tar archive generation + Enable uncompressed tar archive generation + + -g, --enable-tar-gz + Enable gz-compressed tar archive generation -z, --enable-zip Enable zip archive generation -- cgit v1.2.3