From 08f6bc54dac113995fb5e3c138bdc50e2ae75905 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 18 Apr 2021 05:49:52 +0200 Subject: Rename compression code references to 'archive' This name more closely resembles its purpose. For instance, we also now support plain tar archives which are uncompressed but archives nonetheless. --- src/archive.rs | 36 ++++++++++++++++++------------------ src/listing.rs | 18 +++++++++--------- src/renderer.rs | 16 ++++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index e53aea8..b5a0eda 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -11,11 +11,11 @@ use zip::{write, ZipWriter}; use crate::errors::ContextualError; -/// Available compression methods +/// Available archive methods #[derive(Deserialize, Clone, Copy, EnumIter, EnumString, Display)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] -pub enum CompressionMethod { +pub enum ArchiveMethod { /// Gzipped tarball TarGz, @@ -26,38 +26,38 @@ pub enum CompressionMethod { Zip, } -impl CompressionMethod { +impl ArchiveMethod { pub fn extension(self) -> String { match self { - CompressionMethod::TarGz => "tar.gz", - CompressionMethod::Tar => "tar", - CompressionMethod::Zip => "zip", + ArchiveMethod::TarGz => "tar.gz", + ArchiveMethod::Tar => "tar", + ArchiveMethod::Zip => "zip", } .to_string() } pub fn content_type(self) -> String { match self { - CompressionMethod::TarGz => "application/gzip", - CompressionMethod::Tar => "application/tar", - CompressionMethod::Zip => "application/zip", + ArchiveMethod::TarGz => "application/gzip", + ArchiveMethod::Tar => "application/tar", + ArchiveMethod::Zip => "application/zip", } .to_string() } pub fn content_encoding(self) -> ContentEncoding { match self { - CompressionMethod::TarGz => ContentEncoding::Gzip, - CompressionMethod::Tar => ContentEncoding::Identity, - CompressionMethod::Zip => ContentEncoding::Identity, + ArchiveMethod::TarGz => ContentEncoding::Gzip, + ArchiveMethod::Tar => ContentEncoding::Identity, + ArchiveMethod::Zip => ContentEncoding::Identity, } } 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::Zip => zip_enabled, + ArchiveMethod::TarGz => tar_gz_enabled, + ArchiveMethod::Tar => tar_enabled, + ArchiveMethod::Zip => zip_enabled, } } @@ -78,9 +78,9 @@ impl CompressionMethod { { let dir = dir.as_ref(); match self { - CompressionMethod::TarGz => tar_gz(dir, skip_symlinks, out), - CompressionMethod::Tar => tar_dir(dir, skip_symlinks, out), - CompressionMethod::Zip => zip_dir(dir, skip_symlinks, out), + ArchiveMethod::TarGz => tar_gz(dir, skip_symlinks, out), + ArchiveMethod::Tar => tar_dir(dir, skip_symlinks, out), + ArchiveMethod::Zip => zip_dir(dir, skip_symlinks, out), } } } diff --git a/src/listing.rs b/src/listing.rs index dcaed96..013265c 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -12,7 +12,7 @@ use std::path::{Component, Path, PathBuf}; use std::time::SystemTime; use strum_macros::{Display, EnumString}; -use crate::archive::CompressionMethod; +use crate::archive::ArchiveMethod; use crate::errors::{self, ContextualError}; use crate::renderer; use percent_encode_sets::PATH_SEGMENT; @@ -34,7 +34,7 @@ pub struct QueryParameters { pub sort: Option, pub order: Option, qrcode: Option, - download: Option, + download: Option, } /// Available sorting methods @@ -338,8 +338,8 @@ pub fn directory_listing( entries.sort_by_key(|e| !e.is_dir()); } - if let Some(compression_method) = query_params.download { - if !compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { + if let Some(archive_method) = query_params.download { + if !archive_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { return Ok(ServiceResponse::new( req.clone(), HttpResponse::Forbidden() @@ -365,14 +365,14 @@ pub fn directory_listing( } log::info!( "Creating an archive ({extension}) of {path}...", - extension = compression_method.extension(), + extension = archive_method.extension(), path = &dir.path.display().to_string() ); let file_name = format!( "{}.{}", dir.path.file_name().unwrap().to_str().unwrap(), - compression_method.extension() + archive_method.extension() ); // We will create the archive in a separate thread, and stream the content using a pipe. @@ -384,7 +384,7 @@ pub fn directory_listing( // Start the actual archive creation in a separate thread. let dir = dir.path.to_path_buf(); std::thread::spawn(move || { - if let Err(err) = compression_method.create_archive(dir, skip_symlinks, pipe) { + if let Err(err) = archive_method.create_archive(dir, skip_symlinks, pipe) { log::error!("Error during archive creation: {:?}", err); } }); @@ -392,8 +392,8 @@ pub fn directory_listing( Ok(ServiceResponse::new( req.clone(), HttpResponse::Ok() - .content_type(compression_method.content_type()) - .encoding(compression_method.content_encoding()) + .content_type(archive_method.content_type()) + .encoding(archive_method.content_encoding()) .header("Content-Transfer-Encoding", "binary") .header( "Content-Disposition", diff --git a/src/renderer.rs b/src/renderer.rs index 4596369..fc6897c 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -6,7 +6,7 @@ use std::time::SystemTime; use structopt::clap::{crate_name, crate_version}; use strum::IntoEnumIterator; -use crate::archive::CompressionMethod; +use crate::archive::ArchiveMethod; use crate::listing::{Breadcrumb, Entry, SortingMethod, SortingOrder}; /// Renders the file listing @@ -97,9 +97,9 @@ pub fn page( div.toolbar { @if tar_enabled || tar_gz_enabled || zip_enabled { div.download { - @for compression_method in CompressionMethod::iter() { - @if compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { - (archive_button(compression_method, sort_method, sort_order)) + @for archive_method in ArchiveMethod::iter() { + @if archive_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) { + (archive_button(archive_method, sort_method, sort_order)) } } } @@ -230,21 +230,21 @@ fn color_scheme_link(color_scheme: &(&str, &str)) -> Markup { /// Partial: archive button fn archive_button( - compress_method: CompressionMethod, + archive_method: ArchiveMethod, sort_method: Option, sort_order: Option, ) -> Markup { let link = if sort_method.is_none() && sort_order.is_none() { - format!("?download={}", compress_method) + format!("?download={}", archive_method) } else { format!( "{}&download={}", parametrized_link("", sort_method, sort_order,), - compress_method + archive_method ) }; - let text = format!("Download .{}", compress_method.extension()); + let text = format!("Download .{}", archive_method.extension()); html! { a href=(link) { -- cgit v1.2.3