Package: libsane1
Version: 1.2.1-5
Severity: important
Tags: patch
User: [email protected]
Usertags: dep17p7
X-Debbugs-Cc: [email protected]

Dear Maintainer,

libsane1 contains udev files which are installed to /lib; these files
need to be moved to /usr/lib as part of Debian's usr-merge effort.
Because libsane1 is Multi-Arch: same, an unfortunate corner-case can
occur whereby shared files (such as the udev rules) may be erroneously
removed on upgrades (please see DEP17[1] P7: Shared multiarch file
loss).

You will find a patch attached to move the udev files, including the
mitigation for the file loss scenario. Alternatively, you can also find
the commit in this git repository[2].

Please consider applying this patch at your earliest convenience. This
bug will be upgraded to release critical soon, as it blocks the overall
usr-merge effort which is being undertaken for the trixie release.


Many thanks,
Chris

1. https://subdivi.de/~helmut/dep17.html
2. 
https://salsa.debian.org/zeha/sane-backends/-/commits/zeha-usrmerge-move-rules
From 852ece16e1935d3b2e186783799a9c545704bbd6 Mon Sep 17 00:00:00 2001
From: Chris Hofstaedtler <[email protected]>
Date: Wed, 22 Nov 2023 13:21:49 +0100
Subject: [PATCH] Move udev files to /usr

---
 debian/changelog                              |  8 +++++
 debian/libsane1.dirs                          |  2 +-
 debian/libsane1.install                       |  3 +-
 debian/libsane1.lintian-overrides             |  6 ++++
 debian/libsane1.postinst                      | 17 ++++++++++
 debian/libsane1.postrm                        | 23 +++++++++++++
 debian/libsane1.preinst                       | 22 +++++++++++++
 .../0725-fix_link_60-libsane_rule.patch       | 33 -------------------
 debian/patches/series                         |  1 -
 debian/rules                                  | 30 ++++++++---------
 10 files changed, 93 insertions(+), 52 deletions(-)
 create mode 100644 debian/libsane1.lintian-overrides
 create mode 100644 debian/libsane1.postrm
 create mode 100644 debian/libsane1.preinst
 delete mode 100644 debian/patches/0725-fix_link_60-libsane_rule.patch

diff --git a/debian/changelog b/debian/changelog
index e6466d2..4d5aa9e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+sane-backends (1.2.1-6~) UNRELEASED; urgency=medium
+
+  * libsane1: move udev files to /usr, with protective diversion
+    against m-a: same file loss on upgrades (DEP17 P7 M10). Diversion can be
+    removed in forky+1. (Closes: #-1)
+
+ -- Chris Hofstaedtler <[email protected]>  Wed, 22 Nov 2023 13:20:54 +0100
+
 sane-backends (1.2.1-5) unstable; urgency=medium
 
   * debian/rules:
diff --git a/debian/libsane1.dirs b/debian/libsane1.dirs
index ad3a3cc..a2b7938 100644
--- a/debian/libsane1.dirs
+++ b/debian/libsane1.dirs
@@ -1 +1 @@
-/lib/udev/hwdb.d/
+/usr/lib/udev/hwdb.d/
diff --git a/debian/libsane1.install b/debian/libsane1.install
index ba37095..bd940fe 100644
--- a/debian/libsane1.install
+++ b/debian/libsane1.install
@@ -1,3 +1,4 @@
 usr/lib/*/*.so.*
 usr/lib/*/sane/*.so.*
-debian/99-libsane1.rules /lib/udev/rules.d/
+debian/60-libsane1.rules /usr/lib/udev/rules.d/
+debian/99-libsane1.rules /usr/lib/udev/rules.d/
diff --git a/debian/libsane1.lintian-overrides 
b/debian/libsane1.lintian-overrides
new file mode 100644
index 0000000..df62ec5
--- /dev/null
+++ b/debian/libsane1.lintian-overrides
@@ -0,0 +1,6 @@
+# begin-remove-after: released:forky
+# protective diversion for upgrades of files moved from / to /usr
+libsane1: diversion-for-unknown-file lib/udev/hwdb.d/20-sane.hwdb [preinst:*]
+libsane1: diversion-for-unknown-file lib/udev/rules.d/60-libsane1.rules 
[preinst:*]
+libsane1: diversion-for-unknown-file lib/udev/rules.d/99-libsane1.rules 
[preinst:*]
+# end-remove-after
diff --git a/debian/libsane1.postinst b/debian/libsane1.postinst
index 971103e..d327aa0 100644
--- a/debian/libsane1.postinst
+++ b/debian/libsane1.postinst
@@ -1,6 +1,23 @@
 #!/bin/sh
 set -e
 
+# begin-remove-after: released:forky
+# protective diversion of files moved from / to /usr, to avoid file loss.
+# Only for upgrades.
+if [ "$1" = "configure" ]; then
+    # At this point, the package will have installed the same file in */usr*.
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/hwdb.d/20-sane.hwdb.usr-is-merged \
+        --remove /lib/udev/hwdb.d/20-sane.hwdb
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/60-libsane1.rules.usr-is-merged \
+        --remove /lib/udev/rules.d/60-libsane1.rules
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/99-libsane1.rules.usr-is-merged \
+        --remove /lib/udev/rules.d/99-libsane1.rules
+fi
+# end-remove-after
+
 case "$1" in
     configure)
     # Add the scanner system group if it doesn't exist
