avocado-framework / avocado

Avocado is a set of tools and libraries to help with automated testing. One can call it a test framework with benefits. Native tests are written in Python and they follow the unittest pattern, but any executable can serve as a test.
https://avocado-framework.github.io/
Other
342 stars 340 forks source link

utils/archive: support for detecting archive files without proper extensions #5997

Open clebergnu opened 2 months ago

clebergnu commented 2 months ago

Is your feature request related to a problem? Please describe. Currently, support for opening archive files is based on a table that maps extensions to some metadata like them either them being a "zip" or a "tar" file. This does not take into consideration the other types of archive supported, and also fails to support files without extensions.

Describe the solution you'd like It should be possible to open an archive file such as:

$ tar cf /tmp/tarfile /etc/issue

And while is_archive() behaves as expected:

>>> archive.is_archive('/tmp/tarfile')
True

The more important extract() does not:

archive.extract('/tmp/tarfile', '/tmp')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cleber/src/avocado/avocado/avocado/utils/archive.py", line 366, in uncompress
    with ArchiveFile.open(filename) as x:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/cleber/src/avocado/avocado/avocado/utils/archive.py", line 225, in open
    return cls(filename, mode)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/cleber/src/avocado/avocado/avocado/utils/archive.py", line 205, in __init__
    raise ArchiveException("file is not an archive")
avocado.utils.archive.ArchiveException: file is not an archive

Describe alternatives you've considered Requiring users to properly name files, but this is sometimes not possible or just an annoyance. Also the extension table is really not mapping well to the supported archive formats.