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

add ide-specific settings to .gitignore and simply implement 7z #393

Closed
wants to merge 22 commits into from

Conversation

MisileLab
Copy link
Contributor

@MisileLab MisileLab commented Apr 2, 2023

fix #164

Description

implement 7z and add .vscode and .idea to .gitignore

todo

  • implement 7z list
  • return error not using unwrap

@MisileLab MisileLab marked this pull request as ready for review April 3, 2023 13:53
@marcospb19
Copy link
Member

Thanks for your contribution! A review will come once one of us finds the time to take a look.

Copy link
Member

@marcospb19 marcospb19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR, there are some changes needed for it to be merged.

In the title you wrote "simply implement 7z", so maybe your plan was to leave this as it is right now, a simpler implementation, if that's the case, I'll ask you to leave the PR open so that anyone can pick from where you left it and finish it, otherwise, you're more than welcome to finish it yourself.

src/commands/mod.rs Outdated Show resolved Hide resolved
src/commands/decompress.rs Outdated Show resolved Hide resolved
src/commands/decompress.rs Outdated Show resolved Hide resolved
src/commands/list.rs Outdated Show resolved Hide resolved
src/commands/compress.rs Outdated Show resolved Hide resolved
src/commands/list.rs Outdated Show resolved Hide resolved
@marcospb19
Copy link
Member

I've asked for a review from Figsoda because unfortunately I've been busy (and kinda exhausted), but he's also kinda busy so maybe this will have to wait.

Copy link

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the code and it looks pretty simple and straight forward. If I was the project maintainer I would probably also want to see some lines added in ./tests/integration.rs

Copy link
Member

@marcospb19 marcospb19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final change request.

As @Mic92 mentioned, it's necessary to add 7z to the integration tests file.

src/commands/compress.rs Outdated Show resolved Hide resolved
src/commands/decompress.rs Outdated Show resolved Hide resolved
src/commands/list.rs Outdated Show resolved Hide resolved
@MisileLab
Copy link
Contributor Author

I looked at the code and it looks pretty simple and straight forward. If I was the project maintainer I would probably also want to see some lines added in ./tests/integration.rs

idk how to implement test, I'll add tests/integration.rs when I implement it or someone implement test and comment it

@marcospb19
Copy link
Member

marcospb19 commented May 11, 2023

Thanks for sticking to this! It's looking great!

EDIT: removed reference, it looks misleading.

@figsoda
Copy link
Member

figsoda commented May 24, 2023

added 7z to tests, but I kept running into this error

thread \'main\' panicked at \'StripPrefix Failed: StripPrefixError(())\', src/archive/sevenz.rs:17:26

Comment on lines 7 to 29
pub fn compress_sevenz(files: Vec<PathBuf>, output_path: &Path) -> crate::Result<bool> {
let mut writer = sevenz_rust::SevenZWriter::create(output_path).map_err(crate::Error::SevenzipError)?;

for filep in files.iter() {
writer
.push_archive_entry::<std::fs::File>(
sevenz_rust::SevenZWriter::<std::fs::File>::create_archive_entry(
filep,
filep
.strip_prefix(current_dir()?)
.expect("StripPrefix Failed")
.as_os_str()
.to_str()
.unwrap()
.to_string(),
),
None,
)
.map_err(crate::Error::SevenzipError)?;
}

writer.finish()?;
Ok(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in line 17 of this big oneliner.

@MisileLab
Copy link
Contributor Author

i don't know how to fix it and I have a no time for now, anyone can contribute this pull request!

@marcospb19
Copy link
Member

@MisileLab thanks for your hard-work! I might be able to pick it up soon.

@AntoniosBarotsis
Copy link
Contributor

AntoniosBarotsis commented Aug 18, 2023

I saw that tar uses strip_cur_dir instead of something like filep.strip_prefix(current_dir()?) where the issue was in the 7z code.

Switching to that does solve the panic (I can now manually compress and decompress 7z archives from the cli) however it does not fix all the tests. Using strip_cur_dir in my case did not change the file path but instead kept it the same (again, the resulting behaviour worked as expected though). I'm not sure if this was not used on purpose or if using it is a bad idea for some reason so do let me know, if its not then I can push the commit 😅

Another thing that was surprising was when decompressing an archive that was compressed by ouch I get the following log:

$ cargo r -- d tmp.7z
[INFO] Could not detect the extension of `tmp`

This was interesting because it did decompress correctly. The bytes here seem to agree with Wikipedia so not sure why it fails to detect it (but somehow still work?).

The following tests are failing:

test single_empty_file ... FAILED
test single_file ... FAILED
test multiple_files ... FAILED

Edit: On closer inspection, upon decompressing a 7z archive, an empty folder with the same name as the initial archive is created in the same directory

Logs:

$ cargo r -- d tmp.7z
[INFO] Could not detect the extension of `tmp`
[INFO] Created temporary directory C:\Users\anton\Documents\Github\ouch\tmp\.\.tmpRCeHQ4 to hold decompressed elements.
[INFO] Successfully moved C:\Users\anton\Documents\Github\ouch\tmp\.\.tmpRCeHQ4 to .\tmp.
[INFO] Successfully decompressed archive in current directory.
[INFO] Files unpacked: 1

@zzzsyyy
Copy link

zzzsyyy commented Sep 19, 2023

will it work? Whats the block so far?

@marcospb19
Copy link
Member

will it work? Whats the block so far?

I believe it will. The current block is: PR is not ready yet, we're waiting for someone to pick it up and spend more time finishing it (and maybe opening another PR based on this branch, but rebased to solve conflicts).

The one who picks it up needs to debug the errors, solve them, and make the tests pass.

tip: .tar and .zip implementations can be used as a reference.

@Flat
Copy link
Contributor

Flat commented Nov 25, 2023

I've started working on this PR hoping to fix the last issues and get it merged, however I seem to be stuck around the same place after re-basing. If we use the original code from this PR, 7zip will fail tests that contain any additional compression on 7z (bz, bz2 gzip, etc) this is the BadSignature error, it has the header bytes of bzip, which suggests it's being passed to the 7z decompression/unpack before it has been fully decompressed from the other algorithms.

If we try the temp file creation that rar uses, nothing is written from the reader to the temp file, which is confusing since attaching lldb I see the reader has data, but it isn't copied.

@marcospb19
Copy link
Member

marcospb19 commented Nov 25, 2023

@Flat

this is the BadSignature error, it has the header bytes of bzip, which suggests it's being passed to the 7z decompression/unpack before it has been fully decompressed from the other algorithms

Does it look like a problem with our code or the 7z crate code?

@Flat
Copy link
Contributor

Flat commented Nov 25, 2023

@Flat

this is the BadSignature error, it has the header bytes of bzip, which suggests it's being passed to the 7z decompression/unpack before it has been fully decompressed from the other algorithms

Does it look like a problem with our code or the 7z crate code?

I may be barking up the wrong tree on that info actually. Doing some more testing and it looks like regular 7z compression fails, due to a symlink I have setup, the file paths passed to archive/compression algorithms are different than the env:current_dir path used in strip_cur_dir. Once I figure that out I'll look more into the compression/decompression chain.

@marcospb19
Copy link
Member

Superseded by #555, thanks @MisileLab and others who gave input here.

@marcospb19 marcospb19 closed this Nov 25, 2023
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 this pull request may close these issues.

Support .7z
7 participants