Hi!

On Thu, 2020-09-03 at 11:43:02 -0400, David Rayna wrote:
> Package: dpkg
> Version: 1.18.25

> 1st loop in /etc/cron.daily/dpkg treats missing file as a reason to backup.
> 2nd loop does handle missing files okay.
> 
> Result is without any arch file, unchanged files are backed up daily which
> can be critical when the storage medium has limited life.

Hmm, I'm not sure I understand the problem here, because the arch file
is supposed to only exist when it has content. Which means there
should not be an empty backup for that one. Do you really have an
empty arch backup?

Perhaps what you are seeing is that the file has backups even though
it has not changed? If so that'd be explained in the comment in the
cron file, and the intention would be to have all sequence numbers
match the same state.

In any case I think I'll merge the following patch to make the code more
robust, and actually honor the above mentioned property which seems to
have been broken along the way:

diff --git i/debian/dpkg.cron.daily w/debian/dpkg.cron.daily
index 0a135f729..11124f7dd 100644
--- i/debian/dpkg.cron.daily
+++ w/debian/dpkg.cron.daily
@@ -9,15 +9,21 @@ if cd /var/backups ; then
   dbchanged=no
   dbfiles="arch status diversions statoverride"
   for db in $dbfiles ; do
-    if ! cmp -s "dpkg.${db}.0" "$dbdir/$db"; then
+    if ! [ -s "dpkg.${db}.0" ] && ! [ -s "$dbdir/$db" ]; then
+      # Special case the files not existing or being empty as being equal.
+      continue
+    elif ! cmp -s "dpkg.${db}.0" "$dbdir/$db"; then
       dbchanged=yes
       break
     fi
   done
   if [ "$dbchanged" = "yes" ] ; then
     for db in $dbfiles ; do
-      [ -e "$dbdir/$db" ] || continue
-      cp -p "$dbdir/$db" "dpkg.$db"
+      if [ -e "$dbdir/$db" ]; then
+        cp -p "$dbdir/$db" "dpkg.$db"
+      else
+        touch "dpkg.$db"
+      fi
       savelog -c 7 "dpkg.$db" >/dev/null
     done
   fi

Thanks,
Guillem

Reply via email to