Unverified Kaydet (Commit) d8f996f9 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #1825 from docker/fix-context-building

Fix common issues with build context creation: inaccessible files and FIFOs
...@@ -97,7 +97,12 @@ def create_archive(root, files=None, fileobj=None, gzip=False): ...@@ -97,7 +97,12 @@ def create_archive(root, files=None, fileobj=None, gzip=False):
if files is None: if files is None:
files = build_file_list(root) files = build_file_list(root)
for path in files: 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: if i is None:
# This happens when we encounter a socket file. We can safely # This happens when we encounter a socket file. We can safely
# ignore it and proceed. # ignore it and proceed.
...@@ -108,12 +113,14 @@ def create_archive(root, files=None, fileobj=None, gzip=False): ...@@ -108,12 +113,14 @@ def create_archive(root, files=None, fileobj=None, gzip=False):
# and directories executable by default. # and directories executable by default.
i.mode = i.mode & 0o755 | 0o111 i.mode = i.mode & 0o755 | 0o111
try: if i.isfile():
# We open the file object in binary mode for Windows support. try:
with open(os.path.join(root, path), 'rb') as f: with open(full_path, 'rb') as f:
t.addfile(i, f) t.addfile(i, f)
except IOError: except IOError:
# When we encounter a directory the file object is set to None. t.addfile(i, None)
else:
# Directories, FIFOs, symlinks... don't need to be read.
t.addfile(i, None) t.addfile(i, None)
t.close() t.close()
fileobj.seek(0) fileobj.seek(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment