Skip to content

tarfile.py: TarFile.addfile not adding all files #116931

Closed
@elehcimd

Description

@elehcimd

Bug report

Bug description:

I would expect both files A and B to be stored in the tar file. However, only A is archived.

# creating the test directory
!rm -rf test1.tar test1
!mkdir test1
!echo thisisa >test1/A
!echo thisisb >test1/B
import tarfile
archive = tarfile.open("test1.tar", mode="w", format=tarfile.GNU_FORMAT)
archive.addfile(archive.gettarinfo(name="test1/A"))
archive.addfile(archive.gettarinfo(name="test1/B"))
archive.close()
print(tarfile.open("test1.tar", mode="r").getnames())

Expected output:

['test1/A', 'test1/B']

Returned output:

['test1/A']

Reproduced on these Python versions:

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

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions