From ab11bf611e9c3566bb3549bc624b54ea363ad679 Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Wed, 27 Jan 2016 03:52:00 +0100 Subject: [PATCH] Bug 1243318 - [mozfile] extract_zip() should not set file permissions if there are no attributes available. r=ahal --- testing/mozbase/mozfile/mozfile/mozfile.py | 4 ++- .../tests/files/missing_file_attributes.zip | Bin 0 -> 442 bytes testing/mozbase/mozfile/tests/test_extract.py | 25 ++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 testing/mozbase/mozfile/tests/files/missing_file_attributes.zip diff --git a/testing/mozbase/mozfile/mozfile/mozfile.py b/testing/mozbase/mozfile/mozfile/mozfile.py index 04e7a4d9112..d716acc3b58 100644 --- a/testing/mozbase/mozfile/mozfile/mozfile.py +++ b/testing/mozbase/mozfile/mozfile/mozfile.py @@ -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 diff --git a/testing/mozbase/mozfile/tests/files/missing_file_attributes.zip b/testing/mozbase/mozfile/tests/files/missing_file_attributes.zip new file mode 100644 index 0000000000000000000000000000000000000000..2b5409e89c5f2adae1340168cb50b021257ebe26 GIT binary patch literal 442 zcmWIWW@Zs#U}E54U|>+Rnf+V%pavrYLkbfEg9K0{xuBplFSDd1wYWq-H@_+~FD+j$ zt2jTecGBIv76pOU_@y6rt@GV%c-D@)Q!=r@Q;?%MHurM*`-a<(?p@J-cHrl;^Xt`o z_U*J;y5qs;;K_TozgOFM;Z9HRKR4dhkCWCk32d@)6EjSUbX$;pKzd4RQWd_ODwsfxeJL~Grdaw6ePWHIPwP>VH5UBZRHKCRN zNwN0Dt=s?I*_E>W+tZJ`t6LUmv|5BFWtwhS<#XrbUBCBQdw$Q~D{Yk~A{8~q@Mv$Q zl+M#WQI#9VKO1yB@{T@W)w!p+COL@jcd_MX9`UtjXUWegIQpl_OkMkBSHk65=Fr|4 zE&)E(^9yAZ3fc`6Ri!Q*%m@tK{(Q=%2HQWv{dTR7jbxMl?>-$9-w{{jzmKQ1_BDIl nhwuCW-i%Bl47kG=7{o{bS7--#v$BDdF#@3*kd6b!5Ca1MK54WU literal 0 HcmV?d00001 diff --git a/testing/mozbase/mozfile/tests/test_extract.py b/testing/mozbase/mozfile/tests/test_extract.py index d9e6e0750b6..1f28c8a06ff 100644 --- a/testing/mozbase/mozfile/tests/test_extract.py +++ b/testing/mozbase/mozfile/tests/test_extract.py @@ -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()