Skip to content

Commit

Permalink
fix: single loader ignored path components
Browse files Browse the repository at this point in the history
  • Loading branch information
twiggler committed Nov 18, 2024
1 parent daeed33 commit b05639b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dissect/target/loaders/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def detect(_: Path) -> bool:
return False

Check warning on line 22 in dissect/target/loaders/single.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/loaders/single.py#L22

Added line #L22 was not covered by tests

def map(self, target: Target) -> None:
"""Maps the contents of the target path recursively into a special drop folder"""

vfs = VirtualFilesystem(case_sensitive=False, alt_separator=target.fs.alt_separator)
target.filesystems.add(vfs)
target.fs.mount("/", vfs)
for entry in self.path.parent.glob(self.path.name):
mapping = str(vfs.path(SINGLE_FILE_DIR).joinpath(entry.name))
vfs.map_file(mapping, str(entry))
mapping = vfs.path(SINGLE_FILE_DIR).joinpath(entry)
vfs.map_file(str(mapping), str(entry))
16 changes: 16 additions & 0 deletions tests/loaders/test_single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import io
from pathlib import Path

from dissect.target import Target
from dissect.target.filesystem import VirtualFilesystem
from dissect.target.loaders.single import SingleFileLoader


def test_single_loader(target_default: Target) -> None:
path = Path("test/single.txt")
vfs = VirtualFilesystem()
vfs.map_file_fh("test/single.txt", io.BytesIO(b"\x00"))
log_loader = SingleFileLoader(vfs.path(path))
log_loader.map(target_default)

assert target_default.fs.exists("$drop$/test/single.txt")

0 comments on commit b05639b

Please sign in to comment.