Unverified Kaydet (Commit) a718ab69 authored tarafından Christian Bundy's avatar Christian Bundy

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: 's avatarChristian Bundy <christianbundy@fraction.io>
üst cbd2ba52
......@@ -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)
......
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