@@ -286,10 +286,14 @@ return $file } proc getindex {hostname} { + if {[string match "*\[/~\]*" $hostname]} { + return -code error "Invalid hostname" + } + set now [clock seconds] set lastUpdates [db eval {SELECT lastUpdate, ttl FROM sites WHERE hostname = $hostname LIMIT 1;}] if {[llength $lastUpdates] == 0} { set lastUpdate 0 @@ -301,14 +305,10 @@ if {$now < ($lastUpdate + $ttl)} { return COMPLETE } - if {[string match "*\[/~\]*" $hostname]} { - return -code error "Invalid hostname" - } - set url "http://$hostname/appfs/index" catch { set token [::http::geturl $url] if {[::http::ncode $token] == "200"} { @@ -316,14 +316,15 @@ } ::http::reset $token ::http::cleanup $token } + # Note that we attempted to fetch this index and do not try + # again for a while + db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, $::appfs::nttl);} + if {![info exists indexhash_data]} { - # Cache this result for 60 seconds - db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, $::appfs::nttl);} - return -code error "Unable to fetch $url" } set indexhash_data [string trim $indexhash_data "\r\n"] set indexhash_data [split $indexhash_data ","]