Check-in [c0f54be8fb]
Overview
Comment:Updated to deal with having no home directory gracefully and fixed bug introduced with childcount patch
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c0f54be8fb7f947a7ffc16ae0e19781115fcf2a9
User & Date: rkeene on 2014-11-10 06:19:12
Other Links: manifest | tags
Context
2014-11-10
06:47
Made home directory part user-servicable via config file check-in: dde1c0a38d user: rkeene tags: trunk
06:19
Updated to deal with having no home directory gracefully and fixed bug introduced with childcount patch check-in: c0f54be8fb user: rkeene tags: trunk
05:57
Moved to tcl-ops branch check-in: 0effed3239 user: rkeene tags: trunk
Changes

Modified appfsd.tcl from [85c7175a51] to [9561940a42].

   350    350   			}
   351    351   		}
   352    352   
   353    353   		return COMPLETE
   354    354   	}
   355    355   
   356    356   	proc _localpath {package hostname file} {
   357         -		set homedir [::appfsd::get_homedir]
   358         -		set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
          357  +		set dir ""
          358  +		catch {
          359  +			set homedir [::appfsd::get_homedir]
          360  +			set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"]
          361  +		}
   359    362   		return $dir
   360    363   	}
   361    364   
   362    365   	proc _whiteoutpath {package hostname file} {
   363         -		set homedir [::appfsd::get_homedir]
   364         -		set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"]
          366  +		set dir ""
          367  +		catch {
          368  +			set homedir [::appfsd::get_homedir]
          369  +			set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"]
          370  +		}
   365    371   		return $dir
   366    372   	}
   367    373   
   368    374   	proc _parsepath {path} {
   369    375   		set path [string trim $path "/"]
   370    376   		set path [split $path "/"]
   371    377   		set pathlen [llength $path]
................................................................................
   474    480   				set retval [::appfs::db eval {SELECT DISTINCT file_name FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_directory = $pathinfo(file);}]
   475    481   
   476    482   				if {[info exists pathinfo(package)] && [info exists pathinfo(hostname)] && [info exists pathinfo(file)]} {
   477    483   					_as_user {
   478    484   						set dir [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   479    485   						set whiteoutdir [string range [_whiteoutpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)] 0 end-15]
   480    486   
   481         -						foreach file [glob -nocomplain -tails -directory $whiteoutdir {{.,}*.APPFS.WHITEOUT}] {
   482         -							set remove [string range $file 0 end-15]
   483         -							set idx [lsearch -exact $retval $remove]
   484         -							if {$idx != -1} {
   485         -								set retval [lreplace $retval $idx $idx]
          487  +						if {$whiteoutdir != ""} {
          488  +							foreach file [glob -nocomplain -tails -directory $whiteoutdir {{.,}*.APPFS.WHITEOUT}] {
          489  +								set remove [string range $file 0 end-15]
          490  +								set idx [lsearch -exact $retval $remove]
          491  +								if {$idx != -1} {
          492  +									set retval [lreplace $retval $idx $idx]
          493  +								}
   486    494   							}
   487    495   						}
   488    496   
   489         -						foreach file [glob -nocomplain -tails -directory $dir -types {d f l p s} {{.,}*}] {
   490         -							if {$file == "." || $file == ".."} {
   491         -								continue
          497  +						if {$dir != ""} {
          498  +							foreach file [glob -nocomplain -tails -directory $dir {{.,}*}] {
          499  +								if {$file == "." || $file == ".."} {
          500  +									continue
          501  +								}
          502  +
          503  +								if {$file == ".APPFS.WHITEOUT"} {
          504  +									continue
          505  +								}
          506  +
          507  +								if {[lsearch -exact $retval $file] != -1} {
          508  +									continue
          509  +								}
          510  +
          511  +								lappend retval $file
   492    512   							}
   493         -
   494         -							if {$file == ".APPFS.WHITEOUT"} {
   495         -								continue
   496         -							}
   497         -
   498         -							if {[lsearch -exact $retval $file] != -1} {
   499         -								continue
   500         -							}
   501         -
   502         -							lappend retval $file
   503    513   						}
   504    514   					}
   505    515   				}
   506    516   
   507    517   				return $retval
   508    518   			}
   509    519   		}
................................................................................
   569    579   
   570    580   				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   571    581   				set whiteoutpath  [_whiteoutpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   572    582   
   573    583   				set retval(localpath) $localpath
   574    584   				set retval(whiteoutpath) $whiteoutpath
   575    585   
   576         -				if {[file exists $localpath]} {
          586  +				if {$localpath != "" && [file exists $localpath]} {
   577    587   					set retval(is_localfile) 1
   578    588   					catch {
   579    589   						_as_user {
   580    590   							file lstat $localpath localpathinfo
   581    591   						}
   582    592   						set retval(time) $localpathinfo(mtime)
   583    593   
................................................................................
   611    621   							"socket" {
   612    622   								# Capitalized so that the first char is unique
   613    623   								set retval(type) "Socket"
   614    624   							}
   615    625   						}
   616    626   					} err
   617    627   				} else {
   618         -					if {![file exists $whiteoutpath]} {
          628  +					if {$whiteoutpath == "" || ![file exists $whiteoutpath]} {
   619    629   						set retval(is_remotefile) 1
   620    630   
   621    631   						set work [split $pathinfo(file) "/"]
   622    632   						set directory [join [lrange $work 0 end-1] "/"]
   623    633   						set file [lindex $work end]
   624    634   
   625    635   						if {$directory == "" && $file == ""} {
   626    636   							array set retval [list type directory]
   627    637   						}
   628    638   
   629    639   						::appfs::db eval {SELECT type, time, source, size, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_directory = $directory AND file_name = $file;} retval {}
   630    640   
   631         -						if {$retval(type) == "directory"} {
          641  +						if {[info exists retval(type)] && $retval(type) == "directory"} {
   632    642   							set retval(childcount) [llength [getchildren $path]]
   633    643   						}
   634    644   
   635    645   						unset -nocomplain retval(*)
   636    646   					}
   637    647   				}
   638    648   
................................................................................
   652    662   		if {$pathinfo(_type) != "files"} {
   653    663   			return -code error "invalid type"
   654    664   		}
   655    665   
   656    666   		set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]
   657    667   
   658    668   		if {$mode == "create"} {
          669  +			if {$localpath == ""} {
          670  +				return -code error "Asked to create, but no home directory."
          671  +			}
          672  +
   659    673   			return $localpath
   660    674   		}
   661    675   
   662         -		if {[file exists $localpath]} {
          676  +		if {$localpath != "" && [file exists $localpath]} {
   663    677   			return $localpath
   664    678   		}
   665    679   
   666    680   		set work [split $pathinfo(file) "/"]
   667    681   		set directory [join [lrange $work 0 end-1] "/"]
   668    682   		set file [lindex $work end]
   669    683   		::appfs::db eval {SELECT file_sha1, perms FROM files WHERE package_sha1 = $pathinfo(package_sha1) AND file_name = $file AND file_directory = $directory;} pkgpathinfo {}
................................................................................
   738    752   		if {$must_not_exist} {
   739    753   			if {[exists $path] != ""} {
   740    754   				return -code error "File already exists"
   741    755   			}
   742    756   		}
   743    757   
   744    758   		set filename [localpath $path]
          759  +
          760  +		if {$filename == ""} {
          761  +			return -code error "Asked to create, but no home directory."
          762  +		}
   745    763   
   746    764   		set dirname [file dirname $filename]
   747    765   
   748    766   		_as_user {
   749    767   			file mkdir $dirname
   750    768   		}
   751    769   
................................................................................
   756    774   		array set pathattrs [exists $path]
   757    775   
   758    776   		if {![info exists pathattrs(packaged)]} {
   759    777   			return -code error "invalid type"
   760    778   		}
   761    779   
   762    780   		set localpath $pathattrs(localpath)
          781  +
          782  +		if {$localpath == ""} {
          783  +			return -code error "Asked to delete, but no home directory."
          784  +		}
   763    785   
   764    786   		if {[info exists pathattrs(is_localfile)]} {
   765    787   			if {[file isdirectory $localpath]} {
   766    788   				set children [getchildren $path]
   767    789   
   768    790   				if {[llength $children] != 0} {
   769    791   					return -code error "Asked to delete non-empty directory"