summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-11-29 16:42:28 -0800
committerJoffrey F <joffrey@docker.com>2017-11-29 16:42:28 -0800
commit5c5705045be72530091a51372ae920f958192bfb (patch)
treed821b7c5be5eef66e259e189fab3171d86b6dd67
parentc7f1b5f84f9b574de370ef0bb00e84ad3b8a556f (diff)
downloaddocker-py-fix-context-building.tar.gz
Fix common issues with build context creation: inaccessible files and fifosfix-context-building
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--docker/utils/utils.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index a123fd8..6cac4bc 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -97,7 +97,12 @@ def create_archive(root, files=None, fileobj=None, gzip=False):
if files is None:
files = build_file_list(root)
for path in files:
- i = t.gettarinfo(os.path.join(root, path), arcname=path)
+ full_path = os.path.join(root, path)
+ if not os.access(full_path, os.R_OK):
+ raise IOError(
+ 'Can not access file in context: {}'.format(full_path)
+ )
+ i = t.gettarinfo(full_path, arcname=path)
if i is None:
# This happens when we encounter a socket file. We can safely
# ignore it and proceed.
@@ -108,12 +113,14 @@ def create_archive(root, files=None, fileobj=None, gzip=False):
# and directories executable by default.
i.mode = i.mode & 0o755 | 0o111
- try:
- # We open the file object in binary mode for Windows support.
- with open(os.path.join(root, path), 'rb') as f:
- t.addfile(i, f)
- except IOError:
- # When we encounter a directory the file object is set to None.
+ if i.isfile():
+ try:
+ with open(full_path, 'rb') as f:
+ t.addfile(i, f)
+ except IOError:
+ t.addfile(i, None)
+ else:
+ # Directories, FIFOs, symlinks... don't need to be read.
t.addfile(i, None)
t.close()
fileobj.seek(0)