smartfile/python-libarchive

SeekableArchive raises an exception when querying the files a second time

Opened this issue · 0 comments

After opening a SeekableArchive, the contained files can be queried by iterating over it:

echo foo > bar
tar -cjf single-file.tar.bz2 bar
import libarchive  # 4.1.0
a = libarchive.SeekableArchive('single-file.tar.bz2')
print(list(a))  # [<libarchive.Entry at 0x7fed38f9c850>]

But, when trying this a second time, it throws an exception, which isn't what I would expect and which complicates interactive usage by a lot:

print(list(a))
print(list(a))

Exception:

<ipython-input-8-ab50db00fb1d> in <module>
----> 1 print(list(a))

~/.local/lib/python3.10/site-packages/libarchive/__init__.py in __iter__(self)
    677         if not self.eof:
    678             try:
--> 679                 for entry in super(SeekableArchive, self).__iter__():
    680                     self.entries.append(entry)
    681                     yield entry

~/.local/lib/python3.10/site-packages/libarchive/__init__.py in __iter__(self)
    486         while True:
    487             try:
--> 488                 yield self.entry_class.from_archive(self, encoding=self.encoding)
    489             except EOF:
    490                 break

~/.local/lib/python3.10/site-packages/libarchive/__init__.py in from_archive(cls, archive, encoding)
    326         e = _libarchive.archive_entry_new()
    327         try:
--> 328             call_and_check(_libarchive.archive_read_next_header2, archive._a, archive._a, e)
    329             mode = _libarchive.archive_entry_filetype(e)
    330             mode |= _libarchive.archive_entry_perm(e)

~/.local/lib/python3.10/site-packages/libarchive/__init__.py in call_and_check(func, archive, *args)
    111         raise EOF()
    112     else:
--> 113         raise Exception('Problem executing function, message is: %s.' % get_error(archive))
    114 
    115

I think, it should be possible to iterate over the archive how many often the user desires.