Diff

Differences From Artifact [25e6dbc0f2]:

To Artifact [6f6d010e1e]:


   476    476   
   477    477   		return -code error "Invalid or unacceptable path: $dir"
   478    478   	}
   479    479   
   480    480   	proc getattr {path} {
   481    481   		array set pathinfo [_parsepath $path]
   482    482   		array set retval [list]
          483  +
          484  +		catch {
          485  +			::appfs::getindex $pathinfo(hostname)
          486  +			::appfs::getpkgmanifest $pathinfo(hostname) $pathinfo(package_sha1)
          487  +		}
   483    488   
   484    489   		switch -- $pathinfo(_type) {
   485    490   			"toplevel" {
   486    491   				set retval(type) directory
   487    492   				set retval(childcount) 2;
   488    493   			}
   489    494   			"sites" {
................................................................................
   522    527   					if {[info exists pathinfo(package_sha1)] && $pathinfo(package_sha1) != ""} {
   523    528   						set retval(type) directory
   524    529   						set retval(childcount) 2;
   525    530   					}
   526    531   				}
   527    532   			}
   528    533   			"files" {
          534  +
   529    535   				set retval(packaged) 1
   530    536   
   531    537   				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   532    538   				if {[file exists $localpath]} {
   533    539   					catch {
   534    540   						file lstat $localpath localpathinfo
   535    541   						set retval(time) $localpathinfo(mtime)
................................................................................
   580    586   		}
   581    587   
   582    588   		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   583    589   
   584    590   		if {[file exists $localpath]} {
   585    591   			return $localpath
   586    592   		}
          593  +
          594  +		if {$mode == "create"} {
          595  +			return $localpath
          596  +		}
   587    597   
   588    598   		set work [split $pathinfo(file) "/"]
   589    599   		set directory [join [lrange $work 0 end-1] "/"]
   590    600   		set file [lindex $work end]
   591         -		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;}]
          601  +		::appfs::db eval {SELECT file_sha1, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;} pkgpathinfo {}
   592    602   
   593         -		if {$file_sha1 == ""} {
          603  +		if {$pkgpathinfo(file_sha1) == ""} {
   594    604   			return -code error "No such file or directory"
   595    605   		}
   596    606   
   597         -		set localcachefile [download $pathinfo(hostname) $file_sha1]
          607  +		set localcachefile [download $pathinfo(hostname) $pkgpathinfo(file_sha1)]
   598    608   
   599         -		if {$mode == "create"} {
          609  +		if {$mode == "write"} {
   600    610   			set tmplocalpath "${localpath}.[expr rand()][clock clicks]"
   601         -			file copy -force -- $localcachefile $tmplocalpath
   602         -			file rename -force -- $tmplocalpath $localpath
          611  +
          612  +			catch {
          613  +				file copy -force -- $localcachefile $tmplocalpath
          614  +
          615  +				if {$pkgpathinfo(perms) == "x"} {
          616  +					file attributes $tmplocalpath -permissions +x
          617  +				}
          618  +
          619  +				file rename -force -- $tmplocalpath $localpath
          620  +			}
          621  +			catch {
          622  +				file delete -force -- $tmplocalpath
          623  +			}
   603    624   
   604    625   			return $localpath
   605    626   		}
   606    627   
   607    628   		return $localcachefile
   608    629   	}
   609    630   }