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: