• Bug#1085265: local-apt-repository: modified script

    From Darsey Litzenberger@21:1/5 to All on Mon Jul 21 23:40:02 2025
    tags 1085265 + patch
    thanks

    I've taken these patches, added a few more, and created a merge request at:

    https://salsa.debian.org/debian/local-apt-repository/-/merge_requests/2

    I've also attached the same series of patches to this message.

    --
    Darsey Litzenberger <[email protected]>

    From 77f2569ca6259a22b86c1d058f979743bb78ee48 Mon Sep 17 00:00:00 2001
    From: mike <[email protected]>
    Date: Sun, 20 Oct 2024 12:21:52 +0200
    Subject: [PATCH 1/7] use caching (Closes: #1085265)

    Committer's note (dlitz):

    Patch imported into git by applying the contents of the "rebuild" file submitted in the bug report to the "rebuild" file from version 0.9 of
    this package, then rebasing onto the latest master. Commit attributed
    to its original author.

    Link: https://bugs.debian.org/1085265
    Link: https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=1085265;filename=rebuild;msg=15
    Commit-message-by: Darsey Litzenberger <[email protected]>
    ---
    rebuild | 20 +++-----------------
    1 file changed, 3 insertions(+), 17 deletions(-)

    diff --git a/rebuild b/rebuild
    index 7f55e84..9afa60c 100755
    --- a/rebuild
    +++ b/rebuild
    @@ -2,12 +2,6 @@

    set -e

    -force=no
    -if [ "$1" = "-f" ]
    -then
    - force=yes
    -fi
    -
    DEBS=/srv/local-apt-repository
    REPO=/var/lib/local-apt-repository

    @@ -24,10 +18,6 @@ else
    # and restart. But lets bound this to 10 runs.
    for n in $(seq 0 10)
    do
    - if [ "$force" = "yes" ] || ! test -e $REPO/stamp || find $DEBS/ -newer $REPO/stamp -print -quit | fgrep -q ''
    - then
    - # we need to rebuild
    -
    # This is the second round alreay, lets wait a while
    if [ "$n" != "0" ]
    then
    @@ -35,18 +25,14 @@ else
    sleep 10
    fi

    - touch $REPO/stamp
    -
    # Relative paths work better than absolute
    (cd $REPO
    - apt-ftparchive packages ../../../$DEBS > $REPO/Packages
    - apt-ftparchive sources ../../../$DEBS > $REPO/Sources
    - ) || true
    +
  • From Darsey Litzenberger@21:1/5 to All on Tue Jul 22 01:50:01 2025
    Ah, I forgot to handle the case where /srv/local-apt-repository doesn't exist when the package is installed. This updated patch (and my latest push on salsa.d.o) should fix that.

    From bd063c0a9ba11ff53ba9b233ed5c63a64ee97495 Mon Sep 17 00:00:00 2001
    From: Darsey Litzenberger <[email protected]>
    Date: Mon, 21 Jul 2025 16:15:08 -0600
    Subject: [PATCH 6/7] Fix several error cases; improve comments

    Most of the bugs fixed here are related to bash's inconsistent errexit behavior. In bash, "set -e" (errexit) has no effect when a conditional
    is being evaluated on a compound statement. For example:

    # The following code prints "after false" and succeeds.
    set -e
    ( false
    echo after false
    ) || false

    So, errors went uncaught if apt-ftparchive failed while generating $REPO/Packages but succeeded while generating $REPO/Sources, or if dpkg
    failed to print the architecture list for some reason.

    The script might also have broken if apt-ftparchive generated partial
    output and the 10-retry limit was exceeded.
    ---
    rebuild | 70 ++++++++++++++++++++++++++++++++++++++-------------------
    1 file changed, 47 insertions(+), 23 deletions(-)

    diff --git a/rebuild b/rebuild
    index 694491b..8178a9c 100755
    --- a/rebuild
    +++ b/rebuild
    @@ -1,52 +1,76 @@
    #!/bin/bash

    -set -e
    +set -eu

    DEBS=/srv/local-apt-repository
    REPO=/var/lib/local-apt-repository
    CACHE=/var/cache/local-apt-repository
    +ARCHS="$(dpkg --print-architecture && dpkg --print-foreign-architectures)"

    -if ! test -d $DEBS
    -then
    - # We still need ot create the files lest apt will complain
    - > $REPO/Packages
    - > $REPO/Sources
    - rm -f "$REPO"/Contents-*
    +generate_index_files() {
    + # We need "|| return" after every command in this function, because "set -e" + # has no effect inside a conditional context.
    + # See https://mywiki.wooledge.org/BashPitfalls#errexit
    +
    + # This function assumes that we are already inside the REPO directory.
    +
    + apt-ftparchive packages --db "$CACHE/cache.db" ../../../"$DEBS" > Packages || return
    + apt