Diff

Differences From Artifact [9561940a42]:

To Artifact [2a6db15ed4]:


     2      2   
     3      3   package require http 2.7
     4      4   package require sqlite3
     5      5   package require sha1
     6      6   package require appfsd
     7      7   package require platform
     8      8   package require pki
            9  +
           10  +# Functions specifically meant for users to replace as a part of configuration
           11  +namespace eval ::appfs::user {
           12  +	# User-replacable function to convert a hostname/hash/method to an URL
           13  +	proc construct_url {hostname hash method} {
           14  +		return "http://$hostname/appfs/$method/$hash"
           15  +	}
           16  +
           17  +	# User-replaceable function get the home directory of the current user
           18  +	proc get_homedir {} {
           19  +		return [::appfsd::get_homedir]
           20  +	}
           21  +}
     9     22   
    10     23   namespace eval ::appfs {
    11     24   	variable cachedir "/tmp/appfs-cache"
    12     25   	variable ttl 3600
    13     26   	variable nttl 60
    14     27   
    15         -	# User-replacable function to convert a hostname/hash/method to an URL
    16         -	proc _construct_url {hostname hash method} {
    17         -		return "http://$hostname/appfs/$method/$hash"
    18         -	}
    19     28   
    20     29   	proc _hash_sep {hash {seps 4}} {
    21     30   		for {set idx 0} {$idx < $seps} {incr idx} {
    22     31   			append retval "[string range $hash [expr {$idx * 2}] [expr {($idx * 2) + 1}]]/"
    23     32   		}
    24     33   		append retval "[string range $hash [expr {$idx * 2}] end]"
    25     34   
................................................................................
   166    175   		# Create indexes
   167    176   		db eval {CREATE INDEX IF NOT EXISTS sites_index ON sites (hostname);}
   168    177   		db eval {CREATE INDEX IF NOT EXISTS packages_index ON packages (hostname, package, version, os, cpuArch);}
   169    178   		db eval {CREATE INDEX IF NOT EXISTS files_index ON files (package_sha1, file_name, file_directory);}
   170    179   	}
   171    180   
   172    181   	proc download {hostname hash {method sha1}} {
   173         -		set url [_construct_url $hostname $hash $method]
          182  +		set url [::appfs::user::construct_url $hostname $hash $method]
   174    183   		set file [_cachefile $url $hash]
   175    184   
   176    185   		if {![file exists $file]} {
   177    186   			return -code error "Unable to fetch (file does not exist: $file)"
   178    187   		}
   179    188   
   180    189   		return $file
................................................................................
   352    361   
   353    362   		return COMPLETE
   354    363   	}
   355    364   
   356    365   	proc _localpath {package hostname file} {
   357    366   		set dir ""
   358    367   		catch {
   359         -			set homedir [::appfsd::get_homedir]
          368  +			set homedir [::appfs::user::get_homedir]
   360    369   			set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
   361    370   		}
   362    371   		return $dir
   363    372   	}
   364    373   
   365    374   	proc _whiteoutpath {package hostname file} {
   366    375   		set dir ""
   367    376   		catch {
   368         -			set homedir [::appfsd::get_homedir]
          377  +			set homedir [::appfs::user::get_homedir]
   369    378   			set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"]
   370    379   		}
   371    380   		return $dir
   372    381   	}
   373    382   
   374    383   	proc _parsepath {path} {
   375    384   		set path [string trim $path "/"]