mirror of
https://github.com/SinTan1729/ReVancedBuilder.git
synced 2024-12-26 20:58: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:
|
if msg:
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
# Delete the lockfile
|
||||||
|
os.remove('lockfile')
|
||||||
exit(code)
|
exit(code)
|
|
@ -14,7 +14,6 @@ from Cleanup import *
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# TODO: Run post_script (preferably in any language)
|
|
||||||
# TODO: README
|
# TODO: README
|
||||||
# TODO: PATCHES_GUIDE.md (maybe delete it?)
|
# TODO: PATCHES_GUIDE.md (maybe delete it?)
|
||||||
# TODO: Lockfile
|
# TODO: Lockfile
|
||||||
|
@ -94,6 +93,17 @@ except IndexError:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
clean_exit('Invalid working directory provided!', appstate)
|
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
|
# Set up logging
|
||||||
try:
|
try:
|
||||||
os.mkdir('logs')
|
os.mkdir('logs')
|
||||||
|
@ -173,3 +183,6 @@ elif flag != ['checkonly']:
|
||||||
subprocess.run(f"{appstate['build_config']['post_script']['file']} {timestamp}", shell=True)
|
subprocess.run(f"{appstate['build_config']['post_script']['file']} {timestamp}", shell=True)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Delete the lockfile
|
||||||
|
os.remove('lockfile')
|
Loading…
Reference in a new issue