Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Package: Update zip file creation
  • Loading branch information
UK992 committed Dec 1, 2018
1 parent f4d3d8e commit c4b5c94
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions python/servo/command_base.py
Expand Up @@ -21,6 +21,7 @@
from subprocess import PIPE
import sys
import tarfile
import zipfile
from xml.etree.ElementTree import XML
from servo.util import download_file
import urllib2
Expand Down Expand Up @@ -85,10 +86,14 @@ def reset(tarinfo):
dest_archive = os.path.abspath(dest_archive)
with cd(dir_to_archive):
current_dir = "."
file_list = [current_dir]
file_list = []
for root, dirs, files in os.walk(current_dir):
for name in itertools.chain(dirs, files):
file_list.append(os.path.join(root, name))
if dest_archive.endswith(".zip"):
for f in files:
file_list.append(os.path.join(root, f))
else:
for name in itertools.chain(dirs, files):
file_list.append(os.path.join(root, name))

# Sort file entries with the fixed locale
with setlocale('C'):
Expand All @@ -99,13 +104,21 @@ def reset(tarinfo):
# TODO do this in a temporary folder after #11983 is fixed
temp_file = '{}.temp~'.format(dest_archive)
with os.fdopen(os.open(temp_file, os.O_WRONLY | os.O_CREAT, 0644), 'w') as out_file:
with gzip.GzipFile('wb', fileobj=out_file, mtime=0) as gzip_file:
with tarfile.open(fileobj=gzip_file, mode='w:') as tar_file:
if dest_archive.endswith('.zip'):
with zipfile.ZipFile(temp_file, 'w', zipfile.ZIP_DEFLATED) as zip_file:
for entry in file_list:
arcname = entry
if prepend_path is not None:
arcname = os.path.normpath(os.path.join(prepend_path, arcname))
tar_file.add(entry, filter=reset, recursive=False, arcname=arcname)
zip_file.write(entry, arcname=arcname)
else:
with gzip.GzipFile('wb', fileobj=out_file, mtime=0) as gzip_file:
with tarfile.open(fileobj=gzip_file, mode='w:') as tar_file:
for entry in file_list:
arcname = entry
if prepend_path is not None:
arcname = os.path.normpath(os.path.join(prepend_path, arcname))
tar_file.add(entry, filter=reset, recursive=False, arcname=arcname)
os.rename(temp_file, dest_archive)


Expand Down

0 comments on commit c4b5c94

Please sign in to comment.