Skip to content
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

Fix bug in merged tars with big file names on Python 3.8 #204

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(self,
# Instead, we manually re-implement gzopen from tarfile.py and set mtime.
self.fileobj = gzip.GzipFile(
filename=name, mode='w', compresslevel=9, mtime=self.default_mtime)
self.tar = tarfile.open(name=name, mode=mode, fileobj=self.fileobj)
self.tar = tarfile.open(name=name, mode=mode, fileobj=self.fileobj, format=tarfile.GNU_FORMAT)
self.members = set([])
self.directories = set([])

Expand Down
2 changes: 1 addition & 1 deletion pkg/make_deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def CreateDebControl(extrafiles=None, **kwargs):
# Create the control.tar file
tar = BytesIO()
with gzip.GzipFile('control.tar.gz', mode='w', fileobj=tar, mtime=0) as gz:
with tarfile.open('control.tar.gz', mode='w', fileobj=gz) as f:
with tarfile.open('control.tar.gz', mode='w', fileobj=gz, format=tarfile.GNU_FORMAT) as f:
tarinfo = tarfile.TarInfo('./control')
control_file_data = controlfile.encode('utf-8')
tarinfo.size = len(control_file_data)
Expand Down
13 changes: 13 additions & 0 deletions pkg/tests/archive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ def testMergeTarRelocated(self):
f.add_tar(datafile, name_filter=lambda n: n != "./b", root="/foo")
self.assertTarFileContent(self.tempfile, content)

def testMergeTarRelocatedBigNames(self):
content = [
{"name": ".", "mode": 0o755},
{"name": "./foo", "mode": 0o755},
{"name": "./foo/ninety-eight-characters-seems-to-be-the-maximum-limit-for-merged-tarballs-in-the-rules_pkg-for-bzl", "data": b"1"},
{"name": "./foo/ninety-eight-characters-seems-to-be-the-maximum-limit-for-merged-tarballs-in-the-rules_pkg-for-bzl-", "data": b"1"},
]
with archive.TarFileWriter(self.tempfile) as f:
datafile = self.data_files.Rlocation(
os.path.join("rules_pkg", "tests", "testdata", "big-names.tar"))
f.add_tar(datafile, root="/foo")
self.assertTarFileContent(self.tempfile, content)

def testDefaultMtimeNotProvided(self):
with archive.TarFileWriter(self.tempfile) as f:
self.assertEqual(f.default_mtime, 0)
Expand Down
Binary file added pkg/tests/testdata/big-names.tar
Binary file not shown.