-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make acquire compression configurable (#185)
(DIS-3291)
- Loading branch information
Showing
8 changed files
with
131 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from acquire.outputs.dir import DirectoryOutput | ||
from acquire.outputs.tar import TarOutput | ||
from acquire.outputs.zip import ZipOutput | ||
from acquire.outputs.tar import TAR_COMPRESSION_METHODS, TarOutput | ||
from acquire.outputs.zip import ZIP_COMPRESSION_METHODS, ZipOutput | ||
|
||
__all__ = ["DirectoryOutput", "TarOutput", "ZipOutput"] | ||
|
||
OUTPUTS = {"tar": TarOutput, "dir": DirectoryOutput, "zip": ZipOutput} | ||
|
||
COMPRESSION_METHODS = {*TAR_COMPRESSION_METHODS, *ZIP_COMPRESSION_METHODS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import stat | ||
import zipfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
from dissect.target.filesystem import VirtualFilesystem | ||
|
||
from acquire.outputs import ZipOutput | ||
|
||
|
||
@pytest.fixture(params=[(True, "deflate"), (True, "bzip2"), (True, "lzma"), (False, None)]) | ||
def zip_output(tmp_path: Path, request: pytest.FixtureRequest) -> ZipOutput: | ||
compress, compression_method = request.param | ||
return ZipOutput(tmp_path, compress=compress, compression_method=compression_method) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"entry_name", | ||
[ | ||
"/foo/bar/some-file", | ||
"/foo/bar/some-symlink", | ||
"/foo/bar/some-dir", | ||
], | ||
) | ||
def test_zip_output_write_entry(mock_fs: VirtualFilesystem, zip_output: ZipOutput, entry_name: str) -> None: | ||
entry = mock_fs.get(entry_name) | ||
|
||
assert zip_output.compression == zip_output.archive.compression | ||
zip_output.write_entry(entry_name, entry) | ||
zip_output.close() | ||
|
||
zip_file = zipfile.ZipFile(zip_output.path, mode="r") | ||
files = zip_file.filelist | ||
assert len(files) == 1 | ||
|
||
file = files[0] | ||
assert file.filename == entry_name | ||
|
||
file_type = file.external_attr >> 16 | ||
|
||
# zipfile only supports is_dir(). we have all the information we need to determine the file type in 'external_attr' | ||
if entry.is_dir(): | ||
assert stat.S_ISDIR(file_type) | ||
elif entry.is_symlink(): | ||
assert stat.S_ISLNK(file_type) | ||
elif entry.is_file(): | ||
assert stat.S_ISREG(file_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters