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.
This commit is contained in:
Leonid Pliushch 2021-05-19 13:59:31 +03:00
parent 3337b9ffee
commit cf3236e9e8

View File

@ -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
}