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

3.1 Decompress a tarball while removing a prefix from the paths with E0107 #666

Open
marc47marc47 opened this issue May 30, 2022 · 1 comment · May be fixed by #669
Open

3.1 Decompress a tarball while removing a prefix from the paths with E0107 #666

marc47marc47 opened this issue May 30, 2022 · 1 comment · May be fixed by #669

Comments

@marc47marc47
Copy link

Compiling tar03 v0.1.0 (/Users/marc47/rust/tar03)
error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied
--> src/main.rs:8:14
|
8 | fn main() -> Result<()> {
| ^^^^^^ -- supplied 1 generic argument
| |
| expected 2 generic arguments
|
note: enum defined here, with 2 generic parameters: T, E
--> /Users/marc47/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:503:10
|
503 | pub enum Result<T, E> {
| ^^^^^^ - -
help: add missing generic argument
|
8 | fn main() -> Result<(), E> {
| +++

For more information about this error, try rustc --explain E0107.
error: could not compile tar03 due to previous error

@marc47marc47
Copy link
Author

marc47marc47 commented May 30, 2022

use flate2::read::GzDecoder;
use std::fs::File;
use std::path::PathBuf;
use tar::Archive;

type Result = std::result::Result<T, std::io::Error>; // i add this line to solve this issue

fn main() -> Result<()> {
let file = File::open("archive.tar.gz")?;
let mut archive = Archive::new(GzDecoder::new(file));
let prefix = "bundle/logs";

println!("Extracted the following files:");
archive
    .entries()?
    .filter_map(|e| e.ok())
    .map(|mut entry| -> Result<PathBuf> {
        let path = entry.path()?.strip_prefix(prefix).unwrap().to_owned();
        entry.unpack(&path)?;
        Ok(path)
    })
    .filter_map(|e| e.ok())
    .for_each(|x| println!("> {}", x.display()));

Ok(())

}

@v-i-s-h v-i-s-h linked a pull request Jul 4, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant