From 2767e865bc2601147d12bbb8a05b67f3984d8eeb Mon Sep 17 00:00:00 2001 From: Krisztian Fekete <1246751+e3krisztian@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:34:00 +0100 Subject: [PATCH] fix: Do not create extra output directory, if nothing was extracted The output path is printed in the previous commit, so depending on the caller having to look at well known paths is no longer needed. --- .../password/__output__}/.gitkeep | 0 .../encrypted/__output__}/.gitkeep | 0 .../encrypted/__output__/apple_encrypted.zip_extract/.gitkeep | 0 .../partly_encrypted/__output__}/.gitkeep | 0 .../__output__/kaki1_aes.zip_extract/.gitkeep | 0 .../__output__/lorem.txt.small_size.lzma_extract/.gitkeep | 0 .../lorem.txt.smaller_than_compressed.lzma_extract/.gitkeep | 0 .../zstd/__output__/lorem.truncated.zstd_extract/.gitkeep | 0 .../zstd/__output__/truncated.dos.zstd_extract/.gitkeep | 0 .../elf32/__output__/sample_32_prg_end.elf_extract/.gitkeep | 0 .../elf/elf64/__output__/hellomod.sha1.ko_extract/.gitkeep | 0 .../__output__/hellomod.sha1.nonsigned.ko_extract/.gitkeep | 0 .../elf/elf64/__output__/hellomod.sha256.ko_extract/.gitkeep | 0 .../elf/elf64/__output__/hellomod.sha384.ko_extract/.gitkeep | 0 .../elf/elf64/__output__/hellomod.sha512.ko_extract/.gitkeep | 0 tests/test_cli.py | 2 +- unblob/processing.py | 4 ---- 17 files changed, 1 insertion(+), 5 deletions(-) rename tests/integration/archive/{ar/__output__/offset_malformed.ar_extract => rar/password/__output__}/.gitkeep (100%) rename tests/integration/archive/{rar/password/__output__/cherry_password.rar_extract => zip/encrypted/__output__}/.gitkeep (100%) delete mode 100644 tests/integration/archive/zip/encrypted/__output__/apple_encrypted.zip_extract/.gitkeep rename tests/integration/archive/{tar/__output__/truncated-header.tar_extract => zip/partly_encrypted/__output__}/.gitkeep (100%) delete mode 100644 tests/integration/archive/zip/partly_encrypted/__output__/kaki1_aes.zip_extract/.gitkeep delete mode 100644 tests/integration/compression/lzma/__output__/lorem.txt.small_size.lzma_extract/.gitkeep delete mode 100644 tests/integration/compression/lzma/__output__/lorem.txt.smaller_than_compressed.lzma_extract/.gitkeep delete mode 100644 tests/integration/compression/zstd/__output__/lorem.truncated.zstd_extract/.gitkeep delete mode 100644 tests/integration/compression/zstd/__output__/truncated.dos.zstd_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf32/__output__/sample_32_prg_end.elf_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf64/__output__/hellomod.sha1.ko_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf64/__output__/hellomod.sha1.nonsigned.ko_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf64/__output__/hellomod.sha256.ko_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf64/__output__/hellomod.sha384.ko_extract/.gitkeep delete mode 100644 tests/integration/executable/elf/elf64/__output__/hellomod.sha512.ko_extract/.gitkeep diff --git a/tests/integration/archive/ar/__output__/offset_malformed.ar_extract/.gitkeep b/tests/integration/archive/rar/password/__output__/.gitkeep similarity index 100% rename from tests/integration/archive/ar/__output__/offset_malformed.ar_extract/.gitkeep rename to tests/integration/archive/rar/password/__output__/.gitkeep diff --git a/tests/integration/archive/rar/password/__output__/cherry_password.rar_extract/.gitkeep b/tests/integration/archive/zip/encrypted/__output__/.gitkeep similarity index 100% rename from tests/integration/archive/rar/password/__output__/cherry_password.rar_extract/.gitkeep rename to tests/integration/archive/zip/encrypted/__output__/.gitkeep diff --git a/tests/integration/archive/zip/encrypted/__output__/apple_encrypted.zip_extract/.gitkeep b/tests/integration/archive/zip/encrypted/__output__/apple_encrypted.zip_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/archive/tar/__output__/truncated-header.tar_extract/.gitkeep b/tests/integration/archive/zip/partly_encrypted/__output__/.gitkeep similarity index 100% rename from tests/integration/archive/tar/__output__/truncated-header.tar_extract/.gitkeep rename to tests/integration/archive/zip/partly_encrypted/__output__/.gitkeep diff --git a/tests/integration/archive/zip/partly_encrypted/__output__/kaki1_aes.zip_extract/.gitkeep b/tests/integration/archive/zip/partly_encrypted/__output__/kaki1_aes.zip_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/compression/lzma/__output__/lorem.txt.small_size.lzma_extract/.gitkeep b/tests/integration/compression/lzma/__output__/lorem.txt.small_size.lzma_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/compression/lzma/__output__/lorem.txt.smaller_than_compressed.lzma_extract/.gitkeep b/tests/integration/compression/lzma/__output__/lorem.txt.smaller_than_compressed.lzma_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/compression/zstd/__output__/lorem.truncated.zstd_extract/.gitkeep b/tests/integration/compression/zstd/__output__/lorem.truncated.zstd_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/compression/zstd/__output__/truncated.dos.zstd_extract/.gitkeep b/tests/integration/compression/zstd/__output__/truncated.dos.zstd_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf32/__output__/sample_32_prg_end.elf_extract/.gitkeep b/tests/integration/executable/elf/elf32/__output__/sample_32_prg_end.elf_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf64/__output__/hellomod.sha1.ko_extract/.gitkeep b/tests/integration/executable/elf/elf64/__output__/hellomod.sha1.ko_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf64/__output__/hellomod.sha1.nonsigned.ko_extract/.gitkeep b/tests/integration/executable/elf/elf64/__output__/hellomod.sha1.nonsigned.ko_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf64/__output__/hellomod.sha256.ko_extract/.gitkeep b/tests/integration/executable/elf/elf64/__output__/hellomod.sha256.ko_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf64/__output__/hellomod.sha384.ko_extract/.gitkeep b/tests/integration/executable/elf/elf64/__output__/hellomod.sha384.ko_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/executable/elf/elf64/__output__/hellomod.sha512.ko_extract/.gitkeep b/tests/integration/executable/elf/elf64/__output__/hellomod.sha512.ko_extract/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/test_cli.py b/tests/test_cli.py index 9f11d3bbf4..44f0ebdf79 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -314,7 +314,7 @@ def test_keep_extracted_chunks( [ pytest.param([], 5, id="skip-extension-empty"), pytest.param([""], 5, id="skip-zip-extension-empty-suffix"), - pytest.param([".zip"], 1, id="skip-extension-zip"), + pytest.param([".zip"], 0, id="skip-extension-zip"), pytest.param([".rlib"], 5, id="skip-extension-rlib"), ], ) diff --git a/unblob/processing.py b/unblob/processing.py index 51531a00af..b759b55159 100644 --- a/unblob/processing.py +++ b/unblob/processing.py @@ -149,10 +149,6 @@ def process_file( process_result = _process_task(config, task) - if not config.skip_extraction and not carve_dir.exists(): - # ensure that the root extraction directory is created even for empty extractions - extract_dir.mkdir(parents=True, exist_ok=True) - if report_file: write_json_report(report_file, process_result)