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 --format flag #134

Closed
marcospb19 opened this issue Oct 31, 2021 · 7 comments · Fixed by #341
Closed

Add --format flag #134

marcospb19 opened this issue Oct 31, 2021 · 7 comments · Fixed by #341
Labels
enhancement New feature or request high priority

Comments

@marcospb19
Copy link
Member

marcospb19 commented Oct 31, 2021

Problem

Currently, we don't have control of what extensions should be used in compression or decompression, we rely on automatic extension detection.

Using archive.tar.gz.xz as an example, you might want to decompress it into:

archive.tar.gz, without the .xz part, or
archive.tar, without the .gz.xz part.

That is, decompress it partially, or just decompress a file without extensions.

Workaround

Decompress and compress it again.

ouch decompress archive.tar.gz.xz -o result
cd result
ouch compress * .* archive.tar 

Note that the shell expansion .* is necessary in case you have any hidden files.

New solution

--format flag that overwrites the automatic format detection system.

ouch compress file.tar file.tar.xz --format xz
ouch decompress secret_file --format tar.gz

We already have detection on partial compression:

ouch compress file.tar file.tar.xz

Ouch detects it should only partially compress the .xz part, and triggers it, I think this behavior is useful but can be triggered by accident.

We should leave this detection only as a warning to tell the users that if they want to partially compress, they should use the --format flag.

@Artturin
Copy link
Contributor

Artturin commented Nov 26, 2021

+1 i wanted to decompress a zstd initrd but couldn't since it has no extension

file -z $(chase ./result/system/initrd)
/nix/store/gipn2hp41a70bdrzbkcy4dgqxp789z03-initrd-linux-5.10.81/initrd: ASCII cpio archive (SVR4 with no CRC) (Zstandard compressed data (v0.8+), Dictionary ID: None)

@sigmaSd
Copy link
Contributor

sigmaSd commented Nov 26, 2021

@Artturin can you try with master branch? It should infer the extension

@marcospb19
Copy link
Member Author

marcospb19 commented Dec 8, 2021

I will be attempting to solve this now.

@Artturin
Copy link
Contributor

Artturin commented Jan 12, 2022

@Artturin can you try with master branch? It should infer the extension

rev 308b8f7

./result/bin/ouch decompress $(chase /run/current-system/initrd)
[ERROR] Cannot decompress files without extensions
 - Files without supported extensions: /nix/store/c2xv04iimpji7hwd18qnzhcpf1fx2isx-initrd-linux-5.10.90/initrd
 - Decompression formats are detected automatically by the file extension

hint: Provide a file with a supported extension:
hint:   ouch decompress example.tar.gz
hint:
hint: Or overwrite this option with the '--format' flag:
hint:   ouch decompress /nix/store/c2xv04iimpji7hwd18qnzhcpf1fx2isx-initrd-linux-5.10.90/initrd --format tar.gz

--format gives

./result/bin/ouch decompress $(chase /run/current-system/initrd) --format zst
error: Found argument '--format' which wasn't expected, or isn't valid in this context

	If you tried to supply `--format` as a value rather than a flag, use `-- --format`

USAGE:
    ouch decompress [OPTIONS] <FILES>...

For more information try --help

@marcospb19 marcospb19 removed this from the 0.4.0 milestone Jun 8, 2022
@marcospb19
Copy link
Member Author

--format gives

You're right, I had --format unimplemented because I had to stay a little bit away from Ouch.

This is totally broken and needs to be addressed.

@figsoda figsoda added this to the 0.4.0 milestone Oct 16, 2022
@marcospb19 marcospb19 removed this from the 0.4.0 milestone Nov 14, 2022
@marcospb19
Copy link
Member Author

this will require rework on the error handling part, in a medium sized PR, so I'm removing it from the 0.4 milestone just so that we can make the next release

@figsoda
Copy link
Member

figsoda commented Jan 7, 2023

#341

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants