Bug 1243318 - [mozfile] extract_zip() should not set file permissions if there are no attributes available. r=ahal

This commit is contained in:
Henrik Skupin 2016-01-27 03:52:00 +01:00
parent 76b71c3e1b
commit ab11bf611e
3 changed files with 26 additions and 3 deletions

View File

@ -72,7 +72,9 @@ def extract_zip(src, dest):
_dest.write(bundle.read(name))
_dest.close()
mode = bundle.getinfo(name).external_attr >> 16 & 0x1FF
os.chmod(filename, mode)
# Only update permissions if attributes are set. Otherwise fallback to the defaults.
if mode:
os.chmod(filename, mode)
bundle.close()
return namelist

View File

@ -1,14 +1,16 @@
#!/usr/bin/env python
import mozfile
import os
import shutil
import tarfile
import tempfile
import stubs
import unittest
import zipfile
import mozfile
import stubs
class TestExtract(unittest.TestCase):
"""test extracting archives"""
@ -39,6 +41,25 @@ class TestExtract(unittest.TestCase):
finally:
os.remove(_zipfile)
def test_extract_zipfile_missing_file_attributes(self):
"""if files do not have attributes set the default permissions have to be inherited."""
_zipfile = os.path.join(os.path.dirname(__file__), 'files', 'missing_file_attributes.zip')
self.assertTrue(os.path.exists(_zipfile))
dest = tempfile.mkdtemp()
try:
# Get the default file permissions for the user
fname = os.path.join(dest, 'foo')
with open(fname, 'w'):
pass
default_stmode = os.stat(fname).st_mode
files = mozfile.extract_zip(_zipfile, dest)
for filename in files:
self.assertEqual(os.stat(os.path.join(dest, filename)).st_mode,
default_stmode)
finally:
shutil.rmtree(dest)
def test_extract_tarball(self):
"""test extracting a tarball"""
tarball = self.create_tarball()