diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index a62547ebc..983e2dd2b 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -289,7 +289,7 @@ class InfectionMonkey: @staticmethod def _send_log(): monkey_log_path = get_agent_log_path() - if os.path.exists(monkey_log_path): + if monkey_log_path.is_file(): with open(monkey_log_path, "r") as f: log = f.read() else: diff --git a/monkey/infection_monkey/utils/monkey_log_path.py b/monkey/infection_monkey/utils/monkey_log_path.py index 4708213fa..a92891f24 100644 --- a/monkey/infection_monkey/utils/monkey_log_path.py +++ b/monkey/infection_monkey/utils/monkey_log_path.py @@ -3,12 +3,13 @@ import sys import tempfile import time from functools import lru_cache, partial +from pathlib import Path # Cache the result of the call so that subsequent calls always return the same result @lru_cache(maxsize=None) -def _get_log_path(monkey_arg: str) -> str: - return ( +def _get_log_path(monkey_arg: str) -> Path: + return Path( os.path.expandvars(_generate_random_log_filepath(monkey_arg)) if sys.platform == "win32" else _generate_random_log_filepath(monkey_arg)