Diff

Differences From Artifact [ca9b582274]:

To Artifact [c65cce6320]:


     2      2   
     3      3   package require http 2.7
     4      4   package require sqlite3
     5      5   
     6      6   namespace eval ::appfs {
     7      7   	variable cachedir "/tmp/appfs-cache"
     8      8   	variable ttl 3600
            9  +	variable nttl 60
     9     10   
    10     11   	proc _hash_sep {hash {seps 4}} {
    11     12   		for {set idx 0} {$idx < $seps} {incr idx} {
    12     13   			append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/"
    13     14   		}
    14     15   		append retval "[string range $hash [expr {$idx * 2}] end]"
    15     16   
................................................................................
   141    142   			}
   142    143   			::http::reset $token
   143    144   			$token cleanup
   144    145   		}
   145    146   
   146    147   		if {![info exists indexhash_data]} {
   147    148   			# Cache this result for 60 seconds
   148         -			_db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, 60);}
          149  +			_db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, $::appfs::nttl);}
   149    150   
   150    151   			return -code error "Unable to fetch $url"
   151    152   		}
   152    153   
   153    154   		set indexhash [lindex [split $indexhash_data ","] 0]
   154    155   
   155    156   		if {![_isHash $indexhash]} {
................................................................................
   235    236   		}
   236    237   
   237    238   		set file [download $hostname $package_sha1]
   238    239   		set fd [open $file]
   239    240   		set pkgdata [read $fd]
   240    241   		close $fd
   241    242   
   242         -		foreach line [split $pkgdata "\n"] {
   243         -			set line [string trim $line]
          243  +		_db transaction {
          244  +			foreach line [split $pkgdata "\n"] {
          245  +				set line [string trim $line]
          246  +
          247  +				if {$line == ""} {
          248  +					continue
          249  +				}
          250  +
          251  +				set work [split $line ","]
   244    252   
   245         -			if {$line == ""} {
   246         -				continue
   247         -			}
          253  +				unset -nocomplain fileInfo
          254  +				set fileInfo(type) [lindex $work 0]
          255  +				set fileInfo(time) [lindex $work 1]
   248    256   
   249         -			set work [split $line ","]
   250         -
   251         -			unset -nocomplain fileInfo
   252         -			set fileInfo(type) [lindex $work 0]
   253         -			set fileInfo(time) [lindex $work 1]
          257  +				set work [lrange $work 2 end]
          258  +				switch -- $fileInfo(type) {
          259  +					"file" {
          260  +						set fileInfo(size) [lindex $work 0]
          261  +						set fileInfo(perms) [lindex $work 1]
          262  +						set fileInfo(sha1) [lindex $work 2]
   254    263   
   255         -			set work [lrange $work 2 end]
   256         -			switch -- $fileInfo(type) {
   257         -				"file" {
   258         -					set fileInfo(size) [lindex $work 0]
   259         -					set fileInfo(perms) [lindex $work 1]
   260         -					set fileInfo(sha1) [lindex $work 2]
   261         -
   262         -					set work [lrange $work 3 end]
          264  +						set work [lrange $work 3 end]
          265  +					}
          266  +					"symlink" {
          267  +						set fileInfo(source) [lindex $work 0]
          268  +						set work [lrange $work 1 end]
          269  +					}
   263    270   				}
   264         -				"symlink" {
   265         -					set fileInfo(source) [lindex $work 0]
   266         -					set work [lrange $work 1 end]
   267         -				}
   268         -			}
          271  +
          272  +				set fileInfo(name) [join $work ","]
          273  +				set fileInfo(name) [split [string trim $fileInfo(name) "/"] "/"]
          274  +				set fileInfo(directory) [join [lrange $fileInfo(name) 0 end-1] "/"]
          275  +				set fileInfo(name) [lindex $fileInfo(name) end]
   269    276   
   270         -			set fileInfo(name) [join $work ","]
   271         -			set fileInfo(name) [split [string trim $fileInfo(name) "/"] "/"]
   272         -			set fileInfo(directory) [join [lrange $fileInfo(name) 0 end-1] "/"]
   273         -			set fileInfo(name) [lindex $fileInfo(name) end]
   274         -
   275         -			_db eval {INSERT INTO files (package_sha1, type, time, source, size, perms, file_sha1, file_name, file_directory) VALUES ($package_sha1, $fileInfo(type), $fileInfo(time), $fileInfo(source), $fileInfo(size), $fileInfo(perms), $fileInfo(sha1), $fileInfo(name), $fileInfo(directory) );}
   276         -			_db eval {UPDATE packages SET haveManifest = 1 WHERE sha1 = $package_sha1;}
          277  +				_db eval {INSERT INTO files (package_sha1, type, time, source, size, perms, file_sha1, file_name, file_directory) VALUES ($package_sha1, $fileInfo(type), $fileInfo(time), $fileInfo(source), $fileInfo(size), $fileInfo(perms), $fileInfo(sha1), $fileInfo(name), $fileInfo(directory) );}
          278  +				_db eval {UPDATE packages SET haveManifest = 1 WHERE sha1 = $package_sha1;}
          279  +			}
   277    280   		}
   278    281   
   279    282   		return COMPLETE
   280    283   	}
   281    284   }