mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-25 20:28:37 -06:00
feat: Lockfile
This commit is contained in:
parent
b677e73a7c
commit
4f14518166
2 changed files with 17 additions and 1 deletions
|
@ -55,4 +55,7 @@ def clean_exit(msg, appstate, code=1):
|
|||
|
||||
if msg:
|
||||
print(msg)
|
||||
|
||||
# Delete the lockfile
|
||||
os.remove('lockfile')
|
||||
exit(code)
|
|
@ -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')
|
Loading…
Reference in a new issue