From cf3236e9e86eaeb051b39fa204d64011f72cfd29 Mon Sep 17 00:00:00 2001 From: Leonid Pliushch Date: Wed, 19 May 2021 13:59:31 +0300 Subject: [PATCH] termux-tools: pkg: try to avoid cases where pkgcache is up-to-date but sources.list has been changed A small percentage of users reporting issue where `pkg install` shows that package is not available, though it is present in our apt repository. This happens when sources.list has been changed without subsequent `apt update`. Now `pkg` will force run `apt update` if sources.list was modified after packages list update but cache still not expired. --- packages/termux-tools/pkg | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/termux-tools/pkg b/packages/termux-tools/pkg index 07b9b2fcf..060852429 100755 --- a/packages/termux-tools/pkg +++ b/packages/termux-tools/pkg @@ -142,8 +142,17 @@ select_mirror() { } update_apt_cache() { - local pkgcache="@TERMUX_CACHE_DIR@/apt/pkgcache.bin" - if (( $(last_modified "$pkgcache") > 1200 )); then + local cache_modified + local sources_modified + + if [ -e "@TERMUX_CACHE_DIR@/apt/pkgcache.bin" ]; then + cache_modified=$(last_modified "@TERMUX_CACHE_DIR@/apt/pkgcache.bin") + sources_modified=$(last_modified "@TERMUX_PREFIX@/etc/apt/sources.list") + + if (( sources_modified <= cache_modified )) || (( cache_modified > 1200 )); then + apt update + fi + else apt update fi }