Fix errors due to races deleting bitbake temp files

Errors deleting bitbake.sock and bitbake.lock have been observed when
shutting down tinfoil at the end of some of these scripts. Move the code
used in the main layer index update script to a function in utils.py and
use it everywhere in order to avoid the issue.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-01-22 13:57:22 +13:00
parent 0929289465
commit 2c3c287a33
5 changed files with 22 additions and 15 deletions

View File

@ -41,14 +41,6 @@ class DryRunRollbackException(Exception):
pass
def rm_tempdir_onerror(fn, fullname, exc_info):
# Avoid errors when we're racing against bitbake deleting bitbake.lock/bitbake.sock
# (and anything else it happens to create in our temporary build directory in future)
if isinstance(exc_info[1], OSError) and exc_info[1].errno == errno.ENOENT:
pass
else:
raise
def check_machine_conf(path, subdir_start):
subpath = path[len(subdir_start):]
res = conf_re.match(subpath)
@ -860,7 +852,7 @@ def main():
logger.debug('Preserving temp directory %s' % tempdir)
else:
logger.debug('Deleting temp directory')
shutil.rmtree(tempdir, onerror=rm_tempdir_onerror)
utils.rmtree_force(tempdir)
sys.exit(0)

View File

@ -13,6 +13,8 @@ import logging
import time
import fcntl
import signal
import errno
import shutil
import codecs
import re
from datetime import datetime
@ -383,6 +385,22 @@ def lock_file(fn, timeout=30, logger=None):
def unlock_file(lock):
fcntl.flock(lock, fcntl.LOCK_UN)
def rmtree_force(pth):
"""
Delete a directory tree ignoring any ENOENT errors.
Mainly used to avoid errors when we're racing against bitbake deleting bitbake.lock/bitbake.sock
(and anything else it happens to create in our temporary build directory in future)
"""
def rmtree_force_onerror(fn, fullname, exc_info):
if isinstance(exc_info[1], OSError) and exc_info[1].errno == errno.ENOENT:
pass
else:
raise
shutil.rmtree(pth, onerror=rmtree_force_onerror)
def chain_unique(*iterables):
"""Chain unique objects in a list of querysets, preserving order"""
seen = set()

View File

@ -12,7 +12,6 @@ import os.path
import optparse
import logging
from datetime import datetime
import shutil
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
from common import common_setup, load_recipes, \
@ -168,4 +167,4 @@ if __name__=="__main__":
pass
finally:
tinfoil.shutdown()
shutil.rmtree(tempdir)
utils.rmtree_force(tempdir)

View File

@ -12,7 +12,6 @@ import os.path
import optparse
import logging
from datetime import datetime
import shutil
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
from common import common_setup, load_recipes, \
@ -228,7 +227,7 @@ if __name__=="__main__":
finally:
tinfoil.shutdown()
shutil.rmtree(tempdir)
utils.rmtree_force(tempdir)
if options.dry_run:
raise DryRunRollbackException
except DryRunRollbackException:

View File

@ -16,7 +16,6 @@ import optparse
import logging
import re
from distutils.version import LooseVersion
import shutil
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__))))
from common import common_setup, get_pv_type, load_recipes, \
@ -245,7 +244,7 @@ def generate_history(options, layerbranch_id, commit, logger):
finally:
if tinfoil and hasattr(tinfoil, 'shutdown') and (LooseVersion(bb.__version__) > LooseVersion("1.27")):
tinfoil.shutdown()
shutil.rmtree(tempdir)
utils.rmtree_force(tempdir)
if __name__=="__main__":