mostly indenting
[distro-functions] / src / package-manager-abstractions
index 9311038c4f0b616d6b7ad1837d25a413edbfb3ff..dece84830169562a1217de1a7b71f019c7b866ba 100644 (file)
@@ -88,11 +88,25 @@ elif command -v apt-get &>/dev/null; then
     esac
   }
   pupdate() {
-    local s f; [[ $EUID != 0 ]] && s=sudo
+    local now t s f cachetime limittime; [[ $EUID != 0 ]] && s=sudo
     # update package list if its more than an 2 hours old
     f=/var/cache/apt/pkgcache.bin
-    if [[ ! -r $f ]] \
-         || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60*2 )); then
+    if [[ -r $f ]]; then
+      cachetime=$(stat -c %Y $f )
+    else
+      cachetime=0
+    fi
+    now=$(date +%s)
+    limittime=$(( now - 60*60*2 ))
+    for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
+      if [[ -r $f ]]; then
+        t=$(stat -c %Y $f )
+        if (( t > limittime )); then
+          limittime=$t
+        fi
+      fi
+    done
+    if (( cachtime > limittime )); then
       $s apt-get update
     fi
   }