Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] debian packaging: set md5sums for conffiles
@ 2022-07-26 21:13 Rusty Howell
  2022-07-27 10:53 ` [OE-core] " Luca Ceresoli
  0 siblings, 1 reply; 9+ messages in thread
From: Rusty Howell @ 2022-07-26 21:13 UTC (permalink / raw)
  To: openembedded-core; +Cc: Rusty Howell

Currently in an image created with debian package management, dpkg is missing the md5sums in
/var/lib/dpkg/status for files designated as conffiles.  They are just listed as "newconffile",
which is an intermediate state when dpkg installs a package with an conf file.  Also, when the
device first boots the script /usr/sbin/run-postinsts does not cause /var/lib/dpkg/status to update
those hashes either.

The problem here is that when using a package feed, all the conf files are listed as "newconffile",
which will indicate to dpkg to replace them all on the first update.  dpkg will not follow the rules for
confold, confnew, confdef.
---
 meta/lib/oe/package_manager/deb/__init__.py | 42 +++++++++++++++++++++
 meta/lib/oe/package_manager/deb/rootfs.py   |  2 +
 2 files changed, 44 insertions(+)

diff --git a/meta/lib/oe/package_manager/deb/__init__.py b/meta/lib/oe/package_manager/deb/__init__.py
index 2ee68fefb1..fabb955558 100644
--- a/meta/lib/oe/package_manager/deb/__init__.py
+++ b/meta/lib/oe/package_manager/deb/__init__.py
@@ -3,6 +3,7 @@
 #
 
 import re
+import glob
 import subprocess
 from oe.package_manager import *
 
@@ -216,6 +217,47 @@ class DpkgPM(OpkgDpkgPM):
 
         os.rename(status_file + ".tmp", status_file)
 
+    def set_conffile_hashes(self):
+        """
+        This function will populate the md5sums for all the conffiles listed in /var/lib/dpkg/status
+        """
+        status_file = self.target_rootfs + "/var/lib/dpkg/status"
+
+        with open(status_file, "r") as sf:
+            with open(status_file + ".tmp", "w+") as tmp_sf:
+                status = sf.read()
+
+                conffiles = glob.glob(self.target_rootfs + "/var/lib/dpkg/info/*.conffiles")
+                for cf in conffiles:
+                    fname = os.path.basename(cf)
+                    pkg = fname.split('.')[0]
+
+                    bb.note("Populating md5sums for pkg %s" % pkg)
+                    conffiles = "%s/var/lib/dpkg/info/%s.conffiles" % (self.target_rootfs, pkg)
+                    md5sums = "%s/var/lib/dpkg/info/%s.md5sums" % (self.target_rootfs, pkg)
+                    if os.path.exists(conffiles) and os.path.exists(md5sums):
+                        conf_hashes = {}
+                        with open(md5sums, "r") as md5s:
+                            for line in md5s.read().split('\n'):
+                                m = re.match(r"^([a-f0-9]+)\s+(\S+)", line)
+                                if m:
+                                    hash_ = m.group(1)
+                                    fpath = m.group(2)
+                                    if not fpath.startswith('/'):
+                                        fpath = '/' + fpath
+                                    conf_hashes[fpath] = hash_
+
+                        with open(conffiles, "r") as cf:
+                            for fpath in cf.read().split('\n'):
+                                hash_ = conf_hashes.get(fpath, None)
+                                if hash_:
+                                    status = re.sub("%s newconffile" % fpath, "%s %s" % (fpath, hash_), status)
+
+
+                tmp_sf.write(status)
+
+        os.rename(status_file + ".tmp", status_file)
+
     def run_pre_post_installs(self, package_name=None):
         """
         Run the pre/post installs for package "package_name". If package_name is
diff --git a/meta/lib/oe/package_manager/deb/rootfs.py b/meta/lib/oe/package_manager/deb/rootfs.py
index 8fbaca11d6..06e99158de 100644
--- a/meta/lib/oe/package_manager/deb/rootfs.py
+++ b/meta/lib/oe/package_manager/deb/rootfs.py
@@ -186,6 +186,8 @@ class PkgRootfs(DpkgOpkgRootfs):
 
         execute_pre_post_process(self.d, deb_post_process_cmds)
 
+        self.pm.set_conffile_hashes()
+
         if self.progress_reporter:
             self.progress_reporter.next_stage()
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-07-27 15:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-26 21:13 [PATCH] debian packaging: set md5sums for conffiles Rusty Howell
2022-07-27 10:53 ` [OE-core] " Luca Ceresoli
2022-07-27 11:48   ` Alexander Kanavin
2022-07-27 12:25     ` Ross Burton
2022-07-27 13:56       ` Ross Burton
2022-07-27 14:08         ` Ross Burton
2022-07-27 14:32           ` Rusty Howell
2022-07-27 14:35             ` Alexander Kanavin
2022-07-27 15:31               ` Rusty Howell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox