From ac62d7c61cb4cb2ab9a8207ed9c7e0c5af07af55 Mon Sep 17 00:00:00 2001 From: rupa Date: Tue, 7 Feb 2012 12:00:03 -0500 Subject: [PATCH] prune removed dirs from datafile * this got lost when I tried to minimize writes to the data file --- z.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/z.sh b/z.sh index d30efcc..1443a6f 100755 --- a/z.sh +++ b/z.sh @@ -40,12 +40,24 @@ _z() { # maintain the file local tempfile tempfile="$(mktemp $datafile.XXXXXX)" || return - awk -v path="$*" -v now="$(date +%s)" -F"|" ' + awk -v path="$*" -v now="$(date +%s)" -v datafile="$datafile" -F"|" ' + function notdir(path, tmp) { + # faster than system() + n = gsub("/+", "/", path) + for( i = 0; i < n; i++ ) path = path "/.." + path = path datafile + if( ( getline tmp < path ) >= 0 ) { + close(path) + return 0 + } + return 1 + } BEGIN { rank[path] = 1 time[path] = now } $2 >= 1 { + if( notdir($1) ) next if( $1 == path ) { rank[$1] = $2 + 1 time[$1] = now