Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: f13181c69e4f128bc25661bc7d92c456ddf7346a
Ticket: da7c079978cb3183731147d2e6a555794416a5bf
FS strips root '/' from FS root volume "zvfs:/"
User & Date: anonymous on 2017-06-08 02:35:24
Changes

  1. comment changed to:
    I've been attempting to create a vfs which is totally isolated from the native fs. I've set the Tcl_Filesystem to "zvfs" and, following the example in tclTest.c, my FSListVolumesProc returns a single Tcl_Obj "zvfs:/".
    
    Using a minimal Tcl_Filesystem with only ListVolumes, Chdir and PathInFilesystem (which always returns TCL_OK unless the path is a windows path), I find that Tcl is stripping the root '/' from what it considers the cwd.
    
    % cd zvfs:/
    % cd dir
    % pwd
    zvfs:/dir
    % cd ..
    % pwd
    zvfs:
    
    Tcl handles windows paths correctly -- the '/' is not stripped from, say, "C:/".
    
    The routine TclFSNormalizeAbsolutePath in tclPathObj.c is the culprit. It is taking "zvfs:/dir/.." and:
    
    		/*
    		 * Have '..' so need to skip previous directory.
    		 */
    		if (retVal == NULL) {
    		    const char *path = TclGetString(pathPtr);
    
    		    retVal = Tcl_NewStringObj(path, dirSep - path);
    		    Tcl_IncrRefCount(retVal);
    		}
    
    removes the '/' leaving "zvfs:". Toward the bottom of the function there is specific windows code to restore the '/':
    
    
        /*
         * Ensure a windows drive like C:/ has a trailing separator.
         */
    
        if (tclPlatform == TCL_PLATFORM_WINDOWS) {
    	int len;
    	const char *path = Tcl_GetStringFromObj(retVal, &len);
    
    	if (len == 2 && path[0] != 0 && path[1] == ':') {
    	    if (Tcl_IsShared(retVal)) {
    		TclDecrRefCount(retVal);
    		retVal = Tcl_DuplicateObj(retVal);
    		Tcl_IncrRefCount(retVal);
    	    }
    	    Tcl_AppendToObj(retVal, "/", 1);
    	}
        }
    
    Either:
    a) I don't understand what FSListVolumesProc is supposed to return
    b) If "zvfs:/" is OK, then perhaps it's not meant to be equivalent to a windows "drive" even though TclpObjListVolumes() in win/tclWinFCmd.c returns "C:/", etc.
    c) Tcl does not consider fs volumes other than windows
    
    I don't know if this is a bug or what.
    
    How is a fs supposed to tell Tcl about a volume prefix? 
    
    Must a fs "mount" its directory structure somewhere within '/' for both unix and windows?
    
    I wish there was a reference fs or the documentation were more detailed.
    
  2. login: "anonymous"
  3. mimetype: "text/plain"