|
2026-05-31
| ||
| 16:18 | • Ticket [7eb6b3a53f] glob on UNC path requires additional slash status still ... artifact: 4fdeb7f7c1 user: oehhar | |
| 04:40 | • Ticket [7eb6b3a53f]: 3 changes artifact: 800650d7b7 user: apnadkarni | |
|
2026-05-29
| ||
| 13:12 | • Ticket [7eb6b3a53f]: 4 changes artifact: 0a3291c44f user: apnadkarni | |
| 12:34 | • Ticket [7eb6b3a53f]: 3 changes artifact: d1c86832b4 user: anonymous | |
| 12:26 | • Ticket [7eb6b3a53f]: 3 changes artifact: 4b595d9b0d user: anonymous | |
| 11:54 | • Ticket [7eb6b3a53f]: 3 changes artifact: fdbf6ce568 user: apnadkarni | |
| 08:43 | • Ticket [7eb6b3a53f]: 4 changes artifact: 3a9afccfa0 user: oehhar | |
| 07:48 | • New ticket [7eb6b3a53f]. artifact: 29a3301caa user: anonymous | |
glob on UNC path requires additional slash
Glob on windows unc path sometimes works incorrectly:
% llength [glob //?/C:/WINDOWS/*]
112
% llength [glob {\\?\C:\WINDOWS\*}]
no files matched glob pattern "\\?\C:\WINDOWS\*"
% llength [glob "\\\\?\\C:\\WINDOWS\\*"]
no files matched glob pattern "\\?\C:\WINDOWS\*"
With additional slash:
% llength [glob {\\?\C:\WINDOWS\\*}]
112
% llength [glob "\\\\?\\C:\\WINDOWS\\\\*"]
112
(latest tcl 9.1 from repo on windows 10)
This behavior seems inconsistent.
Bug confirmed. Great catch! Harald
That is not a UNC path. As far as I can see, UNC paths work correctly.
% llength [glob //IO/src/*]
124
% llength [glob {\\IO\src\*}]
124
% llength [glob "\\\\IO\\src\\*"]
124
The \\?\ notation follows different syntax rules and semantics. For example, C:\foo\..\bar and \\?\C:\foo\..\bar are different paths as are C:\foo/bar and \\?\C:\foo/bar, or C:\foo\bar. and \\?\C:\foo\bar.
Tcl does not really support the \\?\ syntax. There are some hacks (sorry, but they really are hacks) within Tcl that attempt to deal with this in piecemeal fashion. They lead you to believe that syntax is supported but it isn't. Moreover, in my opinion this is actually not fixable because not even all Win32 API's that Tcl uses understand the syntax.
See bc7925fc50 for other cases.
Same behaviour on network path:
% llength [glob {\\srv\share\tmp\\*}]
132
% llength [glob {\\srv\share\tmp\*}]
no files matched glob pattern "\\srv\share\tmp\*"
I'm using native windows shares from windows domain
Hmm, works great in the top directory
% llength [glob {\\srv\share\\*}]
31
% llength [glob {\\srv\share\*}]
31
Indubitably a bug then :-) Also present in 8.6
Reversing myself yet again, I think works as designed, confusing as it might be.
When globbing a component like Windows\*, the glob syntax will treat \ as escaping the following character, the *. So it is looking actually looking for the string Windows* (i.e. * is a literal character in the pattern, not a wildcard) which fails. The additional \ is needed to escape the \.
The confusing part is why the \ in the UNC leading part does not need to be doubled. Tcl parses the path into a filesystem component and a pattern. The driver for the owning filesystem is then passed the pattern.
The filesystem component itself is not treated as a pattern. In the following:
glob {\\io\src\tcl-cffi\*}
The file system component is parsed as \\io\src\. The pattern is tcl-cffi\*. The asterisk then treated not as a wildcard but an escaped literal character and no file names are returned.
The reason top level wildcards as in \\io\src\* work is that again the file system component is \\io\src\ and the pattern is simply * (unescaped).
The same issue arises with simple drive paths as well, only even more confusing :-) because of the potential for drive-relative paths. The path C:/* is treated as file system C:/ and pattern *. Is the path C:\* to be treated likewise or as a volume relative path with file system C: and an escaped \* literal asterisk? It appears the latter option is chosen so glob {C:\*} will return no files.
I'm not sure there is a satisfactory solution to all this due to the inherent ambiguities. All I can suggest is to use Tcl canonical (forward slash) patterns as far as possible.
Above analysis is not authoritative :-) so leaving ticket open.
At least this is reasonable, thanks Ashok for looking into this.
Perhaps we can add something to the documentation:
Native Windows path ({C:\test}) may only be used for the -directory and -path options. The glob pattern argument should use the forward slash as separator for unique results. Background is the ambiguity of the backslash character, which may escape a glob character ("\*" to specify a literal "*" character). So, for "glob {C:\test\*}", it is not clear, if the last backslash is a path separator or an escaped glob character.
Take care, Harald