|
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
% 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):
So it looks like
% 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
Tcl_FSGetTranslatedPath function has also the same issue, because of file exists wrong result (0).
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
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.
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
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.
>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.
correction: % file dirname //server/share //server/share
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.