Refactor apt list update logic into shared library function

Co-authored-by: awalsh128 <2087466+awalsh128@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-01 01:44:07 +00:00
parent 6be0984af2
commit d6013a02d0
3 changed files with 25 additions and 16 deletions

View file

@ -42,12 +42,7 @@ if [ -n "${add_repository}" ]; then
fi
log "Updating APT package list..."
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5)" ]]; then
sudo apt-fast update > /dev/null
log "done"
else
log "skipped (fresh within at least 5 minutes)"
fi
update_apt_lists_if_stale
log_empty_line

23
lib.sh
View file

@ -135,6 +135,29 @@ function get_tar_relpath {
fi
}
###############################################################################
# Updates APT package lists if they are stale (modified more than 5 minutes ago).
# This ensures compatibility with environments like nektos/act where package lists
# may be empty or stale.
# Arguments:
# None
# Returns:
# None
###############################################################################
function update_apt_lists_if_stale {
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5 2>/dev/null)" ]]; then
log "APT package lists are stale, updating..."
if command -v apt-fast > /dev/null 2>&1; then
sudo apt-fast update > /dev/null 2>&1 || sudo apt update > /dev/null 2>&1 || true
else
sudo apt update > /dev/null 2>&1 || true
fi
log "APT package lists updated"
else
log "APT package lists are fresh (within 5 minutes), skipping update"
fi
}
function log { echo "${@}"; }
function log_err { >&2 echo "${@}"; }

View file

@ -34,16 +34,7 @@ input_packages="${@:6}"
log "Normalizing package list..."
# Ensure APT package lists are updated if stale (for nektos/act compatibility)
# Uses the same logic as install_and_cache_pkgs.sh
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5 2>/dev/null)" ]]; then
log "APT package lists are stale, updating..."
if command -v apt-fast > /dev/null 2>&1; then
sudo apt-fast update > /dev/null 2>&1 || sudo apt update > /dev/null 2>&1 || true
else
sudo apt update > /dev/null 2>&1 || true
fi
log "APT package lists updated"
fi
update_apt_lists_if_stale
packages="$(get_normalized_package_list "${input_packages}")"
log "done"