You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python 3.11.6 (main, Nov 28 2023, 09:22:32) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
gettarinfo() creates a TarInfo object from the result of os.stat(). In particularly it sets the size of a TarInfo object.
addfile() usually takes two arguments: a TarInfo object and a file-like object. It writes a header, taking name, size, and other attributes from the TarInfo object, and then copies the content of the file-like object (with a padding if necessary). When the file does not have content (empty file, directory, other nodes) the second argument is omitted.
So you wrote a header for the first file, but not its content. Then you wrote the header for the second file which was interpreted as the content of the first file.
There is perhaps a lack of documentation, but I think that TarFile should detect such errors and raise an exception. Not writing a content for a non-empty member is an error. Writing a wrong amount of data is also an error.
Tarfile.addfile now throws an ValueError when the user passes
in a non-zero size tarinfo but does not provide a fileobj,
instead of writing an incomplete entry.
Bug report
Bug description:
I would expect both files
A
andB
to be stored in the tar file. However, onlyA
is archived.Expected output:
Returned output:
Reproduced on these Python versions:
CPython versions tested on:
3.11
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: