PDA

View Full Version : [TCL] resolve realpath $path


deo
03-31-2005, 11:17 AM
doesnt error, but doesnt return anything

i was expecting /pwd/ to be returned from $path given ?

thanks

neoxed
03-31-2005, 11:23 AM
I could never get it work either, so I wrote my own virtual->real path resolver.

proc ::nxTools::Pre::ResolvePath {UserName GroupName RealPath} {
set BestMatch 0
set ResolvePath "/"; set VfsFile ""
set RealPath [string map {\\ /} $RealPath]

## Find the user vfs-file
if {[userfile open $UserName] == 0} {
set UserFile [userfile bin2ascii]
foreach UserLine [split $UserFile "\r\n"] {
set LineType [string tolower [lindex $UserLine 0]]
if {[string equal "vfsfile" $LineType]} {
set VfsFile [ArgRange $UserLine 1 end]; break
}
}
}
## Use the group vfs-file, if the user vfs-file doesn't exist.
if {![file isfile $VfsFile] && [groupfile open $GroupName] == 0} {
set GroupFile [groupfile bin2ascii]
foreach GroupLine [split $GroupFile "\r\n"] {
set LineType [string tolower [lindex $GroupLine 0]]
if {[string equal "vfsfile" $LineType]} {
set VfsFile [ArgRange $GroupLine 1 end]; break
}
}
}
## Use the default vfs-file, if the user or group vfs-file don't exist.
if {![file isfile $VfsFile]} {
set VfsFile [config read "Locations" "Default_Vfs"]
}
if {![catch {set Handle [open $VfsFile r]} ErrorMsg]} {
while {![eof $Handle]} {
if {[set FileLine [string trim [gets $Handle]]] == ""} {continue}
foreach {VfsRealPath VfsVirtualPath} [string map {\\ /} $FileLine] {break}
if {[string first [string tolower $VfsRealPath] [string tolower $RealPath]] == 0} {
## Use the longest available mount path (most accurate)
if {[set Length [string length $VfsRealPath]] > $BestMatch} {
set ResolvePath [string range $RealPath [set BestMatch $Length] end]
set ResolvePath [file join $VfsVirtualPath [string trimleft $ResolvePath "/"]]
}
}
}
close $Handle
} else {
ErrorLog PreResolvePath $ErrorMsg
ErrorReturn "Unable to resolve virtual path, contact a siteop."
}
return $ResolvePath
}

Feel free to use it, though you might have to change a few things for it to work with your script(s).

deo
03-31-2005, 11:42 AM
crikeY!

this is why 'vfs chattr $realpath -r $realpath' would be a nice option :)

thx