After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777396 - AutoarExtractor creates an unnecessary directory for a .xz file without tar or cpio
AutoarExtractor creates an unnecessary directory for a .xz file without tar o...
Status: RESOLVED FIXED
Product: gnome-autoar
Classification: Other
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME Autoar maintainer(s)
GNOME Autoar maintainer(s)
: 777814 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-01-17 14:19 UTC by Ting-Wei Lan
Modified: 2017-04-20 20:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
uncompressing-.xz: create different pathname for .xz files (1.37 KB, patch)
2017-03-07 17:26 UTC, Vyas Giridhar
needs-work Details | Review
uncompressing-.xz: use archive name for .xz files (3.49 KB, patch)
2017-03-08 12:36 UTC, Vyas Giridhar
none Details | Review
uncompressing-.xz: use archive name for .xz files (3.64 KB, patch)
2017-03-08 16:42 UTC, Vyas Giridhar
none Details | Review
uncompressing-.xz: use archive name for .xz files (1.71 KB, patch)
2017-03-17 14:50 UTC, Vyas Giridhar
committed Details | Review

Description Ting-Wei Lan 2017-01-17 14:19:03 UTC
We know compression tools like gzip, bzip2, xz, lzma, lzip are usually used together with archiving tools like tar and cpio because they can only handle one file. However, sometimes you want to transfer only one file, you may use those compressing tools without tar or cpio. This kind of compressed files seldom store filenames, and their decompression tools simply decide the name of the output file by removing the extension of the input file.

AutoarExtractor supports them by calling archive_read_support_format_raw when needed. libarchive returns a single entry called 'data' when raw format is used. This causes AutoarExtractor to create an unnecessary directory and put the decompressed file in it.

For example, when we tell AutoarExtractor to extract a file called somefile.xz, it creates:
  new directory - somefile/
  new file      - somefile/data

What it should do is to use the name of the input file and create:
  new file      - somefile

This problem didn't happen in old and unreleased versions made in 2013-2014 because AutoarExtract used to unconditionally change the name of the single top-level file or directory. The behavior was changed because AutoarExtractor was modified to check whether the name of the top-level item matches the name of the input file.
Comment 1 Vyas Giridhar 2017-03-07 16:49:40 UTC
Should this filter out all files which return the single entry "data" or are there any other filter parameters?
Comment 2 Vyas Giridhar 2017-03-07 17:26:33 UTC
Created attachment 347410 [details] [review]
uncompressing-.xz: create different pathname for .xz files

xz files extract as original name/data instead of the original name
libarchive returns a single entry called 'data' when raw format is used.
This causes AutoarExtractor to create an unnecessary directory and put
the decompressed file in it.

This patch checks the entry and sets the resulting filename to the
source file.
Comment 3 Carlos Soriano 2017-03-08 08:23:08 UTC
Review of attachment 347410 [details] [review]:

Hey! Excellent work reading and understanding the code of autoar.
The patch needs work and a different approach, but we will get to it. Here's the review and the approach we should follow:

::: gnome-autoar/autoar-extractor.c
@@ +1597,3 @@
              self->total_files, pathname);
 
+    if (!g_strcmp0(pathname,"data")) {

You are using a logical operator for a rational operation. Use != 0

@@ +1598,3 @@
 
+    if (!g_strcmp0(pathname,"data")) {
+      self->output_is_dest = TRUE;

This is handled in a code where loops on files but you modify the whole extractor for all the files.
Also, what if one of the files in the compressed archive (imagine a tar.xz) has a file that is called "data"? You would wrongly assume it's this case.
Also output_is_dest is something clients of the library set, not that you should modify here against what the client said.

I think what you want here is detect whether the file is in raw data and therefore will only have one file, called "data" (but that would be irrelevant at that point).
So we can take a look at libarchive and see what options do we have to check whether the data is in raw format and act accordingly (probably skipping the whole "while" in here).
Comment 4 Vyas Giridhar 2017-03-08 12:36:48 UTC
Created attachment 347473 [details] [review]
uncompressing-.xz: use archive name for .xz files

.xz files extract as original name/data instead of the original name
libarchive returns a single entry called 'data' when raw format is used.
This causes AutoarExtractor to create an unnecessary directory and put
the decompressed file in it.

This patch checks the entry and sets the resulting filename to the
source file.
Comment 5 Vyas Giridhar 2017-03-08 16:42:28 UTC
Created attachment 347491 [details] [review]
uncompressing-.xz: use archive name for .xz files

.xz files extract as original name/data instead of the original name
libarchive returns a single entry called 'data' when raw format is used.
This causes AutoarExtractor to create an unnecessary directory and put
the decompressed file in it.

This patch checks the entry and sets the resulting filename to the
source file.
Comment 6 Carlos Soriano 2017-03-17 13:49:04 UTC
Review of attachment 347491 [details] [review]:

As mentioned on IRC I think we can merge the shared code
Comment 7 Vyas Giridhar 2017-03-17 14:50:27 UTC
Created attachment 348183 [details] [review]
uncompressing-.xz: use archive name for .xz files

.xz files extract as original name/data instead of the original name
libarchive returns a single entry called 'data' when raw format is used.
This causes AutoarExtractor to create an unnecessary directory and put
the decompressed file in it.

This patch checks the entry and sets the resulting filename to the
source file.
Comment 8 Carlos Soriano 2017-03-28 12:32:28 UTC
Review of attachment 348183 [details] [review]:

So I think the logic of the code is fine now, unfortunately I cannot test right now due to some bug where libarchive fails to decompress xz files now :( So I'll mark as reviewed and come back when I figure out what's going on. Overall, much more improved code now indeed!
Comment 9 Carlos Soriano 2017-04-20 20:04:38 UTC
Review of attachment 348183 [details] [review]:

Looks good now and I could test, thanks!
Comment 10 Carlos Soriano 2017-04-20 20:05:13 UTC
*** Bug 777814 has been marked as a duplicate of this bug. ***
Comment 11 Carlos Soriano 2017-04-20 20:07:20 UTC
Attachment 348183 [details] pushed as 1c4fb9f - uncompressing-.xz: use archive name for .xz files