Skip to content

Commit bae5bb7

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 58600a5 commit bae5bb7

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ function get_tar_relpath {
148148
function update_apt_lists_if_stale {
149149
# Only check for stale package lists when running in nektos/act
150150
# GitHub Actions runners have fresh package lists, so skip this overhead
151-
if [ "${ACT}" = "true" ]; then
151+
# ACT comes from the environment
152+
# shellcheck disable=SC2154
153+
if [[ "${ACT}" = "true" ]]; then
152154
if [[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mmin -5 2>/dev/null)" ]]; then
153155
log "APT package lists are stale, updating..."
154156
if command -v apt-fast > /dev/null 2>&1; then
@@ -200,7 +202,7 @@ function write_manifest {
200202
else
201203
log "Writing ${1} packages manifest to ${3}..."
202204
# 0:-1 to remove trailing comma, delimit by newline and sort.
203-
echo "${2:0:-1}" | tr ',' '\n' | sort > ${3}
205+
echo "${2:0:-1}" | tr ',' '\n' > "${3}"
204206
log "done"
205207
fi
206208
}

restore_pkgs.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ log "done"
4040
log_empty_line
4141

4242
# Only search for archived results. Manifest and cache key also live here.
43-
cached_filepaths=$(ls -1 "${cache_dir}"/*.tar 2>/dev/null | sort)
44-
cached_filecount=$(echo ${cached_filepaths} | wc -w)
43+
manifest_all="${cache_dir}/manifest_all.log"
44+
mapfile -t packages <"${manifest_all}"
4545

46+
cached_filecount="${#packages[@]}"
4647
log "Restoring ${cached_filecount} packages from cache..."
47-
for cached_filepath in ${cached_filepaths}; do
4848

49-
log "- $(basename "${cached_filepath}") restoring..."
49+
for package in "${packages[@]}"; do
50+
cached_filepath="${cache_dir}/${package}.tar"
51+
log "- ${package} restoring..."
5052
sudo tar -xf "${cached_filepath}" -C "${cache_restore_root}" > /dev/null
5153
log " done"
5254

0 commit comments

Comments
 (0)