chiark / gitweb /
rcopy-repeatedly debugging wip
[chiark-utils.git] / scripts / expire-iso8601
index 7cb274e607991354cf88b890b108054c5c9ed9c7..530c48c170bf4adb8d1ab1cab5d8a01526a53a8f 100755 (executable)
@@ -28,6 +28,23 @@ exit status:
 END
                        }
 
+# Copyright 2006 Ian Jackson <ian@chiark.greenend.org.uk>
+#
+# This script and its documentation (if any) are free software; you
+# can redistribute it and/or modify them under the terms of the GNU
+# General Public License as published by the Free Software Foundation;
+# either version 3, or (at your option) any later version.
+# 
+# chiark-named-conf and its manpage are distributed in the hope that
+# it will be useful, but WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE.  See the GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, consult the Free Software Foundation's
+# website at www.fsf.org, or the GNU Project website at www.gnu.org.
+
+
 trap 'exit 16' 0
 badusage () { echo >&2 "bad usage: $*"; usage >&2; trap '' 0; exit 8; }
 
@@ -106,7 +123,8 @@ done
 
 # We process each minimum/extent pair, to have it select a bunch of
 # versions to keep.  We annotate entries in $l: if we are keeping
-# an entry we prepend a colon.
+# an entry we prepend a colon; temporarily, if we are keeping an entry
+# because of this particular minimum/extent, we prepend a comma.
 
 # For each minimum/extent pair we look at the list from most recent
 # to least recent,
@@ -123,27 +141,49 @@ END
 )
 
 for ni in "$@"; do
-       min=$(( ${ni#*x} * $unit - $slop ))
        wantcount=${ni%x*}
 
-       ls=''
+       div=1
+
+       while true; do
+               min=$(( (${ni#*x} * $unit) / $div - $slop ))
+
+               ls=''
+               lnew=''
+               skipped=0
+               for ce in $l; do
+                       cn=${ce#*/}; cl=${ce%%/*}
+                       cs=${cl#,}; cs=${cs#:}
+                       case $cl in ,*) ls=$cs; continue;; esac
+                       if [ $wantcount != 0 ]; then
+                               if ! [ "$ls" ] || \
+                                  [ $(( $ls - $cs )) -ge $min ]; then
+                                       echo "keep (for $ni) $cn"
+                                       ce=,$ce
+                                       ls=$cs
+                                       wantcount=$(( $wantcount - 1 ))
+                               else
+                                       skipped=$(( $skipped+1 ))
+                               fi
+                       fi
+                       lnew="$lnew $ce"
+               done
+               l=$lnew
+
+               if [ $wantcount = 0 ]; then break; fi
+               printf "%s" "insufficient (for $ni) by $wantcount"
+               if [ $skipped = 0 ]; then echo; break; fi
+               div=$(( $div * 2 ))
+               echo " shortening interval ${div}x"
+       done
+
+       # s/([,:]+).*/:\1/g
        lnew=''
        for ce in $l; do
-               cn=${ce#*/}; cl=${ce%%/*}; cs=${cl#:}
-               if [ $wantcount != 0 ]; then
-                       if ! [ "$ls" ] || \
-                          [ $(( $ls - $cs )) -ge $min ]; then
-                               echo "keep (for $ni) $cn"
-                               ls=$cs
-                               ce=:$cs/$cn
-                               wantcount=$(( $wantcount - 1 ))
-                       fi
-               fi
+               case $ce in ,*) ce=:${ce#,};; esac
+               case $ce in ::*) ce=${ce#:};; esac
                lnew="$lnew $ce"
        done
-       if [ $wantcount != 0 ];then
-               echo "insufficient (for $ni) by $wantcount"
-       fi
        l=$lnew
 done