Skip to content

Commit a60011c

Browse files
committed
Add workaround for bpo-32713
Signed-off-by: Joffrey F <[email protected]>
1 parent 91bc75c commit a60011c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docker/utils/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def create_archive(root, files=None, fileobj=None, gzip=False):
107107
# ignore it and proceed.
108108
continue
109109

110+
# Workaround https://bugs.python.org/issue32713
111+
if i.mtime < 0 or i.mtime > 8**11 - 1:
112+
i.mtime = int(i.mtime)
113+
110114
if constants.IS_WINDOWS_PLATFORM:
111115
# Windows doesn't keep track of the execute bit, so we make files
112116
# and directories executable by default.

tests/unit/utils_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,18 @@ def test_tar_socket_file(self):
995995
tar_data = tarfile.open(fileobj=archive)
996996
assert sorted(tar_data.getnames()) == ['bar', 'foo']
997997

998+
def tar_test_negative_mtime_bug(self):
999+
base = tempfile.mkdtemp()
1000+
filename = os.path.join(base, 'th.txt')
1001+
self.addCleanup(shutil.rmtree, base)
1002+
with open(filename, 'w') as f:
1003+
f.write('Invisible Full Moon')
1004+
os.utime(filename, (12345, -3600.0))
1005+
with tar(base) as archive:
1006+
tar_data = tarfile.open(fileobj=archive)
1007+
assert tar_data.getnames() == ['th.txt']
1008+
assert tar_data.getmember('th.txt').mtime == -3600
1009+
9981010

9991011
class ShouldCheckDirectoryTest(unittest.TestCase):
10001012
exclude_patterns = [

0 commit comments

Comments
 (0)