diff options
| -rw-r--r-- | MAT/archive.py | 6 | ||||
| -rw-r--r-- | test/libtest.py | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/MAT/archive.py b/MAT/archive.py index ed55319..ee5c936 100644 --- a/MAT/archive.py +++ b/MAT/archive.py | |||
| @@ -5,6 +5,7 @@ import datetime | |||
| 5 | import logging | 5 | import logging |
| 6 | import os | 6 | import os |
| 7 | import shutil | 7 | import shutil |
| 8 | import stat | ||
| 8 | import tarfile | 9 | import tarfile |
| 9 | import tempfile | 10 | import tempfile |
| 10 | import zipfile | 11 | import zipfile |
| @@ -160,7 +161,10 @@ class ZipStripper(GenericArchiveStripper): | |||
| 160 | if os.path.isfile(name) and not beginning and not ending: | 161 | if os.path.isfile(name) and not beginning and not ending: |
| 161 | cfile = mat.create_class_file(name, False, add2archive=self.add2archive) | 162 | cfile = mat.create_class_file(name, False, add2archive=self.add2archive) |
| 162 | if cfile is not None: | 163 | if cfile is not None: |
| 164 | old_stat = os.stat(name).st_mode | ||
| 165 | os.chmod(name, old_stat|stat.S_IWUSR) | ||
| 163 | cfile.remove_all() | 166 | cfile.remove_all() |
| 167 | os.chmod(name, old_stat) | ||
| 164 | logging.debug('Processing %s from %s' % (item.filename, self.filename)) | 168 | logging.debug('Processing %s from %s' % (item.filename, self.filename)) |
| 165 | elif item.filename not in whitelist: | 169 | elif item.filename not in whitelist: |
| 166 | logging.info('%s\'s format is not supported or harmless' % item.filename) | 170 | logging.info('%s\'s format is not supported or harmless' % item.filename) |
| @@ -244,10 +248,10 @@ class TarStripper(GenericArchiveStripper): | |||
| 244 | class_file = mat.create_class_file(complete_name, | 248 | class_file = mat.create_class_file(complete_name, |
| 245 | False, add2archive=self.add2archive) | 249 | False, add2archive=self.add2archive) |
| 246 | if class_file: | 250 | if class_file: |
| 247 | # Nested archives are treated like unsupported ones | ||
| 248 | if not class_file.is_clean(): | 251 | if not class_file.is_clean(): |
| 249 | if not list_unsupported: | 252 | if not list_unsupported: |
| 250 | return False | 253 | return False |
| 254 | # Nested archives are treated like unsupported files | ||
| 251 | elif isinstance(class_file, GenericArchiveStripper): | 255 | elif isinstance(class_file, GenericArchiveStripper): |
| 252 | ret_list.append(item.name) | 256 | ret_list.append(item.name) |
| 253 | else: | 257 | else: |
diff --git a/test/libtest.py b/test/libtest.py index f052b6e..cbc807f 100644 --- a/test/libtest.py +++ b/test/libtest.py | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | import os | 8 | import os |
| 9 | import sys | 9 | import sys |
| 10 | import shutil | ||
| 10 | import tarfile | 11 | import tarfile |
| 11 | import tempfile | 12 | import tempfile |
| 12 | import test | 13 | import test |
| @@ -157,6 +158,13 @@ class TestArchiveProcessing(test.MATTest): | |||
| 157 | unsupported_files = set(current_file.is_clean(list_unsupported=True)) | 158 | unsupported_files = set(current_file.is_clean(list_unsupported=True)) |
| 158 | self.assertEqual(unsupported_files, set(('mat.desktop', 'README.security', 'setup.py'))) | 159 | self.assertEqual(unsupported_files, set(('mat.desktop', 'README.security', 'setup.py'))) |
| 159 | 160 | ||
| 161 | def test_archive_unwritable_content(self): | ||
| 162 | path = os.path.join(self.tmpdir, './unwritable_content.zip') | ||
| 163 | shutil.copy2('./unwritable_content.zip', self.tmpdir) | ||
| 164 | current_file = MAT.mat.create_class_file(path, False, add2archive=False) | ||
| 165 | current_file.remove_all() | ||
| 166 | current_file = MAT.mat.create_class_file(path, False, add2archive=False) | ||
| 167 | self.assertTrue(current_file.is_clean()) | ||
| 160 | 168 | ||
| 161 | def get_tests(): | 169 | def get_tests(): |
| 162 | ''' Returns every libtests''' | 170 | ''' Returns every libtests''' |
