Check-in [5685a8f9a8]
Overview
Comment:Added validity checking for various types
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcl-ops
Files: files | file ages | folders
SHA1: 5685a8f9a85493348c68a0fc7b9a32d345a74c51
User & Date: rkeene on 2014-11-07 13:04:56
Other Links: branch diff | manifest | tags
Context
2014-11-07
13:19
Added more reliable write support check-in: d836b9fc43 user: rkeene tags: tcl-ops
13:04
Added validity checking for various types check-in: 5685a8f9a8 user: rkeene tags: tcl-ops
12:26
Added basic write support check-in: db5fcbef28 user: rkeene tags: tcl-ops
Changes

Modified appfsd.tcl from [1c94a0206c] to [25e6dbc0f2].

     1      1   #! /usr/bin/env tclsh
     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  +package require platform
     7      8   
     8      9   namespace eval ::appfs {
     9     10   	variable cachedir "/tmp/appfs-cache"
    10     11   	variable ttl 3600
    11     12   	variable nttl 60
    12     13   
    13     14   	# User-replacable function to convert a hostname/hash/method to an URL
................................................................................
   394    395   						if {$pathlen > 3} {
   395    396   							set retval(version) [lindex $path 3]
   396    397   							set retval(_children) files
   397    398   							set retval(_type) versions
   398    399   
   399    400   							set retval(package_sha1) [::appfs::db onecolumn {SELECT sha1 FROM packages WHERE hostname = $retval(hostname) AND os = $retval(os) AND cpuArch = $retval(cpu) AND version = $retval(version);}]
   400    401   							if {$retval(package_sha1) == ""} {
   401         -								return [list]
          402  +								set retval(_children) dead
          403  +								return [array get retval]
   402    404   							}
   403    405   
   404    406   							if {$pathlen > 4} {
   405    407   								set retval(_type) files
   406    408   								set retval(file) [join [lrange $path 4 end] "/"]
   407    409   							} else {
   408    410   								set retval(file) ""
................................................................................
   476    478   	}
   477    479   
   478    480   	proc getattr {path} {
   479    481   		array set pathinfo [_parsepath $path]
   480    482   		array set retval [list]
   481    483   
   482    484   		switch -- $pathinfo(_type) {
   483         -			"toplevel" - "sites" - "packages" - "os-cpu" - "versions" {
          485  +			"toplevel" {
   484    486   				set retval(type) directory
   485    487   				set retval(childcount) 2;
          488  +			}
          489  +			"sites" {
          490  +				set check [::appfs::db onecolumn {SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname);}]
          491  +				if {$check == "1"} {
          492  +					set retval(type) directory
          493  +					set retval(childcount) 2;
          494  +				}
          495  +			}
          496  +			"packages" {
          497  +				set check [::appfs::db onecolumn {SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname) AND package = $pathinfo(package);}]
          498  +				if {$check == "1"} {
          499  +					set retval(type) directory
          500  +					set retval(childcount) 2;
          501  +				}
          502  +			}
          503  +			"os-cpu" {
          504  +				if {$pathinfo(os) == "platform" && $pathinfo(cpu) == ""} {
          505  +					set retval(type) symlink
          506  +					set retval(source) [platform::generic]
          507  +				} else {
          508  +					set check [::appfs::db onecolumn {
          509  +						SELECT 1 FROM packages WHERE hostname = $pathinfo(hostname) AND package = $pathinfo(package) AND os = $pathinfo(os) AND cpuArch = $pathinfo(cpu);
          510  +					}]
          511  +					if {$check == "1"} {
          512  +						set retval(type) directory
          513  +						set retval(childcount) 2;
          514  +					}
          515  +				}
          516  +			}
          517  +			"versions" {
          518  +				if {$pathinfo(version) == "latest"} {
          519  +					set retval(type) symlink
          520  +					set retval(source) "1.0"
          521  +				} else {
          522  +					if {[info exists pathinfo(package_sha1)] && $pathinfo(package_sha1) != ""} {
          523  +						set retval(type) directory
          524  +						set retval(childcount) 2;
          525  +					}
          526  +				}
   486    527   			}
   487    528   			"files" {
   488    529   				set retval(packaged) 1
   489    530   
   490    531   				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   491    532   				if {[file exists $localpath]} {
   492    533   					catch {