Fix file permissions when extracting zip files (#325)

This means that `./emsdk` works on UNIX system after emsdk self-updates
from a zip file.  Without this one would need to run `python ./emsdk`
which seems to be why the tests were doing it this way.
This commit is contained in:
Sam Clegg
2019-08-26 23:06:56 -07:00
committed by GitHub
parent da4900b83f
commit 596bdc5ea4
3 changed files with 12 additions and 5 deletions

9
emsdk
View File

@@ -503,6 +503,12 @@ def unzip(source_filename, dest_dir, unpack_even_if_exists=False):
# Now do the actual decompress. # Now do the actual decompress.
for member in zf.infolist(): for member in zf.infolist():
zf.extract(member, fix_potentially_long_windows_pathname(unzip_to_dir)) zf.extract(member, fix_potentially_long_windows_pathname(unzip_to_dir))
dst_filename = os.path.join(unzip_to_dir, member.filename)
# See: https://stackoverflow.com/questions/42326428/zipfile-in-python-file-permission
unix_attributes = member.external_attr >> 16
if unix_attributes:
os.chmod(dst_filename, unix_attributes)
# Move the extracted file to its final location without the base directory name, if we are stripping that away. # Move the extracted file to its final location without the base directory name, if we are stripping that away.
if common_subdir: if common_subdir:
@@ -514,11 +520,10 @@ def unzip(source_filename, dest_dir, unpack_even_if_exists=False):
d = fix_potentially_long_windows_pathname(final_dst_filename) d = fix_potentially_long_windows_pathname(final_dst_filename)
if not os.path.isdir(d): os.mkdir(d) if not os.path.isdir(d): os.mkdir(d)
else: else:
tmp_dst_filename = os.path.join(unzip_to_dir, member.filename)
parent_dir = os.path.dirname(fix_potentially_long_windows_pathname(final_dst_filename)) parent_dir = os.path.dirname(fix_potentially_long_windows_pathname(final_dst_filename))
if parent_dir and not os.path.exists(parent_dir): if parent_dir and not os.path.exists(parent_dir):
os.makedirs(parent_dir) os.makedirs(parent_dir)
move_with_overwrite(fix_potentially_long_windows_pathname(tmp_dst_filename), fix_potentially_long_windows_pathname(final_dst_filename)) move_with_overwrite(fix_potentially_long_windows_pathname(dst_filename), fix_potentially_long_windows_pathname(final_dst_filename))
if common_subdir: if common_subdir:
try: try:

7
test.py Normal file → Executable file
View File

@@ -1,3 +1,4 @@
#!/usr/bin/env python
import json import json
import os import os
import shlex import shlex
@@ -149,13 +150,13 @@ temp_dir = tempfile.mkdtemp()
for filename in os.listdir('.'): for filename in os.listdir('.'):
if not filename.startswith('.') and not os.path.isdir(filename): if not filename.startswith('.') and not os.path.isdir(filename):
shutil.copyfile(filename, os.path.join(temp_dir, filename)) shutil.copy2(filename, os.path.join(temp_dir, filename))
os.chdir(temp_dir) os.chdir(temp_dir)
check_call('python ./emsdk update') check_call('./emsdk update')
print('second time') print('second time')
check_call('python ./emsdk update') check_call('./emsdk update')
print('verify downloads exist for all OSes') print('verify downloads exist for all OSes')
latest_hash = TAGS['releases'][TAGS['latest']] latest_hash = TAGS['releases'][TAGS['latest']]

1
test.sh Normal file → Executable file
View File

@@ -1,3 +1,4 @@
#!/usr/bin/env sh
echo "test the standard workflow (as close as possible to how a user would do it, in the shell)" echo "test the standard workflow (as close as possible to how a user would do it, in the shell)"
./emsdk install latest ./emsdk install latest
./emsdk activate latest ./emsdk activate latest