Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master from dev #20

Merged
merged 11 commits into from
Apr 7, 2021
Prev Previous commit
Next Next commit
Minor style changes
  • Loading branch information
marcospb19 committed Apr 6, 2021
commit 78d5f435ee120edabbba102c70a5316bf2b6d85f
6 changes: 1 addition & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::{

use oof::{arg_flag, flag};

pub const VERSION: &str = "0.1.5";

#[derive(PartialEq, Eq, Debug)]
pub enum Command {
/// Files to be compressed
Expand All @@ -29,7 +27,6 @@ pub enum Command {
pub struct CommandInfo {
pub command: Command,
pub flags: oof::Flags,
// pub config: Config, // From .TOML, maybe, in the future
}

/// Calls parse_args_and_flags_from using std::env::args_os ( argv )
Expand All @@ -41,7 +38,6 @@ pub fn parse_args() -> crate::Result<ParsedArgs> {
pub struct ParsedArgs {
pub command: Command,
pub flags: oof::Flags,
// pub program_called: OsString, // Useful?
}

fn canonicalize<'a, P>(path: P) -> crate::Result<PathBuf>
Expand All @@ -54,7 +50,7 @@ where
if !path.as_ref().exists() {
Err(crate::Error::FileNotFound(PathBuf::from(path.as_ref())))
} else {
eprintln!("{} {}", "[ERROR]", io_err);
eprintln!("[ERROR] {}", io_err);
Err(crate::Error::IoError)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compressors/bzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
utils::{check_for_multiple_files, ensure_exists},
};

pub struct BzipCompressor {}
pub struct BzipCompressor;

impl BzipCompressor {
fn compress_files(files: Vec<PathBuf>, format: CompressionFormat) -> crate::Result<Vec<u8>> {
Expand Down
6 changes: 0 additions & 6 deletions src/compressors/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ use std::path::PathBuf;

use crate::file::File;

// pub enum CompressionResult {
// ZipArchive(Vec<u8>),
// TarArchive(Vec<u8>),
// FileInMemory(Vec<u8>)
// }

pub enum Entry<'a> {
Files(Vec<PathBuf>),
InMemory(File<'a>),
Expand Down
2 changes: 1 addition & 1 deletion src/compressors/gzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
utils::{check_for_multiple_files, ensure_exists},
};

pub struct GzipCompressor {}
pub struct GzipCompressor;

impl GzipCompressor {
pub fn compress_files(
Expand Down
2 changes: 1 addition & 1 deletion src/compressors/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
utils::{check_for_multiple_files, ensure_exists},
};

pub struct LzmaCompressor {}
pub struct LzmaCompressor;

impl LzmaCompressor {
pub fn compress_files(
Expand Down
1 change: 1 addition & 0 deletions src/compressors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! This module contains the Compressor trait and an implementor for each format.
mod bzip;
mod compressor;
mod gzip;
Expand Down
2 changes: 1 addition & 1 deletion src/compressors/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use walkdir::WalkDir;
use super::compressor::Entry;
use crate::{compressors::Compressor, file::File, utils};

pub struct TarCompressor {}
pub struct TarCompressor;

impl TarCompressor {
// TODO: implement this
Expand Down
2 changes: 1 addition & 1 deletion src/compressors/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use walkdir::WalkDir;
use super::compressor::Entry;
use crate::{compressors::Compressor, file::File, utils};

pub struct ZipCompressor {}
pub struct ZipCompressor;

impl ZipCompressor {
// TODO: this function does not seem to be working correctly ;/
Expand Down
13 changes: 5 additions & 8 deletions src/decompressors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//! This module contains the Decompressor trait and an implementor for each format.

mod decompressor;
mod tar;
mod to_memory;
mod zip;

pub use decompressor::{DecompressionResult, Decompressor};

// These decompressors only decompress to memory,
// unlike {Tar, Zip}Decompressor which are capable of
// decompressing directly to storage
pub use self::{
tar::TarDecompressor,
to_memory::{BzipDecompressor, GzipDecompressor, LzmaDecompressor},
zip::ZipDecompressor,
};
pub use self::to_memory::{BzipDecompressor, GzipDecompressor, LzmaDecompressor};
// The .tar and .zip decompressors are capable of decompressing directly to storage
pub use self::{tar::TarDecompressor, zip::ZipDecompressor};
2 changes: 1 addition & 1 deletion src/decompressors/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::decompressor::{DecompressionResult, Decompressor};
use crate::{bytes::Bytes, dialogs::Confirmation, file::File, utils};

#[derive(Debug)]
pub struct TarDecompressor {}
pub struct TarDecompressor;

impl TarDecompressor {
fn unpack_files(from: File, into: &Path, flags: &oof::Flags) -> crate::Result<Vec<PathBuf>> {
Expand Down
14 changes: 6 additions & 8 deletions src/decompressors/to_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ use std::{
use colored::Colorize;

use super::decompressor::{DecompressionResult, Decompressor};
use crate::bytes::Bytes;
use crate::utils;
use crate::{extension::CompressionFormat, file::File};

struct DecompressorToMemory {}
pub struct GzipDecompressor {}
pub struct LzmaDecompressor {}
pub struct BzipDecompressor {}
use crate::{bytes::Bytes, extension::CompressionFormat, file::File, utils};

struct DecompressorToMemory;
pub struct GzipDecompressor;
pub struct LzmaDecompressor;
pub struct BzipDecompressor;

fn get_decoder<'a>(
format: CompressionFormat,
Expand Down
2 changes: 1 addition & 1 deletion src/decompressors/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn __unix_set_permissions(file_path: &Path, file: &ZipFile) {
}
}

pub struct ZipDecompressor {}
pub struct ZipDecompressor;

impl ZipDecompressor {
fn check_for_comments(file: &ZipFile) {
Expand Down
40 changes: 20 additions & 20 deletions src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use colored::Colorize;

use crate::{
bytes::Bytes,
cli::{Command, VERSION},
cli::Command,
compressors::{
BzipCompressor, Compressor, Entry, GzipCompressor, LzmaCompressor, TarCompressor,
ZipCompressor,
Expand All @@ -23,7 +23,7 @@ use crate::{
utils,
};

pub struct Evaluator {}
pub struct Evaluator;

type BoxedCompressor = Box<dyn Compressor>;
type BoxedDecompressor = Box<dyn Decompressor>;
Expand All @@ -48,23 +48,23 @@ impl Evaluator {
// .tar and .zip
let first_compressor: Option<Box<dyn Compressor>> = match extension.first_ext {
Some(ext) => match ext {
CompressionFormat::Tar => Some(Box::new(TarCompressor {})),
CompressionFormat::Zip => Some(Box::new(ZipCompressor {})),
CompressionFormat::Bzip => Some(Box::new(BzipCompressor {})),
CompressionFormat::Gzip => Some(Box::new(GzipCompressor {})),
CompressionFormat::Lzma => Some(Box::new(LzmaCompressor {})),
CompressionFormat::Tar => Some(Box::new(TarCompressor)),
CompressionFormat::Zip => Some(Box::new(ZipCompressor)),
CompressionFormat::Bzip => Some(Box::new(BzipCompressor)),
CompressionFormat::Gzip => Some(Box::new(GzipCompressor)),
CompressionFormat::Lzma => Some(Box::new(LzmaCompressor)),
},
None => None,
};

// Supported second compressors:
// any
let second_compressor: Box<dyn Compressor> = match extension.second_ext {
CompressionFormat::Tar => Box::new(TarCompressor {}),
CompressionFormat::Zip => Box::new(ZipCompressor {}),
CompressionFormat::Bzip => Box::new(BzipCompressor {}),
CompressionFormat::Gzip => Box::new(GzipCompressor {}),
CompressionFormat::Lzma => Box::new(LzmaCompressor {}),
CompressionFormat::Tar => Box::new(TarCompressor),
CompressionFormat::Zip => Box::new(ZipCompressor),
CompressionFormat::Bzip => Box::new(BzipCompressor),
CompressionFormat::Gzip => Box::new(GzipCompressor),
CompressionFormat::Lzma => Box::new(LzmaCompressor),
};

Ok((first_compressor, second_compressor))
Expand All @@ -86,17 +86,17 @@ impl Evaluator {
};

let second_decompressor: Box<dyn Decompressor> = match extension.second_ext {
CompressionFormat::Tar => Box::new(TarDecompressor {}),
CompressionFormat::Zip => Box::new(ZipDecompressor {}),
CompressionFormat::Gzip => Box::new(GzipDecompressor {}),
CompressionFormat::Lzma => Box::new(LzmaDecompressor {}),
CompressionFormat::Bzip => Box::new(BzipDecompressor {}),
CompressionFormat::Tar => Box::new(TarDecompressor),
CompressionFormat::Zip => Box::new(ZipDecompressor),
CompressionFormat::Gzip => Box::new(GzipDecompressor),
CompressionFormat::Lzma => Box::new(LzmaDecompressor),
CompressionFormat::Bzip => Box::new(BzipDecompressor),
};

let first_decompressor: Option<Box<dyn Decompressor>> = match extension.first_ext {
Some(ext) => match ext {
CompressionFormat::Tar => Some(Box::new(TarDecompressor {})),
CompressionFormat::Zip => Some(Box::new(ZipDecompressor {})),
CompressionFormat::Tar => Some(Box::new(TarDecompressor)),
CompressionFormat::Zip => Some(Box::new(ZipDecompressor)),
_other => None,
},
None => None,
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Evaluator {

#[inline]
fn version_message() {
println!("ouch {}", VERSION);
println!("ouch {}", crate::VERSION);
}

fn help_message() {
Expand Down
15 changes: 5 additions & 10 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,11 @@ impl Extension {
#[derive(Clone, PartialEq, Eq, Debug)]
/// Accepted extensions for input and output
pub enum CompressionFormat {
// .gz
Gzip,
// .bz
Bzip,
// .lzma
Lzma,
// .tar (technically not a compression extension, but will do for now)
Tar,
// .zip
Zip,
Gzip, // .gz
Bzip, // .bz
Lzma, // .lzma
Tar, // .tar (technically not a compression extension, but will do for now)
Zip, // .zip
}

fn extension_from_os_str(ext: &OsStr) -> Result<CompressionFormat, crate::Error> {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod file;
mod test;
mod utils;

pub const VERSION: &str = "0.1.5";

use error::{Error, Result};
use evaluator::Evaluator;

Expand Down
9 changes: 8 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ pub(crate) fn check_for_multiple_files(
format: &CompressionFormat,
) -> crate::Result<()> {
if files.len() != 1 {
eprintln!("{}: cannot compress multiple files directly to {:#?}.\n Try using an intermediate archival method such as Tar.\n Example: filename.tar{}", "[ERROR]".red(), format, format);
eprintln!(
"{}: cannot compress multiple files directly to {:#?}.\n\
Try using an intermediate archival method such as Tar.\n\
Example: filename.tar{}",
"[ERROR]".red(),
format,
format
);
return Err(crate::Error::InvalidInput);
}

Expand Down