diff options
author | Joffrey F <f.joffrey@gmail.com> | 2018-02-01 17:12:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-01 17:12:45 -0800 |
commit | f00e76cac96cb2c27429faaa6d1e30272cadf2e0 (patch) | |
tree | 57980e95ccb77c6852d68c74af6deb1ce63a3e38 | |
parent | 05d34ed1fbaa8233a4cf51a0f52b67aef99a9521 (diff) | |
parent | 04bf470f6e7e06615be453e1adfe7c656bc5f153 (diff) | |
download | docker-py-f00e76cac96cb2c27429faaa6d1e30272cadf2e0.tar.gz |
Merge pull request #1897 from docker/c5618-negative-mtime-tar
Add workaround for bpo-32713
-rw-r--r-- | docker/utils/utils.py | 4 | ||||
-rw-r--r-- | tests/unit/utils_test.py | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index e4e2c0d..b145f11 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -107,6 +107,10 @@ def create_archive(root, files=None, fileobj=None, gzip=False): # ignore it and proceed. continue + # Workaround https://bugs.python.org/issue32713 + if i.mtime < 0 or i.mtime > 8**11 - 1: + i.mtime = int(i.mtime) + if constants.IS_WINDOWS_PLATFORM: # Windows doesn't keep track of the execute bit, so we make files # and directories executable by default. diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index 1f9daf6..1558891 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -995,6 +995,18 @@ class TarTest(unittest.TestCase): tar_data = tarfile.open(fileobj=archive) assert sorted(tar_data.getnames()) == ['bar', 'foo'] + def tar_test_negative_mtime_bug(self): + base = tempfile.mkdtemp() + filename = os.path.join(base, 'th.txt') + self.addCleanup(shutil.rmtree, base) + with open(filename, 'w') as f: + f.write('Invisible Full Moon') + os.utime(filename, (12345, -3600.0)) + with tar(base) as archive: + tar_data = tarfile.open(fileobj=archive) + assert tar_data.getnames() == ['th.txt'] + assert tar_data.getmember('th.txt').mtime == -3600 + class ShouldCheckDirectoryTest(unittest.TestCase): exclude_patterns = [ |