-
Notifications
You must be signed in to change notification settings - Fork 11
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
Opening the same file for the second time via SeekableArchive raises a RuntimeError #23
Comments
Actually, it is even worse. I am not able to open a file inside the archive a second time: import libarchive
a = libarchive.SeekableArchive('single-file.tar.bz2')
files = list(a)
with a.readstream(files[0].pathname) as f:
print(f.read(2)) # "fo"
with a.readstream(files[0].pathname) as f:
print(f.read(2)) # "o\n" would have expected "fo"!!
with a.readstream(files[0].pathname) as f:
print(f.read(2)) # RuntimeError!! The RuntimeError is the same as above. Weirdly enough it even works with an archive with two files where I first open the file appearing later in the archive and then the one appearing before it. But, then again, opening any of the files a second time leads to an exception again. echo foo > bar
echo foo2 > bar2
tar -cf two-files.tbz2 bar bar2 a = libarchive.SeekableArchive('two-files.tar.bz2')
files = list(a)
print(a.readstream(files[1].pathname).read()) # b'foo2\n'
print(a.readstream(files[0].pathname).read()) # b'foo\n'
print(a.readstream(files[0].pathname).read()) # RuntimeError
print(a.readstream(files[1].pathname).read()) # b'foo2\n'
print(a.readstream(files[1].pathname).read()) # RuntimeError
print(a.readstream(files[1].pathname).read()) # RuntimeError
print(a.readstream(files[0].pathname).read()) # b'foo\n'
print(a.readstream(files[0].pathname).read()) # RuntimeError
print(a.readstream(files[1].pathname).read()) # b'foo2\n'
|
Hi, Could we reopen this? Im still experiencing the same issue, with: # python-libarchive == 4.2.1
print(libarchive.version()) # 3.6.1 The issue is that both
file= libarchive.SeekableArchive('updated-file.tar.bz2')
print([f.pathname for f in file]) # ['bar'']
print([f.pathname for f in file]) # ['bar', 'bar']
# RuntimeError: could not read requested data. ==========
This might need further investigation. |
What I'm trying to do is open a file object to a file inside an archive and read from it. And when seeking back, I'm trying to reopen it from the start. My first guess was to simply class
close
on the file object and open it anew, but the second open throws.The problem seems to be that the close on the file object for one of the many files inside the archive will actually close the whole archive. This is unexpected and the missingArchive.close
method only adds to the confusion.The close method actually only calls a deferred close according to the source code. I'm not sure how well behaved that is, especially when calling readstream multiple times and having multiple of those file objects open at the same time ...
Workflow:
Looking at the code, the context manager for
EntryReadStream
should behave correctly, i.e., not callclose
but I can't use it because the lifetime is longer than a simple with-code-block and Python has no C++ like RAII unfortunately.The text was updated successfully, but these errors were encountered: