Error when closing any 7z archive
This happens with almost every 7z archive that contains anything.
With archive.7z being an archive in the current directory:
myfs = fs.archive.open_archive(".","archive.7z")
myfs.close()
results in
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 278, in close
self._saver.save(self)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 58, in save
self.to_stream(fs)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 86, in to_stream
self._to(temp, fs)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/sevenzipfs/__init__.py", line 293, in _to
_7z.worker.archive(_7z.fp, _7z.files, folder, deref=_7z.dereference)
File "/home/krateng/.local/lib/python3.10/site-packages/py7zr/py7zr.py", line 1494, in archive
foutsize, crc = self.write(fp, f, (f.is_symlink and not deref), folder)
File "/home/krateng/.local/lib/python3.10/site-packages/py7zr/py7zr.py", line 1460, in write
with f.origin.open(mode="rb") as fd:
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/sevenzipfs/__init__.py", line 37, in open
return self.fs.openbin(self.path, mode)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/wrapfs.py", line 194, in openbin
bin_file = _fs.openbin(_path, mode=mode, buffering=-1, **options)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/wrap.py", line 149, in openbin
return self._rfs.openbin(path, mode, buffering, **options)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/sevenzipfs/__init__.py", line 194, in openbin
return iocursor.Cursor(decompressed[relpath(_path)].getbuffer())
KeyError: 'randomfileinthearchive.ext'
It also happens when I provide a pre-initialized Filesystem object as the parent of the archive fs and when I use context manager instead of manually closing.
If I create a new archive with only one empty file in it, it works. If that file contains anything, it doesn't work anymore.
The same error happens when trying to read a file.
After some initial experimenting, I think this
https://github.com/althonos/fs.archive/blob/7461b6c197a6e3e25b4c25e6c48eca7686562fb1/fs/archive/sevenzipfs/init.py#L183-L194
needs to pass the relpath to _7z.read. This fixes my issues with reading files, but I haven't looked too much into the overall architecture of the whole package, so I don't know if this clashes with something else.
This now also leads to the archive not closing anymore (even nothing has been written to it) - it seems to be stuck endlessly repeating the function
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 278, in close
self._saver.save(self)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 58, in save
self.to_stream(fs)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/base.py", line 86, in to_stream
self._to(temp, fs)
File "/home/krateng/.local/lib/python3.10/site-packages/fs/archive/sevenzipfs/__init__.py", line 294, in _to
_7z.worker.archive(_7z.fp, _7z.files, folder, deref=_7z.dereference)
File "/home/krateng/.local/lib/python3.10/site-packages/py7zr/py7zr.py", line 1494, in archive
foutsize, crc = self.write(fp, f, (f.is_symlink and not deref), folder)
File "/home/krateng/.local/lib/python3.10/site-packages/py7zr/py7zr.py", line 1461, in write
insize, foutsize, crc = compressor.compress(fd, fp)
File "/home/krateng/.local/lib/python3.10/site-packages/py7zr/compressor.py", line 884, in compress
data = compressor.compress(data)