Diff

Differences From Artifact [c564230658]:

To Artifact [23568748fe]:


    34     34   
    35     35   		file mkdir [file dirname $file]
    36     36   
    37     37   		if {[file exists $file]} {
    38     38   			return $file
    39     39   		}
    40     40   
    41         -		set tmpfile "${file}.[expr {rand()}]"
           41  +		set tmpfile "${file}.[expr {rand()}][clock clicks]"
    42     42   
    43     43   		set fd [open $tmpfile "w"]
    44     44   		fconfigure $fd -translation binary
    45     45   
    46     46   		catch {
    47     47   			set token [::http::geturl $url -channel $fd -binary true]
    48     48   		}
................................................................................
   340    340   
   341    341   		return COMPLETE
   342    342   	}
   343    343   
   344    344   	proc _localpath {package hostname file} {
   345    345   		set homedir [::appfsd::get_homedir]
   346    346   		set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
          347  +		return $dir
   347    348   	}
   348    349   
   349    350   	proc _parsepath {path} {
   350    351   		set path [string trim $path "/"]
   351    352   		set path [split $path "/"]
   352    353   		set pathlen [llength $path]
   353    354   
................................................................................
   525    526   			return -code error "No such file or directory"
   526    527   		}
   527    528   
   528    529   		return [array get retval]
   529    530   	}
   530    531   
   531    532   	proc openpath {path mode} {
          533  +		array set pathinfo [_parsepath $path]
          534  +
          535  +		if {$pathinfo(_type) != "files"} {
          536  +			return -code error "invalid type"
          537  +		}
          538  +
          539  +		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
          540  +
          541  +		if {[file exists $localpath]} {
          542  +			return $localpath
          543  +		}
          544  +
          545  +		set work [split $pathinfo(file) "/"]
          546  +		set directory [join [lrange $work 0 end-1] "/"]
          547  +		set file [lindex $work end]
          548  +		set file_sha1 [::appfs::db onecolumn {SELECT file_sha1 FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;}]
          549  +
          550  +		if {$file_sha1 == ""} {
          551  +			return -code error "No such file or directory"
          552  +		}
          553  +
          554  +		set localcachefile [download $pathinfo(hostname) $file_sha1]
          555  +
          556  +		if {$mode == "create"} {
          557  +			set tmplocalpath "${localpath}.[expr rand()][clock clicks]"
          558  +			file copy -force -- $localcachefile $tmplocalpath
          559  +			file rename -force -- $tmplocalpath $localpath
          560  +
          561  +			return $localpath
          562  +		}
          563  +
          564  +		return $localcachefile
   532    565   	}
   533    566   }