Overview
| Artifact ID: | acf4b3f93b14776c373c7ceeaa7dada6255df08d |
|---|---|
| Ticket: | a47641a031858cceccf92c9a6da34406b35fed77
File normalize is inconsistent with Windows junctions (filesystem-1.3,4) |
| User & Date: | apnadkarni on 2016-02-25 06:06:59 |
Changes
- icomment:
There is a bunch of code in the execution path [file normalize [file join ...]] that I find dubious but the root cause of this specific bug is the special optimization case in TclJoinPath starting at line 874 in tclPathObj.c After a bunch of checks to ensure certain criteria are met (for example, only two elements to join), the special case code calls TclNewFSPathObj to construct the joined path and returns the result. However, as indicated by the comments and reflected in the code, TclNewFSPathObj expects the first argument to be an *absolute* path which in the test case example, it isn't. The returned object's FsPath intrep is essentially marked as not needing normalization (the TCLPATH_NEEDNORM flag is not set) though the cwdPtr field is NOT normalized or absolute. Later, Tcl_FSGetNormalizedPath skips over the crucial normalization code thinking the FsPath intrep is already normalized. Hence the wrong result. Options are - disable the TclJoinPath special case. I've tested that this fixes both the reported bug as well as the failing test cases. I don't know how much of a performance impact this has in real life. The time command does not show any appreciable difference for the file join itself. - disable the optimized code only for Windows since it appears this bug does not manifest on Unix. I'm actually curious as to why since it is common code. My guess is that the file system specific call for normalization does something different on Unix. - Add a check to special case criteria that the first argument is indeed an absolute path. In addition to fixing file join as above, the question also arises whether file normalize should even use cached results at all. IMHO semantics of normalize should require a visit to the filesystem at the time the call is made. Otherwise, how does it take into account a link created (possibly even from outside the program itself) after a path is cached? For the same reason, one might argue that the file link command should increment the global file system epoch when a link is created to invalidate all cached representations. This is exactly as what is done when env(HOME) changes or file system mounts are changed (see comments in tclioutil.c)
- login: "apnadkarni"
- mimetype: "text/plain"