Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsync removes nodes not found locally #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions zookeeper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package require base64
package require sha1
package require struct::set

namespace eval ::zookeeper {
variable zkwd "/"
Expand Down Expand Up @@ -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]
}
}

Expand Down Expand Up @@ -182,7 +188,7 @@ namespace eval ::zookeeper {
if {$where eq ""} {
set zkwd /
} else {
set children
set children
}
return
}
Expand Down