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: | 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 1 #! /usr/bin/env bash 2 + 3 +set -x 4 + 5 +appfsd_options=() 6 +if [ "$1" == "--cachedir" ]; then 7 + appfsd_options=("${appfsd_options[@]}" '--cachedir' "$2") 8 + 9 + shift; shift; 10 +fi 11 + 12 +function call_appfsd() { 13 + appfsd "${appfsd_options[@]}" "$@" 14 +} 2 15 3 16 function invalidate() { 4 - appfsd -sqlite3 'UPDATE sites SET ttl = "0";' 17 + call_appfsd --sqlite3 'UPDATE sites SET ttl = "0";' 5 18 } 6 19 7 20 function remove_site() { 8 21 local site 9 22 10 23 site="$1" 11 24 12 - appfsd -sqlite3 'DELETE FROM sites WHERE hostname = '"'$site'"'; DELETE FROM packages WHERE hostname = '"'$site'"';' || return 1 25 + call_appfsd --sqlite3 'DELETE FROM sites WHERE hostname = '"'$site'"'; DELETE FROM packages WHERE hostname = '"'$site'"';' || return 1 13 26 14 27 clean 15 28 } 16 29 17 30 function clean() { 18 - appfsd -tcl "$(cat <<\_EOF_ 31 + call_appfsd --tcl "$(cat <<\_EOF_ 19 32 unset -nocomplain row 20 33 ::appfs::db eval {SELECT sha1, hostname FROM packages;} row { 21 34 set hostname [::appfs::db onecolumn {SELECT hostname FROM sites WHERE hostname = $row(hostname) LIMIT 1;}] 22 35 if {$hostname == ""} { 23 36 continue 24 37 } 25 38 ................................................................................ 51 64 52 65 if [ -n "${package}" ]; then 53 66 echo "not implemented" >&2 54 67 55 68 return 1 56 69 fi 57 70 58 - appfsd -tcl 'file delete -force -- {*}[glob -directory $::appfs::cachedir {[0-9a-f][0-9a-f]}]' || return 1 59 - appfsd -sqlite3 'DELETE FROM sites; DELETE FROM packages; DELETE FROM files; VACUUM;' || return 1 71 + call_appfsd --tcl 'file delete -force -- {*}[glob -directory $::appfs::cachedir {[0-9a-f][0-9a-f]}]' || return 1 72 + call_appfsd --sqlite3 'DELETE FROM sites; DELETE FROM packages; DELETE FROM files; VACUUM;' || return 1 60 73 } 61 74 62 75 case "$1" in 63 76 invalidate) 64 77 invalidate || exit 1 65 78 ;; 66 79 remove-site)
Modified appfsd.c from [b204b9e307] to [9e818b560b].
722 722 .getattr = appfs_fuse_getattr, 723 723 .readdir = appfs_fuse_readdir, 724 724 .readlink = appfs_fuse_readlink, 725 725 .open = appfs_fuse_open, 726 726 .release = appfs_fuse_close, 727 727 .read = appfs_fuse_read 728 728 }; 729 + 730 +/* 731 + * FUSE option parsing callback 732 + */ 733 +static int appfs_fuse_opt_cb(void *data, const char *arg, int key, struct fuse_args *outargs) { 734 + static seen_cachedir = 0; 735 + 736 + if (key == FUSE_OPT_KEY_NONOPT && seen_cachedir == 0) { 737 + seen_cachedir = 1; 738 + 739 + globalThread.cachedir = strdup(arg); 740 + 741 + return(0); 742 + } 743 + 744 + return(1); 745 +} 729 746 730 747 /* 731 748 * Entry point into this program. 732 749 */ 733 750 int main(int argc, char **argv) { 734 751 struct fuse_args args = FUSE_ARGS_INIT(argc, argv); 735 - const char *cachedir = APPFS_CACHEDIR; 736 752 int pthread_ret; 737 753 754 + /* 755 + * Skip passed program name 756 + */ 757 + if (argc == 0 || argv == NULL) { 758 + return(1); 759 + } 760 + argc--; 761 + argv++; 762 + 738 763 /* 739 764 * Set global variables, these should be configuration options. 740 765 */ 741 - globalThread.cachedir = cachedir; 766 + globalThread.cachedir = APPFS_CACHEDIR; 742 767 globalThread.options.writable = 1; 743 768 744 769 /* 745 770 * Set global variable for "boot time" to set a time on directories 746 771 * that we fake. 747 772 */ 748 773 globalThread.boottime = time(NULL); ................................................................................ 762 787 */ 763 788 pthread_ret = pthread_key_create(&interpKey, NULL); 764 789 if (pthread_ret != 0) { 765 790 fprintf(stderr, "Unable to create TSD key for Tcl. Aborting.\n"); 766 791 767 792 return(1); 768 793 } 794 + 795 + /* 796 + * Manually specify cache directory, without FUSE callback 797 + */ 798 + if (argc >= 2) { 799 + if (strcmp(argv[0], "--cachedir") == 0) { 800 + globalThread.cachedir = strdup(argv[1]); 801 + 802 + argc -= 2; 803 + argv += 2; 804 + } 805 + } 769 806 770 807 /* 771 808 * SQLite3 mode, for running raw SQL against the cache database 772 809 */ 773 - if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) { 774 - return(appfs_sqlite3(argv[2])); 810 + if (argc == 2 && strcmp(argv[0], "--sqlite3") == 0) { 811 + return(appfs_sqlite3(argv[1])); 775 812 } 776 813 777 814 /* 778 815 * Tcl mode, for running raw Tcl in the same environment AppFSd would 779 816 * run code. 780 817 */ 781 - if (argc == 3 && strcmp(argv[1], "-tcl") == 0) { 782 - return(appfs_tcl(argv[2])); 818 + if (argc == 2 && strcmp(argv[0], "--tcl") == 0) { 819 + return(appfs_tcl(argv[1])); 783 820 } 784 821 785 822 /* 786 823 * Add FUSE arguments which we always supply 787 824 */ 788 - fuse_opt_parse(&args, NULL, NULL, NULL); 825 + fuse_opt_parse(&args, NULL, NULL, appfs_fuse_opt_cb); 789 826 fuse_opt_add_arg(&args, "-odefault_permissions,fsname=appfs,subtype=appfsd,use_ino,kernel_cache,entry_timeout=60,attr_timeout=3600,intr,big_writes"); 790 827 791 828 if (getuid() == 0) { 792 829 fuse_opt_parse(&args, NULL, NULL, NULL); 793 830 fuse_opt_add_arg(&args, "-oallow_other"); 794 831 } 795 832