[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1005141: linux-perf: Removes diversions on upgrade breaking it



Control: tags -1 + confirmed patch

On Mon, Feb 07, 2022 at 08:57:22PM +0100, Guillem Jover wrote:
> Package: linux-perf
> Version: 5.16.3-1~exp1
> Severity: serious
> 
> Hi!
> 
> This package has code in its postrm maintscript, which unconditionally
> removes the diversion, which breaks as the rename cannot be performed
> due to linux-base owning the file, and dpkg-divert refusing to
> overwrite it. This is the error shown:
> 
>   ,---
>   # dpkg -i linux-perf_5.16.7-1_amd64.deb
>   (Reading database ... 280997 files and directories currently installed.)
>   Preparing to unpack linux-perf_5.16.7-1_amd64.deb ...
>   Leaving 'diversion of /usr/bin/perf to /usr/bin/perf.wrapper by linux-perf'
>   Leaving 'diversion of /usr/share/bash-completion/completions/perf to /usr/share/bash-completion/completions/perf.wrapper by linux-perf'
>   Leaving 'diversion of /usr/share/man/man1/perf.1.gz to /usr/share/man/man1/perf.wrapper.1.gz by linux-perf'
>   Unpacking linux-perf (5.16.7-1) over (5.16.7-1) ...
>   Removing 'diversion of /usr/bin/perf to /usr/bin/perf.wrapper by linux-perf'
>   dpkg-divert: error: rename involves overwriting '/usr/bin/perf' with
>     different file '/usr/bin/perf.wrapper', not allowed
>   dpkg: warning: old linux-perf package post-removal script subprocess returned error exit status 2
>   dpkg: trying script from the new package instead ...
>   Removing 'diversion of /usr/bin/perf to /usr/bin/perf.wrapper by linux-perf'
>   dpkg-divert: error: rename involves overwriting '/usr/bin/perf' with
>     different file '/usr/bin/perf.wrapper', not allowed
>   dpkg: error processing archive linux-perf_5.16.7-1_amd64.deb (--install):
>    new linux-perf package post-removal script subprocess returned error exit status 2
>   Leaving 'diversion of /usr/bin/perf to /usr/bin/perf.wrapper by linux-perf'
>   Leaving 'diversion of /usr/share/bash-completion/completions/perf to /usr/share/bash-completion/completions/perf.wrapper by linux-perf'
>   Leaving 'diversion of /usr/share/man/man1/perf.1.gz to /usr/share/man/man1/perf.wrapper.1.gz by linux-perf'
>   Removing 'diversion of /usr/bin/perf to /usr/bin/perf.wrapper by linux-perf'
>   dpkg-divert: error: rename involves overwriting '/usr/bin/perf' with
>     different file '/usr/bin/perf.wrapper', not allowed
>   dpkg: error while cleaning up:
>    new linux-perf package post-removal script subprocess returned error exit status 2
>   Processing triggers for man-db (2.10.0-2) ...
>   [main a8458e04] Commit dpkg db updates
>    1 file changed, 2 insertions(+), 1 deletion(-)
>   Errors were encountered while processing:
>    linux-perf_5.16.7-1_amd64.deb
>   `---
> 
> The dpkg-divert calls should be protected to run only on the relevant
> actions on all maintscripts.

Need to test it (if I have not done a thinko), but the following
should do it.

Regards,
Salvatore
>From 669eb799ef017db2433511dfa737fad2585c31b0 Mon Sep 17 00:00:00 2001
From: Salvatore Bonaccorso <carnil@debian.org>
Date: Tue, 8 Feb 2022 13:09:31 +0100
Subject: [PATCH] linux-perf: Protect invocation of dpkg-divert to run only on
 relevant actions in maintscripts

Thanks: Guillem Jover
Closes: #1005141
---
 debian/changelog                 |  7 +++++++
 debian/templates/perf.postrm.in  | 17 ++++++++++-------
 debian/templates/perf.preinst.in | 17 ++++++++++-------
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 3c1b9aa5b5ef..bd6916c658ed 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+linux (5.16.7-2) UNRELEASED; urgency=medium
+
+  * linux-perf: Protect invocation of dpkg-divert to run only on relevant
+    actions in maintscripts. Thanks to Guillem Jover (Closes: #1005141)
+
+ -- Salvatore Bonaccorso <carnil@debian.org>  Tue, 08 Feb 2022 13:11:50 +0100
+
 linux (5.16.7-1) unstable; urgency=medium
 
   * New upstream stable update:
diff --git a/debian/templates/perf.postrm.in b/debian/templates/perf.postrm.in
index d33fdfef0cce..84a6e3df5ba4 100644
--- a/debian/templates/perf.postrm.in
+++ b/debian/templates/perf.postrm.in
@@ -8,12 +8,15 @@ if [ "$old_version_suffix" ]; then
 	/usr/share/doc/linux-perf "linux-perf-${old_version_suffix}" 5.16\~rc8-1\~exp1 linux-perf -- "$@"
 fi
 
-for wrapper in /usr/bin/perf \
-	       /usr/share/bash-completion/completions/perf \
-	       /usr/share/man/man1/perf.1.gz; do
-    diversion="${wrapper%/perf*}/perf.wrapper${wrapper#*/perf}"
-    dpkg-divert --package linux-perf --divert "$diversion" --rename \
-	--remove "$wrapper"
-done
+if [ "$1" = remove ]
+then
+	for wrapper in /usr/bin/perf \
+		       /usr/share/bash-completion/completions/perf \
+		       /usr/share/man/man1/perf.1.gz; do
+	    diversion="${wrapper%/perf*}/perf.wrapper${wrapper#*/perf}"
+	    dpkg-divert --package linux-perf --divert "$diversion" --rename \
+		--remove "$wrapper"
+	done
+fi
 
 #DEBHELPER#
diff --git a/debian/templates/perf.preinst.in b/debian/templates/perf.preinst.in
index 6a5ce7df164b..8965a322f2f9 100644
--- a/debian/templates/perf.preinst.in
+++ b/debian/templates/perf.preinst.in
@@ -8,12 +8,15 @@ if [ "$old_version_suffix" ]; then
 	/usr/share/doc/linux-perf "linux-perf-${old_version_suffix}" 5.16\~rc8-1\~exp1 linux-perf -- "$@"
 fi
 
-for wrapper in /usr/bin/perf \
-	       /usr/share/bash-completion/completions/perf \
-	       /usr/share/man/man1/perf.1.gz; do
-    diversion="${wrapper%/perf*}/perf.wrapper${wrapper#*/perf}"
-    dpkg-divert --package linux-perf --divert "$diversion" --rename \
-	--add "$wrapper"
-done
+if [ "$1" = install ] || [ "$1" = upgrade ]
+then
+	for wrapper in /usr/bin/perf \
+		       /usr/share/bash-completion/completions/perf \
+		       /usr/share/man/man1/perf.1.gz; do
+	    diversion="${wrapper%/perf*}/perf.wrapper${wrapper#*/perf}"
+	    dpkg-divert --package linux-perf --divert "$diversion" --rename \
+		--add "$wrapper"
+	done
+fi
 
 #DEBHELPER#
-- 
2.34.1


Reply to: