]> git.saurik.com Git - apt.git/blobdiff - debian/apt.cron.daily
* apt-pkg/acquire.cc:
[apt.git] / debian / apt.cron.daily
index cdec7eea00315e0d5c3896448498c740a37396a3..7e4214775c8235075e19c910f5156642f2e0eb4d 100644 (file)
@@ -69,26 +69,51 @@ check_stamp()
     interval="$2"
 
     if [ $interval -eq 0 ]; then
-       debug_echo "check_stamp: interval=0."
+       debug_echo "check_stamp: interval=0"
        # treat as no time has passed
         return 1
     fi
 
     if [ ! -f $stamp ]; then
        update_stamp $stamp
-       debug_echo "check_stamp: missing time stamp file: $stamp."
+       debug_echo "check_stamp: missing time stamp file: $stamp"
        # treat as enough time has passed
         return 0
     fi
 
     # compare midnight today to midnight the day the stamp was updated
-    stamp=$(date -r $stamp '+%s')
+    stamp_file="$stamp"
+    stamp=$(date --date=$(date -r $stamp_file --iso-8601) +%s 2>/dev/null)
+    if [ "$?" != "0" ]; then
+        # Due to some timezones returning 'invalid date' for midnight on
+        # certain dates (eg America/Sao_Paulo), if date returns with error
+        # remove the stamp file and return 0. See coreutils bug:
+        # http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00176.html
+        rm -f "$stamp_file"
+        return 0
+    fi
+
+    now=$(date --date=$(date --iso-8601) +%s 2>/dev/null)
+    if [ "$?" != "0" ]; then
+        # As above, due to some timezones returning 'invalid date' for midnight
+        # on certain dates (eg America/Sao_Paulo), if date returns with error
+        # return 0.
+        return 0
+    fi
+
     delta=$(($now-$stamp))
 
     # intervall is in days, convert to sec.
     interval=$(($interval*60*60*24))
     debug_echo "check_stamp: interval=$interval, now=$now, stamp=$stamp, delta=$delta (sec)"
 
+    # remove timestamps a day (or more) in the future and force re-check
+    if [ $stamp -gt $(($now+86400)) ]; then
+         echo "WARNING: file $stamp_file has a timestamp in the future: $stamp"
+         rm -f "$stamp_file"
+         return 0
+    fi
+
     if [ $delta -ge $interval ]; then
         return 0
     fi
@@ -200,7 +225,8 @@ debug_echo()
     fi
 }
 
-# main
+
+# ----------------- main ----------------
 
 # check apt-config exstance
 if ! which apt-config >/dev/null ; then
@@ -238,17 +264,16 @@ if which on_ac_power >/dev/null; then
     on_ac_power
     POWER=$?
     if [ $POWER -eq 1 ]; then
-       debug_echo "exit: system on main power."
+       debug_echo "exit: system NOT on main power."
        exit 0
     elif [ $POWER -ne 0 ]; then
-       debug_echo "exit: power status ($POWER) undetermined."
-       exit 0
+       debug_echo "power status ($POWER) undetermined."
     fi
     debug_echo "system is on main power."
 fi
 
 # check if we can lock the cache and if the cache is clean
-if which apt-get >/dev/null && ! eval apt-get check $XAPTOPT $XSTDERR ; then
+if which apt-get >/dev/null && ! apt-get check $XAPTOPT $XSTDERR ; then
     debug_echo "error encountered in cron job with \"apt-get check\"."
     exit 0
 fi
@@ -283,14 +308,16 @@ eval $(apt-config shell BackupArchiveInterval APT::Periodic::BackupArchiveInterv
 
 BackupLevel=3
 eval $(apt-config shell BackupLevel APT::Periodic::BackupLevel)
-if [ $BackupLevel -le 1 ]; then BackupLevel=2 ; fi
+if [ $BackupLevel -le 1 ]; then 
+    BackupLevel=2 ; 
+fi
 
 CacheBackup="backup/"
 eval $(apt-config shell CacheBackup Dir::Cache::Backup)
 CacheBackup=${CacheBackup%/}
 if [ -z "$CacheBackup" ]; then
-    echo "practically empty Dir::Cache::Backup, exiting" 1>&2
-    exit 0
+    echo "empty Dir::Cache::Backup, using default" 1>&2
+    CacheBackup="backup/"
 fi
 
 # Support old Archive for compatibility.
@@ -335,6 +362,9 @@ if [ $UpdateInterval -eq 0 ] &&
     exit 0
 fi
 
+# sleep random amount of time to avoid hitting the 
+# mirrors at the same time
+random_sleep
 
 # backup after n-days if archive contents changed.
 # (This uses hardlink to save disk space)