Diff

Differences From Artifact [9efbb291d1]:

To Artifact [865f14848a]:


284
285
286
287
288
289
290




291
292
293
294
295
296
297
...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

325
326
327
328
329
330
331
			return -code error "Unable to fetch (file does not exist: $file)"
		}

		return $file
	}

	proc getindex {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
			set ttl 0
		} else {
................................................................................
			set ttl [lindex $lastUpdates 1]
		}

		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"} {
				set indexhash_data [::http::data $token]
			}
			::http::reset $token
			::http::cleanup $token
		}

		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 ","]
		set indexhash       [lindex $indexhash_data 0]
		set indexhashmethod [lindex $indexhash_data 1]







>
>
>
>







 







<
<
<
<











|
|
|

>







284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
...
303
304
305
306
307
308
309




310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
			return -code error "Unable to fetch (file does not exist: $file)"
		}

		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
			set ttl 0
		} else {
................................................................................
			set ttl [lindex $lastUpdates 1]
		}

		if {$now < ($lastUpdate + $ttl)} {
			return COMPLETE
		}





		set url "http://$hostname/appfs/index"

		catch {
			set token [::http::geturl $url]
			if {[::http::ncode $token] == "200"} {
				set indexhash_data [::http::data $token]
			}
			::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]} {
			return -code error "Unable to fetch $url"
		}

		set indexhash_data [string trim $indexhash_data "\r\n"]
		set indexhash_data [split $indexhash_data ","]
		set indexhash       [lindex $indexhash_data 0]
		set indexhashmethod [lindex $indexhash_data 1]