From eed99879ba956aec5f838522860c299ebb9948c6 Mon Sep 17 00:00:00 2001
From: Niels Thykier <niels@thykier.net>
Date: Sun, 3 May 2020 19:05:21 +0000
Subject: [PATCH 4/5] Support remove-on-upgrade in the db

Signed-off-by: Niels Thykier <niels@thykier.net>
---
 lib/dpkg/dump.c   |  2 ++
 lib/dpkg/fields.c | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/dpkg/dump.c b/lib/dpkg/dump.c
index 48f0beb03f..8fdcf5feba 100644
--- a/lib/dpkg/dump.c
+++ b/lib/dpkg/dump.c
@@ -394,6 +394,8 @@ w_conffiles(struct varbuf *vb,
     varbuf_add_str(vb, i->hash);
     if (i->obsolete)
       varbuf_add_str(vb, " obsolete");
+    if (i->remove_on_upgrade)
+      varbuf_add_str(vb, " remove-on-upgrade");
   }
   if (flags&fw_printheader)
     varbuf_add_char(vb, '\n');
diff --git a/lib/dpkg/fields.c b/lib/dpkg/fields.c
index 8294149b9e..66764fcfe3 100644
--- a/lib/dpkg/fields.c
+++ b/lib/dpkg/fields.c
@@ -346,10 +346,11 @@ f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
             const char *value, const struct fieldinfo *fip)
 {
   static const char obsolete_str[]= "obsolete";
+  static const char remove_on_upgrade_str[]= "remove-on-upgrade";
   struct conffile **lastp, *newlink;
   const char *endent, *endfn, *hashstart;
   int c, namelen, hashlen;
-  bool obsolete;
+  bool obsolete, remove_on_upgrade;
   char *newptr;
 
   lastp = &pkgbin->conffiles;
@@ -364,6 +365,13 @@ f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
     conffvalue_lastword(value, endent, endent,
 			&hashstart, &hashlen, &endfn,
                         ps);
+    remove_on_upgrade= (hashlen == sizeof(remove_on_upgrade_str)-1 &&
+                        memcmp(hashstart, remove_on_upgrade_str, hashlen) == 0);
+    if (remove_on_upgrade)
+      conffvalue_lastword(value, endfn, endent,
+			  &hashstart, &hashlen, &endfn,
+			  ps);
+
     obsolete= (hashlen == sizeof(obsolete_str)-1 &&
                memcmp(hashstart, obsolete_str, hashlen) == 0);
     if (obsolete)
@@ -387,6 +395,7 @@ f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
     newptr[hashlen] = '\0';
     newlink->hash= newptr;
     newlink->obsolete= obsolete;
+    newlink->remove_on_upgrade = remove_on_upgrade;
     newlink->next =NULL;
     *lastp= newlink;
     lastp= &newlink->next;
-- 
2.26.2

