mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 12:49:46 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
0200ab2a22
commit
0652fb68b2
@@ -570,15 +570,6 @@ class PackageManager(object, metaclass=ABCMeta):
|
|||||||
installation
|
installation
|
||||||
"""
|
"""
|
||||||
def install_complementary(self, globs=None):
|
def install_complementary(self, globs=None):
|
||||||
# we need to write the list of installed packages to a file because the
|
|
||||||
# oe-pkgdata-util reads it from a file
|
|
||||||
installed_pkgs_file = os.path.join(self.d.getVar('WORKDIR', True),
|
|
||||||
"installed_pkgs.txt")
|
|
||||||
with open(installed_pkgs_file, "w+") as installed_pkgs:
|
|
||||||
pkgs = self.list_installed()
|
|
||||||
output = oe.utils.format_pkg_list(pkgs, "arch")
|
|
||||||
installed_pkgs.write(output)
|
|
||||||
|
|
||||||
if globs is None:
|
if globs is None:
|
||||||
globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
|
globs = self.d.getVar('IMAGE_INSTALL_COMPLEMENTARY', True)
|
||||||
split_linguas = set()
|
split_linguas = set()
|
||||||
@@ -595,22 +586,28 @@ class PackageManager(object, metaclass=ABCMeta):
|
|||||||
if globs is None:
|
if globs is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"),
|
# we need to write the list of installed packages to a file because the
|
||||||
"-p", self.d.getVar('PKGDATA_DIR', True), "glob", installed_pkgs_file,
|
# oe-pkgdata-util reads it from a file
|
||||||
globs]
|
with tempfile.NamedTemporaryFile(mode="w+", prefix="installed-pkgs") as installed_pkgs:
|
||||||
exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY', True)
|
pkgs = self.list_installed()
|
||||||
if exclude:
|
output = oe.utils.format_pkg_list(pkgs, "arch")
|
||||||
cmd.extend(['--exclude=' + '|'.join(exclude.split())])
|
installed_pkgs.write(output)
|
||||||
try:
|
|
||||||
bb.note("Installing complementary packages ...")
|
cmd = [bb.utils.which(os.getenv('PATH'), "oe-pkgdata-util"),
|
||||||
bb.note('Running %s' % cmd)
|
"-p", self.d.getVar('PKGDATA_DIR', True), "glob", installed_pkgs.name,
|
||||||
complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
|
globs]
|
||||||
except subprocess.CalledProcessError as e:
|
exclude = self.d.getVar('PACKAGE_EXCLUDE_COMPLEMENTARY', True)
|
||||||
bb.fatal("Could not compute complementary packages list. Command "
|
if exclude:
|
||||||
"'%s' returned %d:\n%s" %
|
cmd.extend(['--exclude=' + '|'.join(exclude.split())])
|
||||||
(' '.join(cmd), e.returncode, e.output.decode("utf-8")))
|
try:
|
||||||
self.install(complementary_pkgs.split(), attempt_only=True)
|
bb.note("Installing complementary packages ...")
|
||||||
os.remove(installed_pkgs_file)
|
bb.note('Running %s' % cmd)
|
||||||
|
complementary_pkgs = subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode("utf-8")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
bb.fatal("Could not compute complementary packages list. Command "
|
||||||
|
"'%s' returned %d:\n%s" %
|
||||||
|
(' '.join(cmd), e.returncode, e.output.decode("utf-8")))
|
||||||
|
self.install(complementary_pkgs.split(), attempt_only=True)
|
||||||
|
|
||||||
def deploy_dir_lock(self):
|
def deploy_dir_lock(self):
|
||||||
if self.deploy_dir is None:
|
if self.deploy_dir is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user