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

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#168515): 
https://lists.openembedded.org/g/openembedded-core/message/168515
Mute This Topic: https://lists.openembedded.org/mt/92637328/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to