summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2017-04-18 16:19:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-04-05 15:13:47 +0100
commit0652fb68b2b62a1f4800c4befdf92b896d3d9b43 (patch)
tree75f3957a4d22b9d60d83a790479140929099430b
parent0200ab2a22c9d068e307d6e088264b88b662c1ab (diff)
downloadpoky-0652fb68b2b62a1f4800c4befdf92b896d3d9b43.tar.gz
package_manager: don't race on a file when installing complementary packages
PackageManager.install_complementary() uses WORKDIR/installed_pkgs.txt as a temporary file but if two tasks are executing for the same recipe which uses this file (e.g. bitbake my-image my-image:do_populate_sdk) then it's possible for the file to be overwritten or deleted. Instead of using a static filename, use tempfile to generate a unique name and ensure it is cleaned up when finished. Also move the glob generation/expansion earlier in the function as if there are no globs to install, we don't need to generate a package list. (From OE-Core rev: f5a1013ffa9815f22e13989e2bcb83f966e7ce2c) (From OE-Core rev: b02b54192ce71606aac30c21f3ff2199fa70a529) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> [Fixup do to merge conflicts] Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/package_manager.py47
1 files changed, 22 insertions, 25 deletions
diff --git a/meta/lib/oe/package_manager.py b/meta/lib/oe/package_manager.py
index 78d2421421..a20bbd438a 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -570,15 +570,6 @@ class PackageManager(object, metaclass=ABCMeta):
570 installation 570 installation
571 """ 571 """
572 def install_complementary(self, globs=None): 572 def install_complementary(self, globs=None):
573 # we need to write the list of installed packages to a file because the
574 # oe-pkgdata-util reads it from a file
575 installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR', True),
576 "installed_pkgs.txt")
577 with open(installed_pkgs_file, "w+") as installed_pkgs:
578 pkgs = self.list_installed()
579 output = oe.utils.format_pkg_list(pkgs, "arch")
580 installed_pkgs.write(output)
581
582 if globs is None: 573 if globs is None:
583 globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True) 574 globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
584 split_linguas = set() 575 split_linguas = set()
@@ -595,22 +586,28 @@ class PackageManager(object, metaclass=ABCMeta):
595 if globs is None: 586 if globs is None:
596 return 587 return
597 588
598 cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"), 589 # we need to write the list of installed packages to a file because the
599 "-p", self.d.getVar('PKGDATA_DIR', True), "glob", installed_pkgs_file, 590 # oe-pkgdata-util reads it from a file
600 globs] 591 with tempfile.NamedTemporaryFile(mode="w+", prefix="installed-pkgs") as installed_pkgs:
601 exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY', True) 592 pkgs = self.list_installed()
602 if exclude: 593 output = oe.utils.format_pkg_list(pkgs, "arch")
603 cmd.extend(['--exclude=' + '|'.join(exclude.split())]) 594 installed_pkgs.write(output)
604 try: 595
605 bb.note("Installing complementary packages ...") 596 cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"),
606 bb.note('Running %s' % cmd) 597 "-p", self.d.getVar('PKGDATA_DIR', True), "glob", installed_pkgs.name,
607 complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") 598 globs]
608 except subprocess.CalledProcessError as e: 599 exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY', True)
609 bb.fatal("Could not compute complementary packages list. Command " 600 if exclude:
610 "'%s' returned %d:\n%s" % 601 cmd.extend(['--exclude=' + '|'.join(exclude.split())])
611 (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) 602 try:
612 self.install(complementary_pkgs.split(), attempt_only=True) 603 bb.note("Installing complementary packages ...")
613 os.remove(installed_pkgs_file) 604 bb.note('Running %s' % cmd)
605 complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
606 except subprocess.CalledProcessError as e:
607 bb.fatal("Could not compute complementary packages list. Command "
608 "'%s' returned %d:\n%s" %
609 (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
610 self.install(complementary_pkgs.split(), attempt_only=True)
614 611
615 def deploy_dir_lock(self): 612 def deploy_dir_lock(self):
616 if self.deploy_dir is None: 613 if self.deploy_dir is None: