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

Overwrite behavior removes files differently than expected #466

Open
jeiea opened this issue Jul 21, 2023 · 2 comments
Open

Overwrite behavior removes files differently than expected #466

jeiea opened this issue Jul 21, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@jeiea
Copy link

jeiea commented Jul 21, 2023

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

@jeiea jeiea added the bug Something isn't working label Jul 21, 2023
@valoq
Copy link
Contributor

valoq commented Oct 9, 2024

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

@marcospb19
Copy link
Member

marcospb19 commented Oct 26, 2024

Thanks for the issue.

I ran a poll, and most people agree that merging folders is the most intuitive behavior.

This should be an easy change in the code side, we just need to skip trying to overwrite the folder when unpacking an archive.

I think doing this will also prevent Ouch from trying to overwrite the current folder entirely, which is rare to do but might be possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants