diff options
author | Joffrey F <f.joffrey@gmail.com> | 2016-09-27 15:47:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-27 15:47:22 -0700 |
commit | 52c2cc845346884218f566eeaeee5a5ca3e714ab (patch) | |
tree | 6069115d98304b3a7f518f28bf1ddb7f93fc1bb3 | |
parent | 803ff5030e1977e49bca7feea02d74afeabd6356 (diff) | |
parent | a718ab690e3b97c5c9ae4a9697ed2511f4c6f7dd (diff) | |
download | docker-py-52c2cc845346884218f566eeaeee5a5ca3e714ab.tar.gz |
Merge pull request #1228 from christianbundy/synthesize-execute-bit
Synthesize execute permission bit
-rw-r--r-- | docker/utils/utils.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index d46f8fc..b565732 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -4,6 +4,7 @@ import os import os.path import json import shlex +import sys import tarfile import tempfile import warnings @@ -92,7 +93,21 @@ def tar(path, exclude=None, dockerfile=None, fileobj=None, gzip=False): exclude = exclude or [] for path in sorted(exclude_paths(root, exclude, dockerfile=dockerfile)): - t.add(os.path.join(root, path), arcname=path, recursive=False) + i = t.gettarinfo(os.path.join(root, path), arcname=path) + + if sys.platform == 'win32': + # Windows doesn't keep track of the execute bit, so we make files + # and directories executable by default. + i.mode = i.mode & 0o755 | 0o111 + + try: + # We open the file object in binary mode for Windows support. + f = open(os.path.join(root, path), 'rb') + except IOError: + # When we encounter a directory the file object is set to None. + f = None + + t.addfile(i, f) t.close() fileobj.seek(0) |