From 92c57e2a462a5d7fcbc51da4bed3b13cdbf6e5ce Mon Sep 17 00:00:00 2001 From: Erovia Date: Sun, 10 May 2020 17:30:30 +0200 Subject: [PATCH] Fix possibility of recursive execution --- qmk_cli/script_qmk.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qmk_cli/script_qmk.py b/qmk_cli/script_qmk.py index ddf7a4b..fa983fb 100644 --- a/qmk_cli/script_qmk.py +++ b/qmk_cli/script_qmk.py @@ -30,7 +30,12 @@ def in_qmk_firmware(): cur_dir = Path.cwd() while len(cur_dir.parents) > 0: found_bin = cur_dir / 'bin' / 'qmk' - if found_bin.is_file(): + # An additional check for something that exists in the root of qmk_firmware, + # but not in the script's install directory, to avoid recursive execution, + # if started from install directory. + # e.g.: cd ~/.local/bin && ./qmk + found_makefile = cur_dir / 'Makefile' + if found_bin.is_file() and found_makefile.is_file(): command = [sys.executable, found_bin.as_posix()] result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)