Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SeekableArchive raises an exception when querying the files a second time #22

Open
mxmlnkn opened this issue Aug 13, 2022 · 0 comments
Open

Comments

@mxmlnkn
Copy link

mxmlnkn commented Aug 13, 2022

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.

@mxmlnkn mxmlnkn changed the title Usability of the interface SeekableArchive raises an exception when querying the files a second time Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant