Go Back   FlashFXP Forums > >

Programming Need help with C/C++/Delphi? Ask here and make us all laugh.

Closed Thread
 
Thread Tools Rate Thread Display Modes
Old 03-31-2005, 11:17 AM   #1
deo
Banned
 
Join Date: Feb 2005
Posts: 46
Default [TCL] resolve realpath $path

doesnt error, but doesnt return anything

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

thanks
deo is offline  
Old 03-31-2005, 11:23 AM   #2
neoxed
Too much time...
FlashFXP Beta Tester
ioFTPD Scripter
 
Join Date: May 2003
Posts: 1,326
Default

I could never get it work either, so I wrote my own virtual->real path resolver.

Code:
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).
neoxed is offline  
Old 03-31-2005, 11:42 AM   #3
deo
Banned
 
Join Date: Feb 2005
Posts: 46
Default

crikeY!

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

thx
deo is offline  
Closed Thread

Tags
$path, /pwd, error, expecting, returned

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:30 PM.

Parts of this site powered by vBulletin Mods & Addons from DragonByte Technologies Ltd. (Details)