From 4f145181663d5fa67b7a9213d4b8508cd5b89e9a Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Thu, 10 Aug 2023 15:12:22 -0500 Subject: [PATCH] feat: Lockfile --- Cleanup.py | 3 +++ ReVancedBuilder.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cleanup.py b/Cleanup.py index 2fc6484..be9f8a1 100644 --- a/Cleanup.py +++ b/Cleanup.py @@ -55,4 +55,7 @@ def clean_exit(msg, appstate, code=1): if msg: print(msg) + + # Delete the lockfile + os.remove('lockfile') exit(code) \ No newline at end of file diff --git a/ReVancedBuilder.py b/ReVancedBuilder.py index 33c9b47..e915e81 100755 --- a/ReVancedBuilder.py +++ b/ReVancedBuilder.py @@ -14,7 +14,6 @@ from Cleanup import * import logging import subprocess -# TODO: Run post_script (preferably in any language) # TODO: README # TODO: PATCHES_GUIDE.md (maybe delete it?) # TODO: Lockfile @@ -94,6 +93,17 @@ except IndexError: except FileNotFoundError: clean_exit('Invalid working directory provided!', appstate) +# Try to make sure only one instance is running in a given working directory +try: + if os.path.exists('lockfile'): + raise FileExistsError + with open('tmplockfile', 'x') as f: + f.flush() + os.fsync(f.fileno()) + os.replace('tmplockfile', 'lockfile') +except FileExistsError: + sys.exit('Another instance is already running in the same working directory!') + # Set up logging try: os.mkdir('logs') @@ -173,3 +183,6 @@ elif flag != ['checkonly']: subprocess.run(f"{appstate['build_config']['post_script']['file']} {timestamp}", shell=True) except: pass + +# Delete the lockfile +os.remove('lockfile') \ No newline at end of file