Check-in [ddd31f22a4]
Overview
Comment:Added a "--cachedir" option for use when not using FUSE and added the same option to "appfs-cache"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcl-ops
Files: files | file ages | folders
SHA1: ddd31f22a4eb11be19bbd87032b3833bec70d4a4
User & Date: rkeene on 2014-11-07 07:14:28
Other Links: branch diff | manifest | tags
Context
2014-11-07
07:15
Clarified --cachedir check-in: 684f97bc4e user: rkeene tags: tcl-ops
07:14
Added a "--cachedir" option for use when not using FUSE and added the same option to "appfs-cache" check-in: ddd31f22a4 user: rkeene tags: tcl-ops
06:52
Added appropriate subtype check-in: 8eb7be2398 user: rkeene tags: tcl-ops
Changes

Modified appfs-cache from [1d195c7296] to [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)

Modified appfsd.c from [b204b9e307] to [9e818b560b].

722
723
724
725
726
727
728

















729
730
731
732
733
734
735
736
737









738
739
740
741

742
743
744
745
746
747
748
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760
761
762
763
764
765

766
767
768
769
770
771
772
773







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






-


+
+
+
+
+
+
+
+
+



-
+







	.getattr   = appfs_fuse_getattr,
	.readdir   = appfs_fuse_readdir,
	.readlink  = appfs_fuse_readlink,
	.open      = appfs_fuse_open,
	.release   = appfs_fuse_close,
	.read      = appfs_fuse_read
};

/*
 * FUSE option parsing callback
 */
static int appfs_fuse_opt_cb(void *data, const char *arg, int key, struct fuse_args *outargs) {
	static seen_cachedir = 0;

	if (key == FUSE_OPT_KEY_NONOPT && seen_cachedir == 0) {
		seen_cachedir = 1;

		globalThread.cachedir = strdup(arg);

		return(0);
	}

	return(1);
}

/*
 * Entry point into this program.
 */
int main(int argc, char **argv) {
	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
	const char *cachedir = APPFS_CACHEDIR;
	int pthread_ret;

	/*
	 * Skip passed program name
	 */
	if (argc == 0 || argv == NULL) {
		return(1);
	}
	argc--;
	argv++;

	/*
	 * Set global variables, these should be configuration options.
	 */
	globalThread.cachedir = cachedir;
	globalThread.cachedir = APPFS_CACHEDIR;
	globalThread.options.writable = 1;

	/*
	 * Set global variable for "boot time" to set a time on directories
	 * that we fake.
	 */
	globalThread.boottime = time(NULL);
762
763
764
765
766
767
768












769
770
771
772
773
774


775
776
777
778
779
780
781
782


783
784
785
786
787
788

789
790
791
792
793
794
795
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809


810
811
812
813
814
815
816
817


818
819
820
821
822
823
824

825
826
827
828
829
830
831
832







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




-
-
+
+






-
-
+
+





-
+







	 */
	pthread_ret = pthread_key_create(&interpKey, NULL);
	if (pthread_ret != 0) {
		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");

		return(1);
	}

	/*
	 * Manually specify cache directory, without FUSE callback
	 */
	if (argc >= 2) {
		if (strcmp(argv[0], "--cachedir") == 0) {
			globalThread.cachedir = strdup(argv[1]);

			argc -= 2;
			argv += 2;
		}
	}

	/*
	 * SQLite3 mode, for running raw SQL against the cache database
	 */
	if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) {
		return(appfs_sqlite3(argv[2]));
	if (argc == 2 && strcmp(argv[0], "--sqlite3") == 0) {
		return(appfs_sqlite3(argv[1]));
	}

	/*
	 * Tcl mode, for running raw Tcl in the same environment AppFSd would
	 * run code.
	 */
	if (argc == 3 && strcmp(argv[1], "-tcl") == 0) {
		return(appfs_tcl(argv[2]));
	if (argc == 2 && strcmp(argv[0], "--tcl") == 0) {
		return(appfs_tcl(argv[1]));
	}

	/*
	 * Add FUSE arguments which we always supply
	 */
	fuse_opt_parse(&args, NULL, NULL, NULL);
	fuse_opt_parse(&args, NULL, NULL, appfs_fuse_opt_cb);
	fuse_opt_add_arg(&args, "-odefault_permissions,fsname=appfs,subtype=appfsd,use_ino,kernel_cache,entry_timeout=60,attr_timeout=3600,intr,big_writes");

	if (getuid() == 0) {
		fuse_opt_parse(&args, NULL, NULL, NULL);
		fuse_opt_add_arg(&args, "-oallow_other");
	}