diff options
author | Christian Bundy <christianbundy@fraction.io> | 2016-09-27 00:56:12 +0000 |
---|---|---|
committer | Christian Bundy <christianbundy@fraction.io> | 2016-09-27 21:39:30 +0000 |
commit | a718ab690e3b97c5c9ae4a9697ed2511f4c6f7dd (patch) | |
tree | 6069115d98304b3a7f518f28bf1ddb7f93fc1bb3 | |
parent | cbd2ba52af076219198a002533ac75fcd75a1ca3 (diff) | |
download | docker-py-a718ab690e3b97c5c9ae4a9697ed2511f4c6f7dd.tar.gz |
Pass file object to Tarfile.addfile()
This resolves an issue where TarFile.gettarinfo() doesn't include the
file object, meaning that TarFile.addfile(TarFile.gettarinfo()) doesn't
pass the test suite. Instead, this uses an open() within a try...except
block to include a file object for each file without passing a file
object when the path is a directory.
Signed-off-by: Christian Bundy <christianbundy@fraction.io>
-rw-r--r-- | docker/utils/utils.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py index 62e06a2..b565732 100644 --- a/docker/utils/utils.py +++ b/docker/utils/utils.py @@ -94,9 +94,20 @@ def tar(path, exclude=None, dockerfile=None, fileobj=None, gzip=False): for path in sorted(exclude_paths(root, exclude, dockerfile=dockerfile)): 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 - t.addfile(i) + + 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) |