Merge pull request #1228 from christianbundy/synthesize-execute-bit

Synthesize execute permission bit
This commit is contained in:
Joffrey F 2016-09-27 15:47:22 -07:00 committed by GitHub
commit 52c2cc8453
1 changed files with 16 additions and 1 deletions

View File

@ -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)