Bug report
Bug description:
It appears that tarfile.TarFile.addfile() sets neither offset nor offset_data attributes in the TarInfo added to self.members, when it's done adding the file. Members in a reopened TAR have correct values.
Reproducer
from io import BytesIO
from tarfile import TarFile, TarInfo
with TarFile("test.tar", "w") as tar:
data = b"data"
tarinfo = TarInfo("test1.txt")
tarinfo.size = len(data)
tar.addfile(tarinfo, BytesIO(data))
tarinfo = TarInfo("test2.txt")
tarinfo.size = len(data)
tar.addfile(tarinfo, BytesIO(data))
for member in tar.getmembers():
print(member.name, member.offset, member.offset_data)
with TarFile("test.tar", "r") as tar:
for member in tar.getmembers():
print(member.name, member.offset, member.offset_data)
Expected output
test1.txt 0 512
test2.txt 1024 1536
test1.txt 0 512
test2.txt 1024 1536
Actual output
test1.txt 0 0
test2.txt 0 0
test1.txt 0 512
test2.txt 1024 1536
CPython versions tested on:
3.15
Operating systems tested on:
Linux
Bug report
Bug description:
It appears that
tarfile.TarFile.addfile()sets neitheroffsetnoroffset_dataattributes in theTarInfoadded toself.members, when it's done adding the file. Members in a reopened TAR have correct values.Reproducer
Expected output
Actual output
CPython versions tested on:
3.15
Operating systems tested on:
Linux