Fix path separators on Windows in zip_utils
Bug: skia:7077 Change-Id: I5119a7d6c7cd2317129d40ae3e0997dfc9978c25 Reviewed-on: https://skia-review.googlesource.com/52664 Reviewed-by: Ravi Mistry <rmistry@google.com> Commit-Queue: Eric Boren <borenet@google.com>
This commit is contained in:
parent
e4781e934a
commit
097900648b
@ -10,7 +10,9 @@
|
||||
|
||||
|
||||
import fnmatch
|
||||
import ntpath
|
||||
import os
|
||||
import posixpath
|
||||
import zipfile
|
||||
|
||||
|
||||
@ -34,6 +36,9 @@ def zip(target_dir, zip_file, blacklist=None): # pylint: disable=W0622
|
||||
filepath = os.path.join(r, filename)
|
||||
zi = zipfile.ZipInfo(filepath)
|
||||
zi.filename = os.path.relpath(filepath, target_dir)
|
||||
if os.name == 'nt':
|
||||
# Dumb path separator replacement for Windows.
|
||||
zi.filename = zi.filename.replace(ntpath.sep, posixpath.sep)
|
||||
perms = os.stat(filepath).st_mode
|
||||
zi.external_attr = perms << 16L
|
||||
zi.compress_type = zipfile.ZIP_DEFLATED
|
||||
@ -51,8 +56,12 @@ def unzip(zip_file, target_dir):
|
||||
os.makedirs(target_dir)
|
||||
with zipfile.ZipFile(zip_file, 'r', zipfile.ZIP_DEFLATED, True) as z:
|
||||
for zi in z.infolist():
|
||||
dst_path = os.path.join(target_dir, zi.filename)
|
||||
if zi.filename.endswith('/'):
|
||||
dst_subpath = zi.filename
|
||||
if os.name == 'nt':
|
||||
# Dumb path separator replacement for Windows.
|
||||
dst_subpath = dst_subpath.replace(posixpath.sep, ntpath.sep)
|
||||
dst_path = os.path.join(target_dir, dst_subpath)
|
||||
if dst_path.endswith(os.path.sep):
|
||||
os.mkdir(dst_path)
|
||||
else:
|
||||
with open(dst_path, 'wb') as f:
|
||||
|
Loading…
Reference in New Issue
Block a user