From 422884c39324e2130350ca4e8fe02348e03d6580 Mon Sep 17 00:00:00 2001 From: JSCU-CNI <121175071+JSCU-CNI@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:56:18 +0200 Subject: [PATCH 1/3] make log output less noisey --- dissect/target/helpers/record_modifier.py | 8 ++++++++ dissect/target/target.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dissect/target/helpers/record_modifier.py b/dissect/target/helpers/record_modifier.py index 52a734abe..34f002be6 100644 --- a/dissect/target/helpers/record_modifier.py +++ b/dissect/target/helpers/record_modifier.py @@ -94,6 +94,13 @@ def modify_record(target: Target, record: Record, modifier_function: ModifierFun for field_name, resolved_path in _resolve_path_types(target, record): try: _record = modifier_function(field_name, resolved_path) + + except FileNotFoundError as e: + target.log.info( + "Unable to modify record '%s' with function '%s': %s", record._desc.name, modifier_function.__name__, e + ) + target.log.debug("", exc_info=e) + except FilesystemError as e: target.log.warning( "Unable to modify record '%s' with function '%s': %s", @@ -102,6 +109,7 @@ def modify_record(target: Target, record: Record, modifier_function: ModifierFun e, ) target.log.debug("", exc_info=e) + else: additional_records.append(_record) diff --git a/dissect/target/target.py b/dissect/target/target.py index 73a44c86b..9d581e26a 100644 --- a/dissect/target/target.py +++ b/dissect/target/target.py @@ -19,6 +19,7 @@ VolumeSystemError, ) from dissect.target.helpers import config +from dissect.target.helpers.fsutil import TargetPath from dissect.target.helpers.loaderutil import extract_path_info from dissect.target.helpers.record import ChildTargetRecord from dissect.target.helpers.utils import StrEnum, parse_path_uri, slugify @@ -86,8 +87,13 @@ def __init__(self, path: Union[str, Path] = None): self._errors = [] self._applied = False + # We do not want to look for config files at the Target path if it is actually a child Target. + config_paths = [Path.cwd(), Path.home()] + if not isinstance(path, TargetPath): + config_paths = [self.path] + config_paths + try: - self._config = config.load([self.path, Path.cwd(), Path.home()]) + self._config = config.load(config_paths) except Exception as e: self.log.warning("Error loading config file: %s", self.path) self.log.debug("", exc_info=e) From 33d162815f84fa7fb48fb25e2d692a0f517bdad6 Mon Sep 17 00:00:00 2001 From: Computer Network Investigation <121175071+JSCU-CNI@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:43:59 +0200 Subject: [PATCH 2/3] Update dissect/target/helpers/record_modifier.py Co-authored-by: Erik Schamper <1254028+Schamper@users.noreply.github.com> --- dissect/target/helpers/record_modifier.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/dissect/target/helpers/record_modifier.py b/dissect/target/helpers/record_modifier.py index 34f002be6..0cbd7f5d2 100644 --- a/dissect/target/helpers/record_modifier.py +++ b/dissect/target/helpers/record_modifier.py @@ -94,15 +94,10 @@ def modify_record(target: Target, record: Record, modifier_function: ModifierFun for field_name, resolved_path in _resolve_path_types(target, record): try: _record = modifier_function(field_name, resolved_path) - - except FileNotFoundError as e: - target.log.info( - "Unable to modify record '%s' with function '%s': %s", record._desc.name, modifier_function.__name__, e - ) - target.log.debug("", exc_info=e) - except FilesystemError as e: - target.log.warning( + level = logging.INFO if isinstance(e, FileNotFoundError) else logging.WARNING + target.log.log( + level, "Unable to modify record '%s' with function '%s': %s", record._desc.name, modifier_function.__name__, From fead052fb20840c7d51f6f24c95dd8891a594b01 Mon Sep 17 00:00:00 2001 From: JSCU-CNI <121175071+JSCU-CNI@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:41:55 +0200 Subject: [PATCH 3/3] fix linter --- dissect/target/helpers/record_modifier.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dissect/target/helpers/record_modifier.py b/dissect/target/helpers/record_modifier.py index 0cbd7f5d2..492779ad5 100644 --- a/dissect/target/helpers/record_modifier.py +++ b/dissect/target/helpers/record_modifier.py @@ -1,3 +1,4 @@ +import logging from functools import partial from typing import Callable, Iterable, Iterator