feat: Lockfile

This commit is contained in:
Sayantan Santra 2023-08-10 15:12:22 -05:00
parent b677e73a7c
commit 4f14518166
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
2 changed files with 17 additions and 1 deletions

View file

@ -55,4 +55,7 @@ def clean_exit(msg, appstate, code=1):
if msg:
print(msg)
# Delete the lockfile
os.remove('lockfile')
exit(code)

View file

@ -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')