Diff

Differences From Artifact [ca9b582274]:

To Artifact [c65cce6320]:


2
3
4
5
6
7
8

9
10
11
12
13
14
15
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
235
236
237
238
239
240
241

242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281

package require http 2.7
package require sqlite3

namespace eval ::appfs {
	variable cachedir "/tmp/appfs-cache"
	variable ttl 3600


	proc _hash_sep {hash {seps 4}} {
		for {set idx 0} {$idx < $seps} {incr idx} {
			append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/"
		}
		append retval "[string range $hash [expr {$idx * 2}] end]"

................................................................................
			}
			::http::reset $token
			$token cleanup
		}

		if {![info exists indexhash_data]} {
			# Cache this result for 60 seconds
			_db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, 60);}

			return -code error "Unable to fetch $url"
		}

		set indexhash [lindex [split $indexhash_data ","] 0]

		if {![_isHash $indexhash]} {
................................................................................
		}

		set file [download $hostname $package_sha1]
		set fd [open $file]
		set pkgdata [read $fd]
		close $fd


		foreach line [split $pkgdata "\n"] {
			set line [string trim $line]

			if {$line == ""} {
				continue
			}

			set work [split $line ","]

			unset -nocomplain fileInfo
			set fileInfo(type) [lindex $work 0]
			set fileInfo(time) [lindex $work 1]

			set work [lrange $work 2 end]
			switch -- $fileInfo(type) {
				"file" {
					set fileInfo(size) [lindex $work 0]
					set fileInfo(perms) [lindex $work 1]
					set fileInfo(sha1) [lindex $work 2]

					set work [lrange $work 3 end]
				}
				"symlink" {
					set fileInfo(source) [lindex $work 0]
					set work [lrange $work 1 end]
				}
			}

			set fileInfo(name) [join $work ","]
			set fileInfo(name) [split [string trim $fileInfo(name) "/"] "/"]
			set fileInfo(directory) [join [lrange $fileInfo(name) 0 end-1] "/"]
			set fileInfo(name) [lindex $fileInfo(name) end]

			_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) );}
			_db eval {UPDATE packages SET haveManifest = 1 WHERE sha1 = $package_sha1;}

		}

		return COMPLETE
	}
}







>







 







|







 







>
|
|

|
|
|

|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|

|
|
>





2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

package require http 2.7
package require sqlite3

namespace eval ::appfs {
	variable cachedir "/tmp/appfs-cache"
	variable ttl 3600
	variable nttl 60

	proc _hash_sep {hash {seps 4}} {
		for {set idx 0} {$idx < $seps} {incr idx} {
			append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/"
		}
		append retval "[string range $hash [expr {$idx * 2}] end]"

................................................................................
			}
			::http::reset $token
			$token cleanup
		}

		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 [lindex [split $indexhash_data ","] 0]

		if {![_isHash $indexhash]} {
................................................................................
		}

		set file [download $hostname $package_sha1]
		set fd [open $file]
		set pkgdata [read $fd]
		close $fd

		_db transaction {
			foreach line [split $pkgdata "\n"] {
				set line [string trim $line]

				if {$line == ""} {
					continue
				}

				set work [split $line ","]

				unset -nocomplain fileInfo
				set fileInfo(type) [lindex $work 0]
				set fileInfo(time) [lindex $work 1]

				set work [lrange $work 2 end]
				switch -- $fileInfo(type) {
					"file" {
						set fileInfo(size) [lindex $work 0]
						set fileInfo(perms) [lindex $work 1]
						set fileInfo(sha1) [lindex $work 2]

						set work [lrange $work 3 end]
					}
					"symlink" {
						set fileInfo(source) [lindex $work 0]
						set work [lrange $work 1 end]
					}
				}

				set fileInfo(name) [join $work ","]
				set fileInfo(name) [split [string trim $fileInfo(name) "/"] "/"]
				set fileInfo(directory) [join [lrange $fileInfo(name) 0 end-1] "/"]
				set fileInfo(name) [lindex $fileInfo(name) end]

				_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) );}
				_db eval {UPDATE packages SET haveManifest = 1 WHERE sha1 = $package_sha1;}
			}
		}

		return COMPLETE
	}
}