ouch-org / ouch

Painless compression and decompression in the terminal
https://crates.io/crates/ouch
Other
2.24k stars 76 forks source link

Overwrite behavior removes files differently than expected #466

Open jeiea opened 1 year ago

jeiea commented 1 year ago

Version

0.4.1

Description

It looks like ouch is asking the user if they want to overwrite the directory to be unpacked when the contents to be extracted overlap.

I expected it to preserve the original directory contents, but it doesn't. It completely removes the directory contents first. I think the prompt should clarify this behavior (purging the directory) at least, or preserve anything that is unrelated to extraction.

The following is example command.

➜  tmp ouch c 01 a.zip
[INFO] Compressing '01'.
[INFO] Compressing '01/a.txt'.
[INFO] Successfully compressed 'a.zip'.
➜  tmp
➜  tmp ls
01    a.zip
➜  tmp cd 01
➜  01 rm a.txt
➜  01 touch b.txt
➜  01 ..
➜  tmp ouch c 01 b.zip
[INFO] Compressing '01'.
[INFO] Compressing '01/b.txt'.
[INFO] Successfully compressed 'b.zip'.
➜  tmp ls
01    a.zip b.zip
➜  tmp rm -rf 01
➜  tmp ls
a.zip b.zip
➜  tmp ouch d a.zip
[INFO] Created temporary directory /Users/jeiea/tmp/./.tmpn12IYC to hold decompressed elements.
[INFO] File 0 extracted to "/Users/jeiea/tmp/./.tmpn12IYC/01/"
[INFO] ".tmpn12IYC/01/a.txt" extracted. (0B)
[INFO] Successfully moved /Users/jeiea/tmp/./.tmpn12IYC/01 to ./01.
[INFO] Successfully decompressed archive in current directory (2 files).
➜  tmp ls
01    a.zip b.zip
➜  tmp cd 01
➜  01 ls
a.txt
➜  01 cd ..
➜  tmp ouch d b.zip
[INFO] Created temporary directory /Users/jeiea/tmp/./.tmp6qVqif to hold decompressed elements.
[INFO] File 0 extracted to "/Users/jeiea/tmp/./.tmp6qVqif/01/"
[INFO] ".tmp6qVqif/01/b.txt" extracted. (0B)
Do you want to overwrite './01'? [Y/n]
[INFO] Successfully moved /Users/jeiea/tmp/./.tmp6qVqif/01 to ./01.
[INFO] Successfully decompressed archive in current directory (2 files).
➜  tmp cd 01
➜  01 ls
b.txt

Current Behavior

a.txt is deleted.

Expected Behavior

After executing above ls should print a.txt and b.txt.

Additional Information

No response

valoq commented 1 week ago

A different use case where this behavior is relevant, is when decompressing multiple archive files that contain the same directory structure but different files:

Say I have a compressed directory with a series of pdf files that are sorted by topic and split into different compressed files.

Example:

/mathBooks/bookA.pdf
/mathBooks/bookB.pdf
/mathBooks/bookC.pdf

Now I compress this directory and split it three ways, one archive for each book. If I decompress these archives with ouch, I will only receive /mathBooks/bookC.pdf Since all archives share the same directory name mathBooks, all files of the previously decompressed archives are deleted, even though they do not contain any conflicting files.

Expected Behavior When no conflicting files are present, the decompressed directories should be merged by default. (This seems to be the default for other decompression tools as well.)