From 17c3fa02b3ca7e2cfb572778bbe54c2f1e373282 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 10 Mar 2022 08:42:50 -0500 Subject: [PATCH] Agent: Return agent/dropper log path as a Path instead of str --- monkey/infection_monkey/monkey.py | 2 +- monkey/infection_monkey/utils/monkey_log_path.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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)