From c29e5bb7a1b1ae1d1b3491ed64ccd738feb1841f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milio=20Gonzalez?= Date: Sun, 10 Aug 2025 17:19:45 -0400 Subject: [PATCH] fix a bug introduced in the previous 2-3 commits --- ctf/utils.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ctf/utils.py b/ctf/utils.py index 65eaaa8..26c487d 100644 --- a/ctf/utils.py +++ b/ctf/utils.py @@ -7,7 +7,6 @@ import jinja2 import yaml - from ctf import ENV from ctf.logger import LOG @@ -225,15 +224,12 @@ def find_ctf_root_directory() -> str: if "CTF_ROOT_DIR" in ENV else os.path.join(os.getcwd(), ".") ) + if not is_ctf_dir(path=path): + while path != (path := os.path.dirname(p=path)): + ctf_dir = is_ctf_dir(path) - while path != (path := os.path.dirname(p=path)): - dir = os.listdir(path=path) - - if ".deploy" not in dir: - continue - if "challenges" not in dir: - continue - break + if ctf_dir: + break if path == "/": LOG.critical( @@ -246,6 +242,16 @@ def find_ctf_root_directory() -> str: return (__CTF_ROOT_DIRECTORY := path) +def is_ctf_dir(path): + ctf_dir = True + dir = os.listdir(path=path) + if ".deploy" not in dir: + ctf_dir = False + if "challenges" not in dir: + ctf_dir = False + return ctf_dir + + def terraform_binary() -> str: path = shutil.which(cmd="tofu") if not path: