Misleading error message when 7z doesn't support rar files
xabbuh opened this issue · comments
On some Linux distributions, the p7zip package is split into separate packages. For example, you can use 7z on Ubuntu after installing the p7zip-full package while you need to also install the p7zip-rar package to be able to extract rar packages. The issue is that 7z only returns a generic fatal error code. Therefore, you'll receive a FileCorruptedException
if rar support is missing while the file itself still is correct.
@xabbuh thank you! Yes, it is something I have to work in to detect supported formats in some of the tools
@raulfraile Yeah, I just stumbled upon this when running the tests yesterday and the error message was a bit confusing. ;) Though I'm not sure about the best fix. If I didn't overlook anything, 7z doesn't provide an option to retrieve a list of supported formats. Parsing the command output might be an option. But it might depend on the user's locale though.
@xabbuh you are right, unfortunately 7zip
does not provide any option to get the list of supported formats, I wonder if the 7z t
command might be used for this. Do you have the output of the command for extracting a rar
file when p7zip-rar
is not installed?
@raulfraile Looks like one could search for "Unsupported Method":
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=de_DE.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)
Processing archive: /home/christian/Symfony/distill/tests/Resources/files/file_ok.rar
Testing 1.txt Unsupported Method
Testing 2.txt Unsupported Method
Testing 3.txt Unsupported Method
Testing level2/4.txt Unsupported Method
Testing level2/level3/5.txt Unsupported Method
Testing level2/level3
Testing level2
Sub items Errors: 5
@xabbuh thanks! Just one more thing... what's the exit code of that command? In OS X I am getting 2
as an exit code for this:
$ 7z t tests/Resources/files/file_ok.phar
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)
Processing archive: tests/Resources/files/file_ok.phar
Error: Can not open file as archive
@raulfraile Yes, it's 2
. According to its man page, 7z sadly only provides 2
as the error code for fatal errors.
@xabbuh can you check if it is fixed? Now I use a few samples of different formats to test if the command supports it, so it should detect if rar
files are supported or not
@raulfraile Seems so:
There was 1 error:
1) Distill\Tests\Method\Command\x7zipTest::testExtractCorrectRarFile
Distill\Exception\Method\FormatNotSupportedInMethodException: Method "commandx7zip" is not supported for format rar
So, the only thing to do would be to skip tests if the format is not supported.
@xabbuh thanks for testing it! Yes, I'll skip the test in that case, but at least I know that detects the support successfully
@raulfraile The test still fails with the error mentioned in my last comment. I'll investigate that this weekend.
@raulfraile see #12