Check-in [b5d1616f0f]
Overview
Comment:Separated manifest fetching from index fetching
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b5d1616f0f6849fe2ffa99c58ae81a49bba57b20
User & Date: rkeene on 2014-09-08 02:38:06
Other Links: manifest | tags
Context
2014-09-08
02:50
Updated with support for not redownloading manifest if it's already present check-in: d64cb6e110 user: rkeene tags: trunk
02:38
Separated manifest fetching from index fetching check-in: b5d1616f0f user: rkeene tags: trunk
02:33
Updated to populate SQLite database with all package data check-in: 48a551bede user: rkeene tags: trunk
Changes

Modified appfs.tcl from [58a43bb4f1] to [b782d4f8ad].

60
61
62
63
64
65
66











67
68
69
70
71
72
73
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84







+
+
+
+
+
+
+
+
+
+
+








			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 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"
		set file [_cachefile $url $hash]

		if {![file exists $file]} {
			return -code error "Unable to fetch"
		}

		return $file
	}

	proc getindex {hostname} {
		if {[string match "*\[/~\]*" $hostname]} {
			return -code error "Invalid hostname"
		}

		set url "http://$hostname/appfs/index"
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180





181
182
183
184
185
186
187






















188


189
190
191














140
141
142
143
144
145
146








































147
148
149
150
151
152
153
154
155
156







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181



182
183
184
185
186
187
188
189
190
191
192
193
194
195







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-





+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

			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) );}

			set file [download $hostname $pkgInfo(hash)]
			set fd [open $file]
			set pkgdata [read $fd]
			close $fd

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

				if {[string match "*/*" $line]} {
					continue
				}

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

				set work [split $line ","]

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

				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]

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

				_db eval {INSERT INTO files (package_sha1, type, time, source, size, file_sha1, file_name, file_directory) VALUES ($pkgInfo(hash), $fileInfo(type), $fileInfo(time), $fileInfo(source), $fileInfo(size), $fileInfo(sha1), $fileInfo(name), $fileInfo(directory) );}
			}
		}

		return COMPLETE
	}

	proc getpkgmanifest {hostname package_sha1} {
		set file [download $hostname $package_sha1]
		set fd [open $file]
		set pkgdata [read $fd]
		close $fd
	proc download {hostname hash {method sha1}} {
		set url "http://$hostname/appfs/$method/$hash"
		set file [_cachefile $url $hash]

		if {![file exists $file]} {
			return -code error "Unable to fetch"
		}

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

			if {[string match "*/*" $line]} {
				continue
			}

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

			set work [split $line ","]

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

			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]

			set work [lrange $work 2 end-1]
			switch -- $fileInfo(type) {
		return $file
	}
}
				"file" {
					set fileInfo(size) [lindex $work 0]
					set fileInfo(sha1) [lindex $work 1]
				}
				"symlink" {
					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) );}
		}
	}

}