diff options
author | Ross Burton <ross.burton@arm.com> | 2022-10-10 11:53:52 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-10-25 13:42:03 +0100 |
commit | 79af23dc5ef18e5c786c1b2f067be9a9c99c408e (patch) | |
tree | 5b3e10331d14bf03da3e0da04e3584e86fb770a4 /meta/lib | |
parent | 5f6076803027b00b182f496a59c8c9006fc27e90 (diff) | |
download | poky-79af23dc5ef18e5c786c1b2f067be9a9c99c408e.tar.gz |
oe/packagemanager/rpm: don't leak file objects
(From OE-Core rev: 28706c27680745c9f8df27713ce63ef5d611138c)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/package_manager/rpm/__init__.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/meta/lib/oe/package_manager/rpm/__init__.py b/meta/lib/oe/package_manager/rpm/__init__.py index 18ec5c895d..fa218485f5 100644 --- a/meta/lib/oe/package_manager/rpm/__init__.py +++ b/meta/lib/oe/package_manager/rpm/__init__.py | |||
@@ -98,11 +98,15 @@ class RpmPM(PackageManager): | |||
98 | archs = ["sdk_provides_dummy_target"] + archs | 98 | archs = ["sdk_provides_dummy_target"] + archs |
99 | confdir = "%s/%s" %(self.target_rootfs, "etc/dnf/vars/") | 99 | confdir = "%s/%s" %(self.target_rootfs, "etc/dnf/vars/") |
100 | bb.utils.mkdirhier(confdir) | 100 | bb.utils.mkdirhier(confdir) |
101 | open(confdir + "arch", 'w').write(":".join(archs)) | 101 | with open(confdir + "arch", 'w') as f: |
102 | f.write(":".join(archs)) | ||
103 | |||
102 | distro_codename = self.d.getVar('DISTRO_CODENAME') | 104 | distro_codename = self.d.getVar('DISTRO_CODENAME') |
103 | open(confdir + "releasever", 'w').write(distro_codename if distro_codename is not None else '') | 105 | with open(confdir + "releasever", 'w') as f: |
106 | f.write(distro_codename if distro_codename is not None else '') | ||
104 | 107 | ||
105 | open(oe.path.join(self.target_rootfs, "etc/dnf/dnf.conf"), 'w').write("") | 108 | with open(oe.path.join(self.target_rootfs, "etc/dnf/dnf.conf"), 'w') as f: |
109 | f.write("") | ||
106 | 110 | ||
107 | 111 | ||
108 | def _configure_rpm(self): | 112 | def _configure_rpm(self): |
@@ -112,14 +116,17 @@ class RpmPM(PackageManager): | |||
112 | platformconfdir = "%s/%s" %(self.target_rootfs, "etc/rpm/") | 116 | platformconfdir = "%s/%s" %(self.target_rootfs, "etc/rpm/") |
113 | rpmrcconfdir = "%s/%s" %(self.target_rootfs, "etc/") | 117 | rpmrcconfdir = "%s/%s" %(self.target_rootfs, "etc/") |
114 | bb.utils.mkdirhier(platformconfdir) | 118 | bb.utils.mkdirhier(platformconfdir) |
115 | open(platformconfdir + "platform", 'w').write("%s-pc-linux" % self.primary_arch) | 119 | with open(platformconfdir + "platform", 'w') as f: |
120 | f.write("%s-pc-linux" % self.primary_arch) | ||
116 | with open(rpmrcconfdir + "rpmrc", 'w') as f: | 121 | with open(rpmrcconfdir + "rpmrc", 'w') as f: |
117 | f.write("arch_compat: %s: %s\n" % (self.primary_arch, self.archs if len(self.archs) > 0 else self.primary_arch)) | 122 | f.write("arch_compat: %s: %s\n" % (self.primary_arch, self.archs if len(self.archs) > 0 else self.primary_arch)) |
118 | f.write("buildarch_compat: %s: noarch\n" % self.primary_arch) | 123 | f.write("buildarch_compat: %s: noarch\n" % self.primary_arch) |
119 | 124 | ||
120 | open(platformconfdir + "macros", 'w').write("%_transaction_color 7\n") | 125 | with open(platformconfdir + "macros", 'w') as f: |
126 | f.write("%_transaction_color 7\n") | ||
121 | if self.d.getVar('RPM_PREFER_ELF_ARCH'): | 127 | if self.d.getVar('RPM_PREFER_ELF_ARCH'): |
122 | open(platformconfdir + "macros", 'a').write("%%_prefer_color %s" % (self.d.getVar('RPM_PREFER_ELF_ARCH'))) | 128 | with open(platformconfdir + "macros", 'a') as f: |
129 | f.write("%%_prefer_color %s" % (self.d.getVar('RPM_PREFER_ELF_ARCH'))) | ||
123 | 130 | ||
124 | if self.d.getVar('RPM_SIGN_PACKAGES') == '1': | 131 | if self.d.getVar('RPM_SIGN_PACKAGES') == '1': |
125 | signer = get_signer(self.d, self.d.getVar('RPM_GPG_BACKEND')) | 132 | signer = get_signer(self.d, self.d.getVar('RPM_GPG_BACKEND')) |
@@ -166,13 +173,13 @@ class RpmPM(PackageManager): | |||
166 | repo_uri = uri + "/" + arch | 173 | repo_uri = uri + "/" + arch |
167 | repo_id = "oe-remote-repo" + "-".join(urlparse(repo_uri).path.split("/")) | 174 | repo_id = "oe-remote-repo" + "-".join(urlparse(repo_uri).path.split("/")) |
168 | repo_name = "OE Remote Repo:" + " ".join(urlparse(repo_uri).path.split("/")) | 175 | repo_name = "OE Remote Repo:" + " ".join(urlparse(repo_uri).path.split("/")) |
169 | open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'a').write( | 176 | with open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'a') as f: |
170 | "[%s]\nname=%s\nbaseurl=%s\n%s\n" % (repo_id, repo_name, repo_uri, gpg_opts)) | 177 | f.write("[%s]\nname=%s\nbaseurl=%s\n%s\n" % (repo_id, repo_name, repo_uri, gpg_opts)) |
171 | else: | 178 | else: |
172 | repo_name = "OE Remote Repo:" + " ".join(urlparse(uri).path.split("/")) | 179 | repo_name = "OE Remote Repo:" + " ".join(urlparse(uri).path.split("/")) |
173 | repo_uri = uri | 180 | repo_uri = uri |
174 | open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'w').write( | 181 | with open(oe.path.join(self.target_rootfs, "etc", "yum.repos.d", repo_base + ".repo"), 'w') as f: |
175 | "[%s]\nname=%s\nbaseurl=%s\n%s" % (repo_base, repo_name, repo_uri, gpg_opts)) | 182 | f.write("[%s]\nname=%s\nbaseurl=%s\n%s" % (repo_base, repo_name, repo_uri, gpg_opts)) |
176 | 183 | ||
177 | def _prepare_pkg_transaction(self): | 184 | def _prepare_pkg_transaction(self): |
178 | os.environ['D'] = self.target_rootfs | 185 | os.environ['D'] = self.target_rootfs |
@@ -331,7 +338,8 @@ class RpmPM(PackageManager): | |||
331 | return e.output.decode("utf-8") | 338 | return e.output.decode("utf-8") |
332 | 339 | ||
333 | def dump_install_solution(self, pkgs): | 340 | def dump_install_solution(self, pkgs): |
334 | open(self.solution_manifest, 'w').write(" ".join(pkgs)) | 341 | with open(self.solution_manifest, 'w') as f: |
342 | f.write(" ".join(pkgs)) | ||
335 | return pkgs | 343 | return pkgs |
336 | 344 | ||
337 | def load_old_install_solution(self): | 345 | def load_old_install_solution(self): |
@@ -365,7 +373,8 @@ class RpmPM(PackageManager): | |||
365 | bb.utils.mkdirhier(target_path) | 373 | bb.utils.mkdirhier(target_path) |
366 | num = self._script_num_prefix(target_path) | 374 | num = self._script_num_prefix(target_path) |
367 | saved_script_name = oe.path.join(target_path, "%d-%s" % (num, pkg)) | 375 | saved_script_name = oe.path.join(target_path, "%d-%s" % (num, pkg)) |
368 | open(saved_script_name, 'w').write(output) | 376 | with open(saved_script_name, 'w') as f: |
377 | f.write(output) | ||
369 | os.chmod(saved_script_name, 0o755) | 378 | os.chmod(saved_script_name, 0o755) |
370 | 379 | ||
371 | def _handle_intercept_failure(self, registered_pkgs): | 380 | def _handle_intercept_failure(self, registered_pkgs): |