Skip to content

Commit 0088d04

Browse files
committed
Fix parsing of dpkg-query for old kernel packages
When looking for packages that own a directory in /lib/modules, it returns a comma-delimited list including both header and kernel packages. This properly separates them so that the purge step correctly uninstalls both packages, instead of a nonexistent package.
1 parent 76fddb8 commit 0088d04

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

library/collect_kernel_info.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434
latest_kernel = kernel
3535

3636
booted_kernel = "/lib/modules/{}".format(to_text(
37-
subprocess.run(["uname", "-r"], capture_output=True).stdout.strip))
37+
subprocess.run(["uname", "-r"], capture_output=True).stdout).strip())
3838

3939
booted_kernel_package = ""
4040
old_kernel_packages = []
@@ -50,18 +50,19 @@ def main():
5050
if e.stderr.startswith(b"dpkg-query: no path found matching"):
5151
continue
5252
raise e
53+
pkgs = to_text(sp.stdout).split(":")[0].split(", ")
5354
if kernel.split("/")[-1] == booted_kernel.split("/")[-1]:
54-
booted_kernel_package = to_text(sp.stdout).split(":")[0]
55+
booted_kernel_packages = pkgs
5556
elif kernel != latest_kernel:
56-
old_kernel_packages.append(to_text(sp.stdout).split(":")[0])
57+
old_kernel_packages.extend(pkgs)
5758

5859
# returns True if we're not booted into the latest kernel
5960
new_kernel_exists = booted_kernel.split("/")[-1] != latest_kernel.split("/")[-1]
6061
module.exit_json(
6162
changed=False,
6263
new_kernel_exists=new_kernel_exists,
6364
old_packages=old_kernel_packages,
64-
booted_package=booted_kernel_package
65+
booted_packages=booted_kernel_packages
6566
)
6667

6768

0 commit comments

Comments
 (0)