mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Implement locking for update/bulkchange process
Avoid the possibility of these two clashing especially when multiple branches are being used. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
1643aef67d
commit
1eebd6e525
|
@ -215,6 +215,12 @@ def main():
|
||||||
fetchdir = settings.LAYER_FETCH_DIR
|
fetchdir = settings.LAYER_FETCH_DIR
|
||||||
bitbakepath = os.path.join(fetchdir, 'bitbake')
|
bitbakepath = os.path.join(fetchdir, 'bitbake')
|
||||||
|
|
||||||
|
lockfn = os.path.join(fetchdir, "layerindex.lock")
|
||||||
|
lockfile = utils.lock_file(lockfn)
|
||||||
|
if not lockfile:
|
||||||
|
sys.stderr.write("Layer index lock timeout expired\n")
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, True)
|
(tinfoil, tempdir) = recipeparse.init_parser(settings, branch, bitbakepath, True)
|
||||||
|
|
||||||
changeset = get_changeset(sys.argv[1])
|
changeset = get_changeset(sys.argv[1])
|
||||||
|
@ -223,6 +229,9 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
outp = generate_patches(tinfoil, fetchdir, changeset, sys.argv[2])
|
outp = generate_patches(tinfoil, fetchdir, changeset, sys.argv[2])
|
||||||
|
finally:
|
||||||
|
utils.unlock_file(lockfile)
|
||||||
|
|
||||||
if outp:
|
if outp:
|
||||||
print outp
|
print outp
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -174,6 +174,12 @@ def main():
|
||||||
fetchedrepos = []
|
fetchedrepos = []
|
||||||
failedrepos = []
|
failedrepos = []
|
||||||
|
|
||||||
|
lockfn = os.path.join(fetchdir, "layerindex.lock")
|
||||||
|
lockfile = utils.lock_file(lockfn)
|
||||||
|
if not lockfile:
|
||||||
|
logger.error("Layer index lock timeout expired")
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
bitbakepath = os.path.join(fetchdir, 'bitbake')
|
bitbakepath = os.path.join(fetchdir, 'bitbake')
|
||||||
|
|
||||||
if not options.nofetch:
|
if not options.nofetch:
|
||||||
|
@ -513,6 +519,9 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
transaction.leave_transaction_management()
|
transaction.leave_transaction_management()
|
||||||
|
|
||||||
|
finally:
|
||||||
|
utils.unlock_file(lockfile)
|
||||||
|
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ import sys
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
import fcntl
|
||||||
|
|
||||||
def get_branch(branchname):
|
def get_branch(branchname):
|
||||||
from layerindex.models import Branch
|
from layerindex.models import Branch
|
||||||
|
@ -63,3 +65,18 @@ def logger_create(name):
|
||||||
logger.addHandler(loggerhandler)
|
logger.addHandler(loggerhandler)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
def lock_file(fn):
|
||||||
|
starttime = time.time()
|
||||||
|
while True:
|
||||||
|
lock = open(fn, 'w')
|
||||||
|
try:
|
||||||
|
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
return lock
|
||||||
|
except IOError:
|
||||||
|
lock.close()
|
||||||
|
if time.time() - starttime > 30:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def unlock_file(lock):
|
||||||
|
fcntl.flock(lock, fcntl.LOCK_UN)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user