Bug 362479 - [unrar] Ark extracts files into wrong subdirectory when subdirectories of same name are present
Summary: [unrar] Ark extracts files into wrong subdirectory when subdirectories of sam...
Status: CONFIRMED
Alias: None
Product: ark
Classification: Applications
Component: plugins (show other bugs)
Version: 22.04.1
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Ragnar Thomsen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-29 21:29 UTC by Zoidberg
Modified: 2022-06-01 16:46 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Console output from Ark (11.39 KB, text/plain)
2016-04-30 17:32 UTC, Zoidberg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zoidberg 2016-04-29 21:29:57 UTC
I have several archives (in that case .rar, but it seems to happen with other types) which contain 2 directories (e.g. dirA and dirB) with numerous files in each.
I'd like to extract them into a nested directory structure containing directories of the same name in a way that Ark writes into the existing directories:
e.g. /maindir/subdir/ contains dirA and dirB, I tell Ark to extract into "subdir/" (unchecking the "create subfolder" box).
Instead of extracting the files form archive.rar/dirA into /dirA/ (and dirB respecitvely), it unpacks both dirA and dirB as subfolders into dirA (i.e. afterwards I have */dirA/dirA and */dirA/dirB)

Reproducible: Always

Steps to Reproduce:
1. Unpack archive with folder structure into directories containing subdirectory of same name as folders in archive


Actual Results:  
Directory structure is extracted not into the chosen folder, but into one of the homonymous subdirectories inside the folder

Expected Results:  
The files in the folders inside the archive should be written into the respective folders in the directory which has been chosen for extraction, merging the content of the folders from the archive and the folders from the extraction target.
Comment 1 Elvis Angelaccio 2016-04-30 14:54:38 UTC
Hi,
I have just tried on Ark 16.04 and I cannot reproduce. The files are "merged" into the existing folders dirA and dirB, as you was expecting.
This is with a rar archive.


