• Bug#1006655: [PATCH] Implement rm_conffile_if_unmodified (1/5)

    From Josh Triplett@1:229/2 to All on Tue May 28 23:40:01 2024
    XPost: linux.debian.bugs.dist
    From: josh@joshtriplett.org

    tags 1006655 + patch
    thanks

    I've attached a patch implementing an rm_conffile_if_unmodifed command
    for dpkg-maintscript-helper, as well as a declarative version for debian/conffiles.

    I've included documentation and tests for both.

    Using this has the same effect as rm_conffile if the file is unmodified. However, if the file is modified, this leaves the file in place under
    the existing name (treating it as an obsolete conffile so that it still
    gets removed if purging the package).

    Thus, unlike rm_conffile, this version is useful for packages that still support reading the configuration file if present, and thus don't want
    to move existing modified configuration aside with a .dpkg-bak suffix,
    because that'll prevent the modified configuration from being used.

    - Josh Triplett

    From f3f04a4288076471b9f963f75d10470ba7e446a6 Mon Sep 17 00:00:00 2001 Message-ID: <f3f04a4288076471b9f963f75d10470ba7e446a6.1716931259.git.josh@joshtriplett.org>
    From: Josh Triplett <josh@joshtriplett.org>
    Date: Tue, 28 May 2024 11:11:06 -0700
    Subject: [PATCH] Implement rm_conffile_if_unmodified

    Sometimes, a package wants to no longer install a conffile in new
    versions; for instance, the conffile might still be supported, but the
    default version is not needed for new installations. In this case, the
    existing `rm_conffile` doesn't suffice, because it will rename modified versions with a .dpkg-bak suffix.

    Add a new `rm_conffile_if_unmodified` (also available as
    `rm_conffile --if-unmodified`) to handle this case.

    Provide a declarative version `remove-if-unmodified` as well.

    Document these, and add tests for them.

    Closes: #1006655

    Signed-off-by: Josh Triplett <josh@joshtriplett.org>
    ---
    lib/dpkg/dpkg-db.h | 1 +
    lib/dpkg/dump.c | 2 +
    lib/dpkg/fields.c | 10 +++-
    lib/dpkg/fsys.h | 2 +
    man/deb-conffiles.pod | 19 ++++++-
    man/dpkg-maintscript-helper.pod | 43 ++++++++++++++--
    src/deb/build.c | 7 ++-
    src/dpkg-maintscript-helper.sh | 50 +++++++++++++++----
    src/main/archives.c | 7 ++-
    src/main/configure.c | 8 ++-
    src/main/help.c | 4 +-
    src/main/unpack.c | 26 ++++++----
    tests/t-conffile-declarative-removal/Makefile | 21 +++++++-
    .../pkg-conffile-v1/DEBIAN/conffiles | 1 +
    .../test-conffile-to-be-removed-if-unmodified | 0
    .../pkg-conffile-v2/DEBIAN/conffiles | 1 +
    tests/t-conffile-obsolete/Makefile | 18 ++++++-
    .../pkg-conff-