Skip to content

Commit 2da29a2

Browse files
committed
Preserve apt package install order on restore.
* The manifest_all.log file is now kept in the order apt installed the packages. * restore_pkgs.sh now restores packages in the order they are in the manifest_all.log file instead of the order of the tarballs in the filesystem. Resolves: awalsh128#196
1 parent 22ad28f commit 2da29a2

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

lib.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ function get_tar_relpath {
161161
function update_apt_lists_if_stale {
162162
# Only check for stale package lists when running in nektos/act
163163
# GitHub Actions runners have fresh package lists, so skip this overhead
164-
if [ "${ACT}" = "true" ]; then
164+
# ACT comes from the environment
165+
# shellcheck disable=SC2154
166+
if [[ "${ACT}" = "true" ]]; then
165167
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5 2>/dev/null)" ]]; then
166168
log "APT package lists are stale, updating..."
167169
if command -v apt-fast > /dev/null 2>&1; then
@@ -213,7 +215,7 @@ function write_manifest {
213215
else
214216
log "Writing ${1} packages manifest to ${3}..."
215217
# 0:-1 to remove trailing comma, delimit by newline and sort.
216-
echo "${2:0:-1}" | tr ',' '\n' | sort > "${3}"
218+
echo "${2:0:-1}" | tr ',' '\n' > "${3}"
217219
log "done"
218220
fi
219221
}

restore_pkgs.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ log "done"
4242
log_empty_line
4343

4444
# Only search for archived results. Manifest and cache key also live here.
45-
# Use find instead of ls to better handle non-alphanumeric filenames
46-
cached_filepaths=$(find "${cache_dir}" -maxdepth 1 -name "*.tar" -type f 2>/dev/null | sort)
47-
cached_filecount=$(echo "${cached_filepaths}" | wc -w)
45+
manifest_all="${cache_dir}/manifest_all.log"
46+
mapfile -t packages <"${manifest_all}"
4847

48+
cached_filecount="${#packages[@]}"
4949
log "Restoring ${cached_filecount} packages from cache..."
50-
for cached_filepath in ${cached_filepaths}; do
5150

52-
log "- $(basename "${cached_filepath}") restoring..."
51+
for package in "${packages[@]}"; do
52+
cached_filepath="${cache_dir}/${package}.tar"
53+
log "- ${package} restoring..."
5354
sudo tar -xf "${cached_filepath}" -C "${cache_restore_root}" > /dev/null
5455
log " done"
5556

0 commit comments

Comments
 (0)