# Copyright (c) 2001 Josha Foust (tivoweb@lightn.org) proc strim {str} { return [string trim $str "\{\}"] } proc defaultval {val1 val2} { if { $val2 != "" } { return $val2 } else { return $val1 } } proc get_fsidbyprefix {dirname prefix} { if { [catch {mfs scan $dirname -start $prefix -count 1} batch] } { global errorCode errorInfo if { $errorCode == "errNmNameNotFound" } { return } else { error $batch $errorInfo $errorCode } } set item [lindex $batch 0] set name [lindex $item 1] if { [PrefixMatches $prefix $name] } { return [lindex $item 0] } else { return "" } } proc ForeachMfsFileTrans { idVar nameVar typeVar dirName prefix count body } { global errorInfo errorCode upvar $idVar id upvar $nameVar name upvar $typeVar type # Get the first batch of names RetryTransaction { if { [catch {mfs scan $dirName -start $prefix -count $count} batch] } { global errorCode errorInfo if { $errorCode == "errNmNameNotFound" } { return } else { error $batch $errorInfo $errorCode } } } set done 0 while { [llength $batch] > 0 } { # Execute the body for each item in this batch RetryTransaction { foreach item $batch { set id [lindex $item 0] set name [lindex $item 1] set type [lindex $item 2] # bail if we're past the entries that start with the given prefix if { ! [PrefixMatches $prefix $name] } { set done 1 break } set code [catch {uplevel $body} string] if { $code == 1 } { global errorCode errorInfo if { $errorCode == "errTmActiveLockConflict" || $errorCode == "errFsLockConflict" } { error $batch $errorInfo $errorCode } else { set done 2 break } } elseif { $code == 3 } { # this is a break in the body. just return normally set done 3 break } elseif { $code != 0 } { set done 4 break } } } switch -exact $done { 1 {return} 2 {return -code error -errorinfo $errorInfo \ -errorcode $errorCode $string} 3 {return} 4 {return -code $code $string} } # Get the next batch set lastName [lindex [lindex $batch end] 1] RetryTransaction { set batch [mfs scan $dirName -start $lastName -count $count] if { $lastName == [lindex [lindex $batch 0] 1] } { set batch [lrange $batch 1 end] } } } }