For consistent behavior in all timezones, make emerge-webrsync use UTC time for decis...
authorZac Medico <zmedico@gentoo.org>
Sat, 2 Dec 2006 08:07:37 +0000 (08:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 2 Dec 2006 08:07:37 +0000 (08:07 -0000)
svn path=/main/trunk/; revision=5154

bin/emerge-webrsync

index 31d1e4f8b2059b285a6932919618b892dafb721e..be5f6d6d9356e9555c2cfb542efa729031650c5a 100755 (executable)
@@ -84,21 +84,20 @@ sync_local() {
 
 echo "Fetching most recent snapshot"
 
-declare -i attempts=-1
+declare -i attempts=0
 while (( $attempts <  40 )) ; do
        attempts=$(( attempts + 1 ))
 
-       #this too, sucks.  it works in the interim though.
-       if [ "$USERLAND" == "BSD" ] || [ "$USERLAND" == "Darwin" ] ; then
-               daysbefore=$(expr $(date +"%s") - 86400 \* $attempts)
-               day=$(date -r $daysbefore +"%d")
-               month=$(date -r $daysbefore +"%m")
-               year=$(date -r $daysbefore +"%Y")
-       else
-               day=$(date -d "-$attempts day" +"%d")
-               month=$(date -d "-$attempts day" +"%m")
-               year=$(date -d "-$attempts day" +"%Y")
-       fi
+       # The snapshot for a given day is generated at 01:45 UTC on the following
+       # day, so the current day's snapshot (going by UTC time) hasn't been
+       # generated yet.  Therefore, always start by looking for the previous day's
+       # snapshot (for attempts=1, subtract 1 day from the current UTC time).
+       daysbefore=$(expr $(date -u +"%s") - 86400 \* ${attempts})
+       DATE_ARGS="-d @${daysbefore}"
+       [ "${USERLAND}" != "GNU" ] && DATE_ARGS="-r ${daysbefore}"
+       day=$(date ${DATE_ARGS} -u +"%d")
+       month=$(date ${DATE_ARGS} -u +"%m")
+       year=$(date ${DATE_ARGS} -u +"%Y")
 
        FILE_ORIG="portage-${year}${month}${day}.tar.bz2"