Beispiel #1
0
 def test_file_is_zero(self):
     self.assertTrue(
         file_is_empty('{}/zero_byte'.format(get_test_data_dir())),
         'file is empty but stated differently')
     self.assertFalse(
         file_is_empty('{}/get_files_test/testfile1'.format(
             get_test_data_dir())), 'file not empty but stated differently')
     self.assertFalse(
         file_is_empty(os.path.join(get_test_data_dir(), 'broken_link')),
         'Broken link is not empty')
Beispiel #2
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
Beispiel #3
0
 def generate_and_store_file_objects(self, file_paths: List[Path],
                                     extraction_dir: Path,
                                     parent: FileObject):
     extracted_files = {}
     for item in file_paths:
         if not file_is_empty(item):
             current_file = FileObject(file_path=str(item))
             base = get_base_of_virtual_path(
                 parent.get_virtual_file_paths()[parent.get_root_uid()][0])
             current_virtual_path = join_virtual_path(
                 base, parent.uid,
                 get_relative_object_path(item, extraction_dir))
             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
Beispiel #4
0
 def generate_and_store_file_objects(self, file_paths, tmp_dir, parent):
     extracted_files = {}
     for item in file_paths:
         if not file_is_empty(item):
             current_file = FileObject(file_path=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_chroot_path_excluding_extracted_dir(make_unicode_string(item), tmp_dir)
             )
             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.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
Beispiel #5
0
 def test_file_is_zero_broken_link(self):
     self.assertFalse(file_is_empty(os.path.join(get_test_data_dir(), 'broken_link')), 'Broken link is not empty')
Beispiel #6
0
def test_file_is_zero_broken_link():
    assert not file_is_empty(
        TEST_DATA_DIR / 'broken_link'), 'Broken link is not empty'
Beispiel #7
0
def test_file_is_zero():
    assert file_is_empty(TEST_DATA_DIR /
                         'zero_byte'), 'file is empty but stated differently'
    assert not file_is_empty(
        TEST_DATA_DIR / 'get_files_test' /
        'testfile1'), 'file not empty but stated differently'