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

Fixes #17: Upgrade to [email protected] #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
945 changes: 454 additions & 491 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["decompress", "xtask"]
resolver = "2"
2 changes: 1 addition & 1 deletion decompress/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bzip2 = { version = "0.4.3", optional = true }
flate2 = { version = "1.0.25", optional = true }
xz = { version = "0.1.0", optional = true }
zstd = { version = "0.12.0", optional = true }
unrar = { version = "0.4.4", optional = true }
unrar = { version = "0.5.6", optional = true }
infer = "0.12.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion decompress/src/decompressors/ar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::decompressors::utils::normalize_mode;
use crate::{DecompressError, Decompression, Decompressor, ExtractOpts, Listing};
use ar::Archive;
use lazy_static::lazy_static;
Expand Down Expand Up @@ -130,6 +129,7 @@ impl Decompressor for Ar {

#[cfg(unix)]
{
use crate::decompressors::utils::normalize_mode;
use std::os::unix::fs::PermissionsExt;
let mode = normalize_mode(mode);
fs::set_permissions(&outpath, fs::Permissions::from_mode(mode))?;
Expand Down
2 changes: 1 addition & 1 deletion decompress/src/decompressors/tar_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
path::{Path, PathBuf},
};

use crate::decompressors::utils::normalize_mode;
use crate::{DecompressError, ExtractOpts};
use tar::Archive;

Expand Down Expand Up @@ -71,6 +70,7 @@ pub fn tar_extract(

#[cfg(unix)]
{
use crate::decompressors::utils::normalize_mode;
use std::os::unix::fs::PermissionsExt;
if let Ok(mode) = h {
let mode = normalize_mode(mode);
Expand Down
53 changes: 28 additions & 25 deletions decompress/src/decompressors/unrar.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use lazy_static::lazy_static;
use regex::Regex;
use std::path::Path;
use unrar::FileHeader;

use crate::{DecompressError, Decompression, Decompressor, ExtractOpts, Listing};

macro_rules! check {
($e : expr) => {
$e.map_err(|e| crate::DecompressError::Error(e.to_string()))?
};
}

lazy_static! {
static ref RE: Regex = Regex::new(r"(?i)\.rar$").unwrap();
}
Expand All @@ -21,6 +28,14 @@ impl Unrar {
pub fn build(re: Option<Regex>) -> Box<Self> {
Box::new(Self::new(re))
}

fn get_entry_path(entry: &FileHeader) -> String {
let mut s = entry.filename.to_string_lossy().into_owned();
if entry.is_directory() && !s.ends_with('/') {
s.push('/');
}
s
}
}

impl Decompressor for Unrar {
Expand All @@ -36,19 +51,12 @@ impl Decompressor for Unrar {
}

fn list(&self, archive: &Path) -> Result<Listing, DecompressError> {
let res = unrar::Archive::new(archive.to_string_lossy().to_string())
.list()
.map_err(|e| DecompressError::Error(e.to_string()))?
.process()
.map_err(|e| DecompressError::Error(e.to_string()))?;

Ok(Listing {
id: "rar",
entries: res
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<_>>(),
})
let rar = check!(unrar::Archive::new(archive).open_for_listing());
let entries = rar
.into_iter()
.map(|e| Ok(Self::get_entry_path(&check!(e))))
.collect::<Result<Vec<_>, DecompressError>>()?;
Ok(Listing { id: "rar", entries })
}

fn decompress(
Expand All @@ -62,18 +70,13 @@ impl Decompressor for Unrar {
fs::create_dir_all(to)?;
}

let res = unrar::Archive::new(archive.to_string_lossy().to_string())
.extract_to(to.to_string_lossy().to_string())
.map_err(|e| DecompressError::Error(e.to_string()))?
.process()
.map_err(|e| DecompressError::Error(e.to_string()))?;
let mut rar = check!(unrar::Archive::new(archive).open_for_processing());
let mut files = Vec::new();
while let Some(header) = check!(rar.read_header()) {
files.push(Self::get_entry_path(header.entry()));
rar = check!(header.extract_with_base(to));
}

Ok(Decompression {
id: "rar",
files: res
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<_>>(),
})
Ok(Decompression { id: "rar", files })
}
}
1 change: 1 addition & 0 deletions decompress/src/decompressors/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(unix)]
pub fn normalize_mode(mode: u32) -> u32 {
if mode == 0 {
0o644
Expand Down
6 changes: 2 additions & 4 deletions decompress/src/decompressors/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use lazy_static::lazy_static;
use regex::Regex;
use zip::ZipArchive;

use crate::{
decompressors::utils::normalize_mode, DecompressError, Decompression, Decompressor,
ExtractOpts, Listing,
};
use crate::{DecompressError, Decompression, Decompressor, ExtractOpts, Listing};

lazy_static! {
static ref RE: Regex = Regex::new(r"(?i)\.zip$").unwrap();
Expand Down Expand Up @@ -120,6 +117,7 @@ impl Decompressor for Zip {
// Get and Set permissions
#[cfg(unix)]
{
use crate::decompressors::utils::normalize_mode;
use std::os::unix::fs::PermissionsExt;
if let Some(mode) = file.unix_mode() {
let mode = normalize_mode(mode);
Expand Down
1 change: 0 additions & 1 deletion decompress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ impl Decompress {
let mt = res.map(|t| t.mime_type());
mt.and_then(|mt| self.decompressors.iter().find(|dec| dec.test_mimetype(mt)))
} else {
println!("f: {:?} ", archive.as_ref());
self.decompressors
.iter()
.find(|dec| dec.test(archive.as_ref()))
Expand Down