ouch icon indicating copy to clipboard operation
ouch copied to clipboard

Add `--format` flag

Open marcospb19 opened this issue 4 years ago • 5 comments

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.

marcospb19 avatar Oct 31 '21 18:10 marcospb19

+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)

Artturin avatar Nov 26 '21 17:11 Artturin

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

sigmaSd avatar Nov 26 '21 18:11 sigmaSd

I will be attempting to solve this ~~now~~.

marcospb19 avatar Dec 08 '21 03:12 marcospb19

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

rev 308b8f7e906c57d8da334ae6395aa15ecbdfb2d8

./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

Artturin avatar Jan 12 '22 08:01 Artturin

--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.

marcospb19 avatar Aug 17 '22 22:08 marcospb19

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

marcospb19 avatar Nov 14 '22 21:11 marcospb19

https://github.com/ouch-org/ouch/pull/341

figsoda avatar Jan 07 '23 20:01 figsoda