Example #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 = join_virtual_path(
                 get_base_of_virtual_path(parent.get_virtual_file_paths()[
                     parent.get_root_uid()][0]), parent.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.uid in extracted_files:  # the same file is extracted multiple times from one archive
                 extracted_files[current_file.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.uid] = current_file
     return extracted_files
Example #2
0
 def add_virtual_file_path_if_none_exists(self, parent_paths, parent_uid):
     if self.root_uid not in self.virtual_file_path.keys():
         self.virtual_file_path[self.root_uid] = []
         for item in parent_paths:
             base_path = get_base_of_virtual_path(item)
             if base_path:
                 base_path += "|"
             self.virtual_file_path[self.root_uid].append("{}{}|{}".format(
                 base_path, parent_uid, self.file_path))
Example #3
0
    def add_virtual_file_path_if_none_exists(self, parent_paths: List[str], parent_uid: str) -> None:
        '''
        Add virtual file paths (vfps) to this file based on an existing list of vfps on the parent
        and the parent's uid as root.

        :param parent_paths: List of virtual paths on parent object.
        :param parent_uid: uid of parent.
        '''
        if self.root_uid not in self.virtual_file_path.keys():
            self.virtual_file_path[self.root_uid] = []
            for item in parent_paths:
                base_path = get_base_of_virtual_path(item)
                if base_path:
                    base_path += "|"
                self.virtual_file_path[self.root_uid].append("{}{}|{}".format(base_path, parent_uid, self.file_path))