diff --git a/debian/libsane1.postrm b/debian/libsane1.postrm
new file mode 100644
index 0000000..6fbd208
--- /dev/null
+++ b/debian/libsane1.postrm
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+set -e
+
+# begin-remove-after: released:forky
+# protective diversion of files moved from / to /usr, to avoid file loss.
+# Only for upgrades.
+if [ "$1" = "remove" ] && [ "$DPKG_MAINTSCRIPT_PACKAGE_REFCOUNT" = "1" ]; then
+    # Cleanup in case package is removed before upgrade is finished (postinst 
ran).
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/hwdb.d/20-sane.hwdb.usr-is-merged \
+        --remove /lib/udev/hwdb.d/20-sane.hwdb
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/60-libsane1.rules.usr-is-merged \
+        --remove /lib/udev/rules.d/60-libsane1.rules
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/99-libsane1.rules.usr-is-merged \
+        --remove /lib/udev/rules.d/99-libsane1.rules
+fi
+# end-remove-after
+
+#DEBHELPER#
+
diff --git a/debian/libsane1.preinst b/debian/libsane1.preinst
new file mode 100644
index 0000000..9ca1e19
--- /dev/null
+++ b/debian/libsane1.preinst
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -e
+
+# begin-remove-after: released:forky
+# protective diversion of files moved from / to /usr, to avoid file loss.
+# Only for upgrades.
+if [ "$1" = "upgrade" ]; then
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/hwdb.d/20-sane.hwdb.usr-is-merged \
+        --add /lib/udev/hwdb.d/20-sane.hwdb
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/60-libsane1.rules.usr-is-merged \
+        --add /lib/udev/rules.d/60-libsane1.rules
+    dpkg-divert --package usr-is-merged --no-rename \
+        --divert /lib/udev/rules.d/99-libsane1.rules.usr-is-merged \
+        --add /lib/udev/rules.d/99-libsane1.rules
+fi
+# end-remove-after
+
+#DEBHELPER#
+
diff --git a/debian/patches/0725-fix_link_60-libsane_rule.patch 
b/debian/patches/0725-fix_link_60-libsane_rule.patch
deleted file mode 100644
index 0b424e2..0000000
--- a/debian/patches/0725-fix_link_60-libsane_rule.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-Description: Fix directory for 20-sane.hwdb
-Author: Jörg Frings-Fürst <[email protected]>
-Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916239
-Forwarded: not-needed
-Last-Update: 2019-04-27
----
-This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
-Index: trunk/tools/sane-desc.c
-===================================================================
---- trunk.orig/tools/sane-desc.c
-+++ trunk/tools/sane-desc.c
-@@ -3649,7 +3649,7 @@ print_udevhwdb_header (void)
-     ("#\n"
-      "# udev rules file for supported USB and SCSI devices\n"
-      "#\n"
--     "# For the list of supported USB devices see 
/usr/lib/udev/hwdb.d/20-sane.hwdb\n"
-+     "# For the list of supported USB devices see 
/lib/udev/hwdb.d/20-sane.hwdb\n"
-      "#\n"
-      "# The SCSI device support is very basic and includes only\n"
-      "# scanners that mark themselves as type \"scanner\" or\n"
-Index: trunk/testsuite/tools/data/udev+hwdb.ref
-===================================================================
---- trunk.orig/testsuite/tools/data/udev+hwdb.ref
-+++ trunk/testsuite/tools/data/udev+hwdb.ref
-@@ -3,7 +3,7 @@
- #
- # udev rules file for supported USB and SCSI devices
- #
--# For the list of supported USB devices see /usr/lib/udev/hwdb.d/20-sane.hwdb
-+# For the list of supported USB devices see /lib/udev/hwdb.d/20-sane.hwdb
- #
- # The SCSI device support is very basic and includes only
- # scanners that mark themselves as type "scanner" or
diff --git a/debian/patches/series b/debian/patches/series
index 81eddad..ac4a4b6 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -5,7 +5,6 @@
 0140-avahi.patch
 0145-avahi.patch
 0705-kfreebsd.patch
-0725-fix_link_60-libsane_rule.patch
 0150-i386-test.patch
 0155-hurd_PATH_MAX.patch
 0050-Use-python3-shebang.patch
diff --git a/debian/rules b/debian/rules
index 03d63c3..d4168f2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -85,12 +85,26 @@ override_dh_auto_install-indep:
        $(RM) debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/sane/libsane-dll.*
 
 override_dh_install-arch:
+ifeq (linux,$(DEB_HOST_ARCH_OS))
+       # udev support
+       # Generate the udev rules file
+       $(SANE_DESC) -s $(CURDIR)/doc/descriptions -m udev+hwdb > 
$(CURDIR)/debian/60-libsane1.rules
+       $(SANE_DESC) -s $(CURDIR)/doc/descriptions -m hwdb > 
$(CURDIR)/debian/20-sane.hwdb
+
+       cp $(CURDIR)/debian/20-sane.hwdb 
$(CURDIR)/debian/libsane1/usr/lib/udev/hwdb.d/
+endif
+
        dh_install
        # Install the pkg-config file
        mkdir -p debian/libsane-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/
        cp tools/sane-backends.pc 
debian/libsane-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/
        cp debian/sane-utils.logrotate 
debian/sane-utils/etc/logrotate.d/sane-utils
 
+       # remove rpath from the binaries (wonderful tool !)
+       chrpath -d debian/sane-utils/usr/sbin/saned
+       chrpath -d debian/sane-utils/usr/bin/scanimage
+       chrpath -d debian/sane-utils/usr/bin/sane-find-scanner
+
 override_dh_install-indep:
        dh_install
 
@@ -126,22 +140,6 @@ ifeq (linux,$(DEB_HOST_ARCH_OS))
        cp README.linux debian/libsane-common/usr/share/doc/libsane-common/
 endif
 
-override_dh_installudev-arch:
-ifeq (linux,$(DEB_HOST_ARCH_OS))
-       # udev support
-       # Generate the udev rules file
-       $(SANE_DESC) -s $(CURDIR)/doc/descriptions -m udev+hwdb > 
$(CURDIR)/debian/libsane1.udev
-       $(SANE_DESC) -s $(CURDIR)/doc/descriptions -m hwdb > 
$(CURDIR)/debian/20-sane.hwdb
-
-       cp $(CURDIR)/debian/20-sane.hwdb 
$(CURDIR)/debian/libsane1/lib/udev/hwdb.d/
-       dh_installudev
-endif
-
-       # remove rpath from the binaries (wonderful tool !)
-       chrpath -d debian/sane-utils/usr/sbin/saned
-       chrpath -d debian/sane-utils/usr/bin/scanimage
-       chrpath -d debian/sane-utils/usr/bin/sane-find-scanner
-
 override_dh_installinit-arch:
        dh_installinit -psane-utils --name=saned
 
-- 
2.39.2

Reply via email to