@@ -352,18 +352,24 @@ return COMPLETE } proc _localpath {package hostname file} { - set homedir [::appfsd::get_homedir] - set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"] + set dir "" + catch { + set homedir [::appfsd::get_homedir] + set dir [file join $homedir .appfs "./${package}@${hostname}" "./${file}"] + } return $dir } proc _whiteoutpath {package hostname file} { - set homedir [::appfsd::get_homedir] - set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"] + set dir "" + catch { + set homedir [::appfsd::get_homedir] + set dir [file join $homedir .appfs "./${package}@${hostname}" ".APPFS.WHITEOUT" "./${file}.APPFS.WHITEOUT"] + } return $dir } proc _parsepath {path} { set path [string trim $path "/"] @@ -476,32 +482,36 @@ if {[info exists pathinfo(package)] && [info exists pathinfo(hostname)] && [info exists pathinfo(file)]} { _as_user { set dir [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)] set whiteoutdir [string range [_whiteoutpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)] 0 end-15] - foreach file [glob -nocomplain -tails -directory $whiteoutdir {{.,}*.APPFS.WHITEOUT}] { - set remove [string range $file 0 end-15] - set idx [lsearch -exact $retval $remove] - if {$idx != -1} { - set retval [lreplace $retval $idx $idx] - } - } - - foreach file [glob -nocomplain -tails -directory $dir -types {d f l p s} {{.,}*}] { - if {$file == "." || $file == ".."} { - continue - } - - if {$file == ".APPFS.WHITEOUT"} { - continue - } - - if {[lsearch -exact $retval $file] != -1} { - continue - } - - lappend retval $file + if {$whiteoutdir != ""} { + foreach file [glob -nocomplain -tails -directory $whiteoutdir {{.,}*.APPFS.WHITEOUT}] { + set remove [string range $file 0 end-15] + set idx [lsearch -exact $retval $remove] + if {$idx != -1} { + set retval [lreplace $retval $idx $idx] + } + } + } + + if {$dir != ""} { + foreach file [glob -nocomplain -tails -directory $dir {{.,}*}] { + if {$file == "." || $file == ".."} { + continue + } + + if {$file == ".APPFS.WHITEOUT"} { + continue + } + + if {[lsearch -exact $retval $file] != -1} { + continue + } + + lappend retval $file + } } } } return $retval @@ -571,11 +581,11 @@ set whiteoutpath [_whiteoutpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)] set retval(localpath) $localpath set retval(whiteoutpath) $whiteoutpath - if {[file exists $localpath]} { + if {$localpath != "" && [file exists $localpath]} { set retval(is_localfile) 1 catch { _as_user { file lstat $localpath localpathinfo } @@ -613,11 +623,11 @@ set retval(type) "Socket" } } } err } else { - if {![file exists $whiteoutpath]} { + if {$whiteoutpath == "" || ![file exists $whiteoutpath]} { set retval(is_remotefile) 1 set work [split $pathinfo(file) "/"] set directory [join [lrange $work 0 end-1] "/"] set file [lindex $work end] @@ -626,11 +636,11 @@ array set retval [list type directory] } ::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 {} - if {$retval(type) == "directory"} { + if {[info exists retval(type)] && $retval(type) == "directory"} { set retval(childcount) [llength [getchildren $path]] } unset -nocomplain retval(*) } @@ -654,14 +664,18 @@ } set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)] if {$mode == "create"} { + if {$localpath == ""} { + return -code error "Asked to create, but no home directory." + } + return $localpath } - if {[file exists $localpath]} { + if {$localpath != "" && [file exists $localpath]} { return $localpath } set work [split $pathinfo(file) "/"] set directory [join [lrange $work 0 end-1] "/"] @@ -740,10 +754,14 @@ return -code error "File already exists" } } set filename [localpath $path] + + if {$filename == ""} { + return -code error "Asked to create, but no home directory." + } set dirname [file dirname $filename] _as_user { file mkdir $dirname @@ -758,10 +776,14 @@ if {![info exists pathattrs(packaged)]} { return -code error "invalid type" } set localpath $pathattrs(localpath) + + if {$localpath == ""} { + return -code error "Asked to delete, but no home directory." + } if {[info exists pathattrs(is_localfile)]} { if {[file isdirectory $localpath]} { set children [getchildren $path]