Ejemplo n.º 1
0
 def generate_and_store_file_objects(self, file_paths: List[Path],
                                     extractor_dir: str,
                                     parent: FileObject):
     extracted_files = {}
     for item in file_paths:
         if not file_is_empty(item):
             current_file = FileObject(file_path=str(item))
             current_virtual_path = '{}|{}|{}'.format(
                 parent.get_base_of_virtual_path(
                     parent.get_virtual_file_paths()[
                         parent.get_root_uid()][0]), parent.get_uid(),
                 get_object_path_excluding_fact_dirs(
                     make_unicode_string(str(item)),
                     str(Path(extractor_dir, 'files'))))
             current_file.temporary_data[
                 'parent_fo_type'] = get_file_type_from_path(
                     parent.file_path)['mime']
             if current_file.get_uid(
             ) in extracted_files:  # the same file is extracted multiple times from one archive
                 extracted_files[current_file.get_uid()].virtual_file_path[
                     parent.get_root_uid()].append(current_virtual_path)
             else:
                 self.db_interface.set_unpacking_lock(current_file.uid)
                 self.file_storage_system.store_file(current_file)
                 current_file.virtual_file_path = {
                     parent.get_root_uid(): [current_virtual_path]
                 }
                 current_file.parent_firmware_uids.add(
                     parent.get_root_uid())
                 extracted_files[current_file.get_uid()] = current_file
     return extracted_files
Ejemplo n.º 2
0
 def test_get_base_of_virtual_path_root(self):
     fo = FileObject(binary=b'file_object')
     virtual_test_path = 'root_uid'
     self.assertEqual(fo.get_base_of_virtual_path(virtual_test_path), '')
Ejemplo n.º 3
0
 def test_get_base_of_virtual_path(self):
     fo = FileObject(binary=b'file_object')
     virtual_test_path = 'root_uid|child_1_uid|child_2_uid|directory/file.type'
     self.assertEqual(fo.get_base_of_virtual_path(virtual_test_path), 'root_uid|child_1_uid|child_2_uid')