Diff

Differences From Artifact [1d195c7296]:

To Artifact [b7083177d4]:


1
2













3
4

5
6
7
8
9
10
11
12

13
14
15
16
17
18

19
20
21
22
23
24
25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24

25
26
27
28
29
30

31
32
33
34
35
36
37
38


+
+
+
+
+
+
+
+
+
+
+
+
+

-
+







-
+





-
+







#! /usr/bin/env bash

set -x

appfsd_options=()
if [ "$1" == "--cachedir" ]; then
	appfsd_options=("${appfsd_options[@]}" '--cachedir' "$2")

	shift; shift;
fi

function call_appfsd() {
	appfsd "${appfsd_options[@]}" "$@"
}

function invalidate() {
	appfsd -sqlite3 'UPDATE sites SET ttl = "0";'
	call_appfsd --sqlite3 'UPDATE sites SET ttl = "0";'
}

function remove_site() {
	local site

	site="$1"

	appfsd -sqlite3 'DELETE FROM sites WHERE hostname = '"'$site'"'; DELETE FROM packages WHERE hostname = '"'$site'"';' || return 1
	call_appfsd --sqlite3 'DELETE FROM sites WHERE hostname = '"'$site'"'; DELETE FROM packages WHERE hostname = '"'$site'"';' || return 1

	clean
}

function clean() {
	appfsd -tcl "$(cat <<\_EOF_
	call_appfsd --tcl "$(cat <<\_EOF_
		unset -nocomplain row
		::appfs::db eval {SELECT sha1, hostname FROM packages;} row {
			set hostname [::appfs::db onecolumn {SELECT hostname FROM sites WHERE hostname = $row(hostname) LIMIT 1;}]
			if {$hostname == ""} {
				continue
			}

51
52
53
54
55
56
57
58
59


60
61
62
63
64
65
66
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79







-
-
+
+








	if [ -n "${package}" ]; then
		echo "not implemented" >&2

		return 1
	fi

	appfsd -tcl 'file delete -force -- {*}[glob -directory $::appfs::cachedir {[0-9a-f][0-9a-f]}]' || return 1
	appfsd -sqlite3 'DELETE FROM sites; DELETE FROM packages; DELETE FROM files; VACUUM;' || return 1
	call_appfsd --tcl 'file delete -force -- {*}[glob -directory $::appfs::cachedir {[0-9a-f][0-9a-f]}]' || return 1
	call_appfsd --sqlite3 'DELETE FROM sites; DELETE FROM packages; DELETE FROM files; VACUUM;' || return 1
}

case "$1" in
	invalidate)
		invalidate || exit 1
		;;
	remove-site)