summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/package_manager.py
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2017-04-18 16:19:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-04-19 10:18:43 +0100
commitae5d6431145b62aca79db7e3d7854d30a74e2311 (patch)
treeadadfd1eda646d28b8570c7a3713f6d228eddc8a /meta/lib/oe/package_manager.py
parent4c6d7a20bcdc5cbe0d50ccb6fb4848631407e257 (diff)
downloadpoky-ae5d6431145b62aca79db7e3d7854d30a74e2311.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) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/package_manager.py')
-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 60d6e52a58..f7190cf0b9 100644
--- a/meta/lib/oe/package_manager.py
+++ b/meta/lib/oe/package_manager.py
@@ -377,15 +377,6 @@ class PackageManager(object, metaclass=ABCMeta):
377 installation 377 installation
378 """ 378 """
379 def install_complementary(self, globs=None): 379 def install_complementary(self, globs=None):
380 # we need to write the list of installed packages to a file because the
381 # oe-pkgdata-util reads it from a file
382 installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR'),
383 "installed_pkgs.txt")
384 with open(installed_pkgs_file, "w+") as installed_pkgs:
385 pkgs = self.list_installed()
386 output = oe.utils.format_pkg_list(pkgs, "arch")
387 installed_pkgs.write(output)
388
389 if globs is None: 380 if globs is None:
390 globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY') 381 globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY')
391 split_linguas = set() 382 split_linguas = set()
@@ -402,22 +393,28 @@ class PackageManager(object, metaclass=ABCMeta):
402 if globs is None: 393 if globs is None:
403 return 394 return
404 395
405 cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"), 396 # we need to write the list of installed packages to a file because the
406 "-p", self.d.getVar('PKGDATA_DIR'), "glob", installed_pkgs_file, 397 # oe-pkgdata-util reads it from a file
407 globs] 398 with tempfile.NamedTemporaryFile(mode="w+", prefix="installed-pkgs") as installed_pkgs:
408 exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY') 399 pkgs = self.list_installed()
409 if exclude: 400 output = oe.utils.format_pkg_list(pkgs, "arch")
410 cmd.extend(['--exclude=' + '|'.join(exclude.split())]) 401 installed_pkgs.write(output)
411 try: 402
412 bb.note("Installing complementary packages ...") 403 cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"),
413 bb.note('Running %s' % cmd) 404 "-p", self.d.getVar('PKGDATA_DIR'), "glob", installed_pkgs.name,
414 complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8") 405 globs]
415 except subprocess.CalledProcessError as e: 406 exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY')
416 bb.fatal("Could not compute complementary packages list. Command " 407 if exclude:
417 "'%s' returned %d:\n%s" % 408 cmd.extend(['--exclude=' + '|'.join(exclude.split())])
418 (' '.join(cmd), e.returncode, e.output.decode("utf-8"))) 409 try:
419 self.install(complementary_pkgs.split(), attempt_only=True) 410 bb.note("Installing complementary packages ...")
420 os.remove(installed_pkgs_file) 411 bb.note('Running %s' % cmd)
412 complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
413 except subprocess.CalledProcessError as e:
414 bb.fatal("Could not compute complementary packages list. Command "
415 "'%s' returned %d:\n%s" %
416 (' '.join(cmd), e.returncode, e.output.decode("utf-8")))
417 self.install(complementary_pkgs.split(), attempt_only=True)
421 418
422 def deploy_dir_lock(self): 419 def deploy_dir_lock(self):
423 if self.deploy_dir is None: 420 if self.deploy_dir is None: