From f74a06a257f07a6b9cfc6b73685d70d5cd44c830 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Mon, 1 Nov 2021 22:50:31 +0200 Subject: [PATCH] POC: add smart index updating --- cdist/conf/type/__package_apt/explorer/index | 9 +++++++++ cdist/conf/type/__package_apt/gencode-remote | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 cdist/conf/type/__package_apt/explorer/index diff --git a/cdist/conf/type/__package_apt/explorer/index b/cdist/conf/type/__package_apt/explorer/index new file mode 100644 index 00000000..58215eff --- /dev/null +++ b/cdist/conf/type/__package_apt/explorer/index @@ -0,0 +1,9 @@ +#!/bin/sh -e + +if [ ! -d /var/lib/apt/lists ] \ + || [ -n "$( find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists )" ] \ + || [ ! -f /var/cache/apt/pkgcache.bin ] \ + || [ "$( stat --format %Y /var/cache/apt/pkgcache.bin )" -lt "$( date +%s -d '-1 day' )" ] +then + echo 'update' +fi diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index 79c0d9d3..ee9b3b5a 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -92,15 +92,9 @@ case "$state_should" in # See more: ticket #861 # https://code.ungleich.ch/ungleich-public/cdist/-/issues/861 apt_opts="-o Acquire::AllowReleaseInfoChange::Suite=true -o Acquire::AllowReleaseInfoChange::Version=true" - - # following is bit ugly, but important hack. - # due to how cdist config run works, there isn't - # currently better way to do it :( - cat << EOF -if [ ! -f /var/cache/apt/pkgcache.bin ] || [ "\$( stat --format %Y /var/cache/apt/pkgcache.bin )" -lt "\$( date +%s -d '-1 day' )" ] -then echo apt-get $apt_opts update > /dev/null 2>&1 || true -fi -EOF + if [ "$(cat "$__object/explorer/index")" = 'update' ]; then + echo "apt-get $apt_opts update || true" + fi if [ -n "$version" ]; then name="${name}=${version}" fi