(In reply to Zoidberg from comment #0)

> e.g. /maindir/subdir/ contains dirA and dirB, I tell Ark to extract into
> "subdir/"

Are you 100% sure about this? Maybe just told Ark to extract into "subdir/dirA/" ?
Comment 2 Zoidberg 2016-04-30 15:03:55 UTC
> I have just tried on Ark 16.04 and I cannot reproduce. 

Hello and thank you for the reply! 
I'm using Ark 15.12.3 which is shipped with Kubuntu 16.04.
Maybe this bug is not (or no longer) present in Ark 16.04 then?

> Are you 100% sure about this? Maybe just told Ark to extract into
> "subdir/dirA/" ?

Yes, of that I'm sure. I have extracted about 8 archives of the same structure (to be precise, texture mods for Morrowind, containing the folders "Textures" and "Meshes"), everytime choosing to extract into a folder containing the respective subfolders (i.e. the folder "Data Files", which itself contains "Textures" and "Meshes").
The files were always extracted into folders inside the subfolder (i.e. creating new folders "Meshes" and "Textures" INSIDE "Meshes", rather than merging the folders).

I don't know what I could do differently here.
Comment 3 Elvis Angelaccio 2016-04-30 15:15:00 UTC
I can try to check on Ark 15.12 as well. In the meantime, can you check your version of unrar? (assuming that ark is using unrar to unpack rar archives, which it should be the case)
Comment 4 Elvis Angelaccio 2016-04-30 15:57:17 UTC
I just tried with Ark 15.12.3 and I cannot reproduce either.

To check your unrar version, just run "unrar | head -2" from Konsole.
Comment 5 Zoidberg 2016-04-30 16:42:41 UTC
UNRAR 5.30 beta 2 freeware 

Also, I just checked again and it still happens the same.

I even made a new folder called "Test" and created two empty folders ("Meshes" and "Textures") inside, then opened one of the .rar archives, choose "Extract", select the Folder "Test", uncheck "create subfolder" (which would just create a folder with the name of the archive) and voilà, I again have the two folders INSIDE the original Meshes folder.

Could it be that it's a bug caused by some older component of KDE in Kubuntu 16.04?
Here's what I get from the About menu:

KDE Frameworks 5.18.0
Qt 5.5.1

However, I did now also try to extract the archive and repackage it as .tar.gz, then used that with the same procedure and this seems to work as expected! 
So maybe it's an issue with unrar after all?

Btw.: Here are the respective rar archives:
http://mw.modhistory.com/download-44-14107
Comment 6 Elvis Angelaccio 2016-04-30 17:06:32 UTC
(In reply to Zoidberg from comment #5)
> UNRAR 5.30 beta 2 freeware 

That's weird, this should be the same version I have... 

Can you try again running Ark from terminal with debug output enabled?

$ export QT_LOGGING_RULES=ark.*.debug=true
$ /usr/bin/ark
Comment 7 Zoidberg 2016-04-30 17:32:36 UTC
Created attachment 98712 [details]
Console output from Ark
Comment 8 Elvis Angelaccio 2016-04-30 17:48:43 UTC
I was finally able to reproduce it (thanks to Ragnar for the steps!).
I was always extracting the whole archive, while the bug is triggered only when selecting the Textures and Meshes folders before performing the extraction.
Comment 9 Zoidberg 2016-04-30 18:02:27 UTC
Indeed. :D
I hadn't mentioned that I had selected the folders in the archives, since they usually contained a text file I had no interest in. I just considered that to be unimportant, when it was apparently crucial to replicate the bug.
Comment 10 Ragnar Thomsen 2016-04-30 18:06:53 UTC
We'll try to get this fixed in the 16.04 series. Meanwhile as a temporary workaround you can just drag the folders to the destination. This should work.
Comment 11 Zoidberg 2016-04-30 19:15:47 UTC
Yes, this seems to provide a workaround.
Thanks a lot!
Comment 12 mrfrh 2022-05-31 19:45:32 UTC
I tried to investigate this bug and think that this is caused by inconsistent behavior of unrar. I also submitted my findings to rarlab.

Independently of Ark, when using unrar to unpack an archive into a target_directory that already contains the same subdirectory as the archive (with all files/directories listed in the unrar-command), the archive will not be unpacked to the target_directory, but to the first subdirectory "target_directory/subdirectory".

Example Archive to reproduce:
dirA\A1.txt
dirA\A2.txt
dirB\B1.txt
dirB\B2.txt

Unpacking via "unrar x -kb -p- /home/user/archive.rar dirA dirB dirA/A1.txt dirA/A2.txt dirB/B1.txt dirB/B2.txt /home/user/target_directory" will unpack all files into "/home/user/target_directory/dirA"
Expected result: files should be unpacked to "/home/user/target_directory" and not into the subdirectory "dirA".

By the way, everything works as expected when unpacking all directories and files one by one so this could be a workaround in this case:
"unrar x -kb /home/user/archive.rar dirA /home/user/target_directory"
"unrar x -kb /home/user/archive.rar dirB /home/user/target_directory"
"unrar x -kb /home/user/archive.rar dirA/A1.txt /home/user/target_directory"
...
Comment 13 mrfrh 2022-06-01 16:26:40 UTC
After feedback by rarlab, this issue is caused by a missing trailing backslash for the target directory. 
Since ark doesn't add a trailing slash for the target directory, unrar can't be sure that it is the target directory. So it checks if any of the specified parameters is an existing directory --> then everything is extracted into the first valid directory = dirA.

So this is what ark does right now (and what reproduces the bug): 
unrar x -kb -p- /home/user/archive.rar dirA dirB dirA/A1.txt dirA/A2.txt dirB/B1.txt dirB/B2.txt /home/user/target_directory

With a trailing backslash for the target directory, everything works as expected:
unrar x -kb -p- /home/user/archive.rar dirA dirB dirA/A1.txt dirA/A2.txt dirB/B1.txt dirB/B2.txt /home/user/target_directory/