diff options
Diffstat (limited to 'libmat/archive.py')
| -rw-r--r-- | libmat/archive.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/libmat/archive.py b/libmat/archive.py index a662e61..12ca55e 100644 --- a/libmat/archive.py +++ b/libmat/archive.py | |||
| @@ -9,8 +9,7 @@ import tarfile | |||
| 9 | import tempfile | 9 | import tempfile |
| 10 | import zipfile | 10 | import zipfile |
| 11 | 11 | ||
| 12 | import mat | 12 | from libmat import parser |
| 13 | import parser | ||
| 14 | 13 | ||
| 15 | # Zip files do not support dates older than 01/01/1980 | 14 | # Zip files do not support dates older than 01/01/1980 |
| 16 | ZIP_EPOCH = (1980, 1, 1, 0, 0, 0) | 15 | ZIP_EPOCH = (1980, 1, 1, 0, 0, 0) |
| @@ -20,6 +19,9 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 20 | """ Represent a generic archive | 19 | """ Represent a generic archive |
| 21 | """ | 20 | """ |
| 22 | 21 | ||
| 22 | def get_meta(self): | ||
| 23 | raise NotImplementedError | ||
| 24 | |||
| 23 | def __init__(self, filename, mime, backup, is_writable, **kwargs): | 25 | def __init__(self, filename, mime, backup, is_writable, **kwargs): |
| 24 | super(GenericArchiveStripper, self).__init__(filename, mime, backup, is_writable, **kwargs) | 26 | super(GenericArchiveStripper, self).__init__(filename, mime, backup, is_writable, **kwargs) |
| 25 | self.compression = '' | 27 | self.compression = '' |
| @@ -32,8 +34,9 @@ class GenericArchiveStripper(parser.GenericParser): | |||
| 32 | """ | 34 | """ |
| 33 | for root, _, files in os.walk(self.tempdir): | 35 | for root, _, files in os.walk(self.tempdir): |
| 34 | for item in files: | 36 | for item in files: |
| 37 | from libmat.mat import secure_remove | ||
| 35 | path_file = os.path.join(root, item) | 38 | path_file = os.path.join(root, item) |
| 36 | mat.secure_remove(path_file) | 39 | secure_remove(path_file) |
| 37 | shutil.rmtree(self.tempdir) | 40 | shutil.rmtree(self.tempdir) |
| 38 | 41 | ||
| 39 | def is_clean(self, list_unsupported=False): | 42 | def is_clean(self, list_unsupported=False): |
| @@ -90,7 +93,8 @@ class ZipStripper(GenericArchiveStripper): | |||
| 90 | logging.debug('%s from %s has compromising zipinfo', item.filename, self.filename) | 93 | logging.debug('%s from %s has compromising zipinfo', item.filename, self.filename) |
| 91 | return False | 94 | return False |
| 92 | if os.path.isfile(path): | 95 | if os.path.isfile(path): |
| 93 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 96 | from libmat.mat import create_class_file |
| 97 | cfile = create_class_file(path, False, add2archive=self.add2archive) | ||
| 94 | if cfile is not None: | 98 | if cfile is not None: |
| 95 | if not cfile.is_clean(): | 99 | if not cfile.is_clean(): |
| 96 | logging.debug('%s from %s has metadata', item.filename, self.filename) | 100 | logging.debug('%s from %s has metadata', item.filename, self.filename) |
| @@ -122,7 +126,8 @@ class ZipStripper(GenericArchiveStripper): | |||
| 122 | zipin.extract(item, self.tempdir) | 126 | zipin.extract(item, self.tempdir) |
| 123 | path = os.path.join(self.tempdir, item.filename) | 127 | path = os.path.join(self.tempdir, item.filename) |
| 124 | if os.path.isfile(path): | 128 | if os.path.isfile(path): |
| 125 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 129 | from libmat.mat import create_class_file |
| 130 | cfile = create_class_file(path, False, add2archive=self.add2archive) | ||
| 126 | if cfile is not None: | 131 | if cfile is not None: |
| 127 | cfile_meta = cfile.get_meta() | 132 | cfile_meta = cfile.get_meta() |
| 128 | if cfile_meta != {}: | 133 | if cfile_meta != {}: |
| @@ -172,7 +177,8 @@ class ZipStripper(GenericArchiveStripper): | |||
| 172 | ending = any((True for f in ending_blacklist if item.filename.endswith(f))) | 177 | ending = any((True for f in ending_blacklist if item.filename.endswith(f))) |
| 173 | 178 | ||
| 174 | if os.path.isfile(path) and not beginning and not ending: | 179 | if os.path.isfile(path) and not beginning and not ending: |
| 175 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 180 | from libmat.mat import create_class_file |
| 181 | cfile = create_class_file(path, False, add2archive=self.add2archive) | ||
| 176 | if cfile is not None: | 182 | if cfile is not None: |
| 177 | # Handle read-only files inside archive | 183 | # Handle read-only files inside archive |
| 178 | old_stat = os.stat(path).st_mode | 184 | old_stat = os.stat(path).st_mode |
| @@ -231,7 +237,8 @@ class TarStripper(GenericArchiveStripper): | |||
| 231 | tarin.extract(item, self.tempdir) | 237 | tarin.extract(item, self.tempdir) |
| 232 | if item.isfile(): | 238 | if item.isfile(): |
| 233 | path = os.path.join(self.tempdir, item.name) | 239 | path = os.path.join(self.tempdir, item.name) |
| 234 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 240 | from libmat.mat import create_class_file |
| 241 | cfile = create_class_file(path, False, add2archive=self.add2archive) | ||
| 235 | if cfile is not None: | 242 | if cfile is not None: |
| 236 | # Handle read-only files inside archive | 243 | # Handle read-only files inside archive |
| 237 | old_stat = os.stat(path).st_mode | 244 | old_stat = os.stat(path).st_mode |
| @@ -286,7 +293,8 @@ class TarStripper(GenericArchiveStripper): | |||
| 286 | tarin.extract(item, self.tempdir) | 293 | tarin.extract(item, self.tempdir) |
| 287 | path = os.path.join(self.tempdir, item.name) | 294 | path = os.path.join(self.tempdir, item.name) |
| 288 | if item.isfile(): | 295 | if item.isfile(): |
| 289 | cfile = mat.create_class_file(path, False, add2archive=self.add2archive) | 296 | from libmat.mat import create_class_file |
| 297 | cfile = create_class_file(path, False, add2archive=self.add2archive) | ||
| 290 | if cfile is not None: | 298 | if cfile is not None: |
| 291 | if not cfile.is_clean(): | 299 | if not cfile.is_clean(): |
| 292 | logging.debug('%s from %s has metadata', item.name.decode("utf8"), self.filename) | 300 | logging.debug('%s from %s has metadata', item.name.decode("utf8"), self.filename) |
| @@ -316,7 +324,8 @@ class TarStripper(GenericArchiveStripper): | |||
| 316 | if item.isfile(): | 324 | if item.isfile(): |
| 317 | tarin.extract(item, self.tempdir) | 325 | tarin.extract(item, self.tempdir) |
| 318 | path = os.path.join(self.tempdir, item.name) | 326 | path = os.path.join(self.tempdir, item.name) |
| 319 | class_file = mat.create_class_file(path, False, add2archive=self.add2archive) | 327 | from libmat.mat import create_class_file |
| 328 | class_file = create_class_file(path, False, add2archive=self.add2archive) | ||
| 320 | if class_file is not None: | 329 | if class_file is not None: |
| 321 | meta = class_file.get_meta() | 330 | meta = class_file.get_meta() |
| 322 | if meta: | 331 | if meta: |
