Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-11-13
21:58 • Closed ticket [cc1fabcb10]: windows: file join, file normalize (and/or Tcl_FSGet... artifact: 1b0ef5ddd8 user: jan.nijtmans
2024-11-11
11:58 • Ticket [cc1fabcb10]: 3 changes artifact: 60d29cd451 user: jan.nijtmans
2024-11-08
13:00 • Ticket [cc1fabcb10]: 3 changes artifact: 4b2ab0f9d1 user: juliannoble2
12:58 • Ticket [cc1fabcb10]: 3 changes artifact: a9cba6f931 user: juliannoble2
12:01 • Ticket [cc1fabcb10]: 3 changes artifact: 50503150d1 user: pooryorick
09:26 • Ticket [cc1fabcb10]: 3 changes artifact: beb7debf09 user: juliannoble2
09:11 • Ticket [cc1fabcb10]: 3 changes artifact: 0c7a741186 user: juliannoble2
07:30 • Ticket [cc1fabcb10]: 4 changes artifact: 621fa8a28f user: oehhar
00:13 • New ticket [cc1fabcb10]. artifact: 4b4548b3a8 user: sebres

windows: file join, file normalize (and/or Tcl_FSGetTranslatedPath) behave incorrect by translation to parent dir for root of samba path

Closed / Invalidcc1fabcb10f74c404f7992845c64f796e43fd27bCreated 2 years agoUpdated 2 years ago
Descriptionwiki2024-11-08 00:13:03
Example:
    % file normalize [file join //host/former ../latter/.$tcl_platform(platform)]
    //host/former/latter/.windows
    % file join [file dirname //host/former] latter/.$tcl_platform(platform)
    //host/former/latter/.windows
For windows it doesn't switch samba-share (must basically replace former with latter here), so it simply ignores ".."

Expected (for both cases):

    //host/latter/.windows

PoC, why it is definitely wrong (and deviates from native FS):

    % puts [set p [file join //?/d:/ ../c:/windows]]]\t[file normalize $p]\t[file exists $p]
    //?/d:/../c:/windows]   //?/d:/c:/windows       0
    % exec cmd /c "IF EXIST $p ECHO YES"
    YES
So it looks like Tcl_FSGetTranslatedPath function has also the same issue, because of file exists wrong result (0).
oehharwiki2024-11-08 07:30:35

Great observation, Sebres, as always.

Perhaps remove the spurious "]" from the last example:

% puts [set p [file join //?/d:/ ../c:/windows]]\t[file normalize $p]\t[file exists $p]
//?/d:/../c:/windows	//?/d:/c:/windows	0
% exec cmd /c "IF EXIST $p ECHO YES"
YES

I can confirm on 8.6.

Thank you, Harald

juliannoble2plain2024-11-08 09:11:21
For the first case of an ordinary UNC path - I wouldn't expect it to backtrack beyond the share name either using .. or file dirname.
 
- On my windows system it doesn't in either cmd.exe or powershell.

For the case of Dos device paths:
 //./  //?/  //./UNC/server/share //?/UNC/server share - it seems to natively backtrack as far as you like - so as I see it, that's the part that Tcl behaviour doesn't match.
juliannoble2plain2024-11-08 09:26:34
see also: https://core.tcl-lang.org/tcl/tktview/d8f12171564f57c9ed3c

In particular the //./ syntax isn't fully supported anyway

%file normalize //./c:/windows
//./c:windows

The //?/ syntax happens to work in this case - but it has other issues as shown in the above ticket.

%file normalize //?/c:/windows
//?/c:/windows
pooryorickwiki2024-11-08 12:01:00

I believe the current behaviour is the correct before. ".." is a synonym for "the parent directory", and the parent directory of the root directory is the root directory.

juliannoble2plain2024-11-08 12:58:55
>I believe the current behaviour is the correct before. ".." is a synonym for "the parent directory", and the parent directory of the root directory is the root directory.

Yes... or in Microsofts terminology - the server and share make up the 'volume' which can't be navigated beyond.
ie the following is correct
  % file dirname //server/share
  //server share

//server/share/etc is an ordinary UNC path with volume //server/share/
//?/UNC/server/share/etc is a device UNC path with volume //?/UNC/server/share/ 

//?/c:/ is a dos device path with volume //?/c:/

(where technically forwardslashes are backslashes)

As an added microsoft twist - the windows API documentation suggests that you can't navigate beyond the volume - but it seems that cmd.exe and powershell may process ".." segments before passing to the API - so some commandline tests can be misleading.  Presumably it's the API behaviour we want to be consistent with.
juliannoble2plain2024-11-08 13:00:25
 correction:
 % file dirname //server/share
  //server/share
jan.nijtmanswiki2024-11-11 11:58:10

There is special processing for this case:

https://core.tcl-lang.org/tcl/file?name=generic/tclPathObj.c&ci=95b4578597ed8b7a&ln=179-187

Which means that in the case of UNC paths, the first two components cannot be separated.

Conclusion: This is expected behavior.

jan.nijtmans Closed ticket [cc1fabcb10]. [History diff]2024-11-13 21:58:42
Log in (anonymous is fine) to add a comment.