Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

prune removed dirs from datafile

* this got lost when I tried to minimize writes to the data file
  • Loading branch information...
commit ac62d7c61cb4cb2ab9a8207ed9c7e0c5af07af55 1 parent 7fe57a5
@rupa authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 z.sh
View
14 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
Please sign in to comment.
Something went wrong with that request. Please try again.