Index: README.md ================================================================== --- README.md +++ README.md @@ -25,7 +25,7 @@ /opt/appfs/hostname/{sha1,package/os-cpuArch/version}/file Fetches: http://hostname/appfs/sha1/ Database -------- - packages(hostname, sha1, package, version, os, cpuArch, isLatest) + packages(hostname, sha1, package, version, os, cpuArch, isLatest, haveManifest) files(package_sha1, type, time, source, size, file_sha1, file_name, file_directory) Index: appfs.tcl ================================================================== --- appfs.tcl +++ appfs.tcl @@ -59,11 +59,11 @@ file mkdir $::appfs::cachedir sqlite3 ::appfs::db [file join $::appfs::cachedir cache.db] } - _db eval {CREATE TABLE IF NOT EXISTS packages(hostname, sha1, package, version, os, cpuArch, isLatest);} + _db eval {CREATE TABLE IF NOT EXISTS packages(hostname, sha1, package, version, os, cpuArch, isLatest, haveManifest);} _db eval {CREATE TABLE IF NOT EXISTS files(package_sha1, type, time, source, size, file_sha1, file_name, file_directory);} } proc download {hostname hash {method sha1}} { set url "http://$hostname/appfs/$method/$hash" @@ -140,18 +140,25 @@ if {$pkgInfo(isLatest)} { _db eval {UPDATE packages SET isLatest = 0 WHERE hostname = $hostname AND package = $pkgInfo($package) AND os = $pkgInfo($package) AND cpuArch = $pkgInfo(cpuArch);} } - _db eval {INSERT INTO packages (hostname, sha1, package, version, os, cpuArch, isLatest) VALUES ($hostname, $pkgInfo(hash), $pkgInfo(package), $pkgInfo(version), $pkgInfo(os), $pkgInfo(cpuArch), $pkgInfo(isLatest) );} + _db eval {INSERT INTO packages (hostname, sha1, package, version, os, cpuArch, isLatest, haveManifest) VALUES ($hostname, $pkgInfo(hash), $pkgInfo(package), $pkgInfo(version), $pkgInfo(os), $pkgInfo(cpuArch), $pkgInfo(isLatest), 0);} } return COMPLETE } proc getpkgmanifest {hostname package_sha1} { + set haveManifests [_db eval {SELECT haveManifest FROM packages WHERE sha1 = $package_sha1 LIMIT 1;}] + set haveManifest [lindex $haveManifests 0] + + if {$haveManifest} { + return COMPLETE + } + set file [download $hostname $package_sha1] set fd [open $file] set pkgdata [read $fd] close $fd @@ -187,9 +194,11 @@ set fileInfo(source) [lindex $work 0] } } _db eval {INSERT INTO files (package_sha1, type, time, source, size, file_sha1, file_name, file_directory) VALUES ($package_sha1, $fileInfo(type), $fileInfo(time), $fileInfo(source), $fileInfo(size), $fileInfo(sha1), $fileInfo(name), $fileInfo(directory) );} + _db eval {UPDATE packages SET haveManifest = 1 WHERE sha1 = $package_sha1;} } - } + return COMPLETE + } }