def _remove_all(self, method): tarin = tarfile.open(self.filename, 'r' + self.compression) tarout = tarfile.open(self.output, 'w' + self.compression) for item in tarin.getmembers(): tarin.extract(item, self.tempdir) name = os.path.join(self.tempdir, item.name) if item.type is '0': # is item a regular file ? #no backup file try: cfile = mat.create_class_file(name, False, self.add2archive) if method is 'normal': cfile.remove_all() else: cfile.remove_all_ugly() tarout.add(name, item.name, filter=self._remove) except: logging.info('%s\' format is not supported or harmless' % item.name) _, ext = os.path.splitext(name) if self.add2archive or ext in parser.NOMETA: tarout.add(name, item.name, filter=self._remove) tarin.close() tarout.close() self.do_backup()
def is_clean(self): ''' Check if the file is clean from harmful metadatas ''' tarin = tarfile.open(self.filename, 'r' + self.compression) for item in tarin.getmembers(): if not self.is_file_clean(item): tarin.close() return False tarin.extract(item, self.tempdir) name = os.path.join(self.tempdir, item.name) if item.type is '0': # is item a regular file ? try: class_file = mat.create_class_file( name, False, self.add2archive) # no backup file if not class_file.is_clean(): tarin.close() return False except: logging.error('%s\'s foramt is not supported or harmless' % item.filename) _, ext = os.path.splitext(name) if ext not in parser.NOMETA: tarin.close() return False tarin.close() return True
def is_clean(self): ''' Check if the file is clean from harmful metadatas ''' tarin = tarfile.open(self.filename, 'r' + self.compression) for item in tarin.getmembers(): if not self.is_file_clean(item): tarin.close() return False tarin.extract(item, self.tempdir) name = os.path.join(self.tempdir, item.name) if item.type is '0': # is item a regular file ? try: class_file = mat.create_class_file(name, False, self.add2archive) # no backup file if not class_file.is_clean(): tarin.close() return False except: logging.error('%s\'s foramt is not supported or harmless' % item.filename) _, ext = os.path.splitext(name) if ext not in parser.NOMETA: tarin.close() return False tarin.close() return True
def get_meta(self): ''' Return a dict with all the meta of the file ''' tarin = tarfile.open(self.filename, 'r' + self.compression) metadata = {} for current_file in tarin.getmembers(): if current_file.type is '0': if not self.is_file_clean(current_file): # if there is meta current_meta = {} current_meta['mtime'] = current_file.mtime current_meta['uid'] = current_file.uid current_meta['gid'] = current_file.gid current_meta['uname'] = current_file.uname current_meta['gname'] = current_file.gname metadata[current_file.name] = current_meta tarin.close() return metadata