GNOME Bugzilla – Bug 777396
AutoarExtractor creates an unnecessary directory for a .xz file without tar or cpio
Last modified: 2017-04-20 20:07:23 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.
Should this filter out all files which return the single entry "data" or are there any other filter parameters?
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.
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).
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.
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.
Review of attachment 347491 [details] [review]: As mentioned on IRC I think we can merge the shared code
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.
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!
Review of attachment 348183 [details] [review]: Looks good now and I could test, thanks!
*** Bug 777814 has been marked as a duplicate of this bug. ***
Attachment 348183 [details] pushed as 1c4fb9f - uncompressing-.xz: use archive name for .xz files