Tcl Source Code

View Ticket
Login
Ticket UUID: 961646
Title: [file normalize] changes file reference
Type: Bug Created on: 2004-05-27 15:36:01
Submitter: dgp Assigned to: aku
Subsystem: 37. File System Severity: Minor
Priority: 5 Medium Last modified: 2018-06-28 19:06:41
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: obsolete: 8.5a2
Description:
% glob *
file
% open noSuchDir/../file
couldn't open "noSuchDir/../file": no such file or
directory
% open [file normalize noSuchDir/../file]
file3

Here [file normalize] converts
"noSuchDir/../file" to "file", but
and [open] on one fails, the  other
succeeds.

I think of [file normalize] giving me
the preferred name among many
names for one file.  Here it is
convering a string that names no
file into one that does name a file.

This suggests that /../ interpretation
is Tcl_Filesystem-specific and
ought to be done in each Tcl_Filesystem's
Tcl_FSNormalizePathProc rather
than in the core FS layer.
User Comments:
vincentdarley added on 2004-05-27 22:50:02:
Logged In: YES 
user_id=32170

An alternative interpretation is that 'open' on Unix has a
bug.  For example:

% file exists noSuchDir/../file
1

works just fine.  (And on Windows your 'open' example works
fine too)

dgp added on 2004-05-28 00:14:55:
Logged In: YES 
user_id=80530

% file exists noSuchDir/../file
0
% file exists [file normalize noSuchDir/../file]
1

The interpretation of /../ is filesystem dependent.

vincentdarley added on 2004-06-02 21:27:58:
Logged In: YES 
user_id=32170

I still tend to think this illustrates a bug in Tcl
somewhere, since the above behaviour is not expected.  I now
think it's due to some of the fs-optimization that was
performed.  In particular, I think it's due to the 'if'
block here in NativeCreateNativeRep:

    if (tsdPtr->cwdClientData != NULL) {
        /* The cwd is native */
validPathPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr);
    } else {
/* Make sure the normalized path is set */
validPathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr);
Tcl_IncrRefCount(validPathPtr);
    }

try making that 'if (0)' and see if the problem goes away.

--

Now, it's a separate issue as to what the desired behaviour
is.  I see arguments for both approaches, really.  In
particular, if, as you suggest the /../ interpretation is
moved to the filesystem-specific layer (vastly complicating
all filesystems), what behaviour should 'file normalize'
have in this case?  How should 'file normalize' be documented?

dgp added on 2018-06-28 19:06:41:
The rules of path resolution by linux system calls are spelled out here.

  http://man7.org/linux/man-pages/man7/path_resolution.7.html

According to them, Tcl needs to pass the "/.." substrings of things
like /path/to/../foobar to the system calls intact to get them processed
properly against the state of the filesystem. Lexical shortening due to
"normalization" or for whatever other reasons lurk in the core of
Tcl filesystem operations to pass /path/foobar instead are incorrect.

That is, they create a system where the meaning of paths in Tcl are
demonstrably inconsistent with the meaning of paths on the platform
itself.  If Tcl really does mean to intentionally be different, that
needs a lot more explanation and spelling out.  I think it's just a
broken implementation.