diff --git a/layerindex/update_layer.py b/layerindex/update_layer.py index 3ae4f65..fac914c 100644 --- a/layerindex/update_layer.py +++ b/layerindex/update_layer.py @@ -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) diff --git a/layerindex/utils.py b/layerindex/utils.py index ed1ebbc..814dee8 100644 --- a/layerindex/utils.py +++ b/layerindex/utils.py @@ -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() diff --git a/rrs/tools/rrs_distros.py b/rrs/tools/rrs_distros.py index 6942254..41818b4 100755 --- a/rrs/tools/rrs_distros.py +++ b/rrs/tools/rrs_distros.py @@ -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) diff --git a/rrs/tools/rrs_upstream_history.py b/rrs/tools/rrs_upstream_history.py index 3ca3cbc..e9346a1 100755 --- a/rrs/tools/rrs_upstream_history.py +++ b/rrs/tools/rrs_upstream_history.py @@ -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: diff --git a/rrs/tools/upgrade_history_internal.py b/rrs/tools/upgrade_history_internal.py index d58a79d..1f38d66 100644 --- a/rrs/tools/upgrade_history_internal.py +++ b/rrs/tools/upgrade_history_internal.py @@ -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__":