diff --git a/zookeeper.tcl b/zookeeper.tcl index 28b18d0..683745d 100644 --- a/zookeeper.tcl +++ b/zookeeper.tcl @@ -5,6 +5,7 @@ package require base64 package require sha1 +package require struct::set namespace eval ::zookeeper { variable zkwd "/" @@ -80,19 +81,24 @@ namespace eval ::zookeeper { # # zsync - sync a filesystem tree to a znode tree + # removes any items in zk not found in the local + # path # # zpath is prepended to the destination path # proc zsync {zk path zpath {pattern *}} { mkpath $zk $zpath - set regexp "^${path}(.*)" - foreach file [lsort [glob -nocomplain -dir $path -types f $pattern]] { - regexp $regexp $file dummy tail - copy_file $zk $file $zpath$tail + set locals [list] + foreach file [lsort [glob -nocomplain -tails -dir $path -types f $pattern]] { + copy_file $zk [file join $path $file] [file join $zpath $file] + lappend locals $file } - foreach dir [lsort [glob -nocomplain -dir $path -types d *]] { - regexp $regexp $dir dummy tailDir - zsync $zk $dir $zpath$tailDir $pattern + foreach dir [lsort [glob -nocomplain -tails -dir $path -types d *]] { + zsync $zk [file join $path $dir] [file join $zpath $dir] $pattern + lappend locals $dir + } + foreach node [::struct::set difference [$zk children $zpath] $locals] { + rmrf $zk [file join $zpath $node] } } @@ -182,7 +188,7 @@ namespace eval ::zookeeper { if {$where eq ""} { set zkwd / } else { - set children + set children } return }