From 2bae301ed8efcf4239849a45b94cdc42e398b905 Mon Sep 17 00:00:00 2001 From: Dean Li 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 +++-- 5 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src') 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, 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)) } } -- cgit v1.2.3 From c9506c72ff368867982d138a686648fa302b116d Mon Sep 17 00:00:00 2001 From: Dean Li 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(-) (limited to 'src') 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, 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