VfsFullyNormalizePath fix vfs-1-2
authorVince Darley <vincentdarley@sourceforge.net>
Tue, 4 Feb 2003 18:54:39 +0000 (18:54 +0000)
committerVince Darley <vincentdarley@sourceforge.net>
Tue, 4 Feb 2003 18:54:39 +0000 (18:54 +0000)
ChangeLog
generic/vfs.c

index 096b565654c0ca501972da754e7b5c6429bb7d1a..c9d5b16c65a05f979f2d1bad83625aa3021979b1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-2003-01-28  Vince Darley <vincentdarley@sourceforge.net>
+2003-02-04  Vince Darley <vincentdarley@sourceforge.net>
+
+       * generic/vfs.c: fixed version of VfsFullyNormalizePath,
+       should resolve some problems with symlinks. Tcl really needs
+       a 'file normalized -full' and equivalent C api.
+       
+2003-02-04  Vince Darley <vincentdarley@sourceforge.net>
 
        * tests/*.test: cleanup
        
index 8ba028f47d76480f14f5261d18ec38cc309fbcc3..f49ee020b787fa935cbc825c40fc8adce130e911 100644 (file)
@@ -801,6 +801,39 @@ VfsFullyNormalizePath(Tcl_Interp *interp, Tcl_Obj *pathPtr) {
        if (path == NULL) {
            break;
        }
+       if (Tcl_FSGetPathType(path) != TCL_PATH_ABSOLUTE) {
+           /* 
+            * This is more complex, we need to find the path
+            * relative to the original file, effectively:
+            * 
+            *  file join [file dirname $pathPtr] $path
+            *  
+            * or 
+            * 
+            *  file join $pathPtr .. $path
+            *  
+            * So...
+            */
+           Tcl_Obj *dotdotPtr, *joinedPtr;
+           Tcl_Obj *joinElements[2];
+           
+           dotdotPtr = Tcl_NewStringObj("..",2);
+           Tcl_IncrRefCount(dotdotPtr);
+           
+           joinElements[0] = dotdotPtr;
+           joinElements[1] = path;
+
+           joinedPtr = Tcl_FSJoinToPath(pathPtr, 2, joinElements);
+           
+           if (joinedPtr != NULL) {
+               Tcl_IncrRefCount(joinedPtr);
+               Tcl_DecrRefCount(path);
+               path = joinedPtr;
+           } else {
+               /* We failed, and our action is undefined */
+           }
+           Tcl_DecrRefCount(dotdotPtr);
+       }
        Tcl_DecrRefCount(pathPtr);
        pathPtr = path;
        counter++;