Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-21
10:03 • Closed ticket [3023017fff]: win32 file isdirectory <dir>/* broken. plu... artifact: 6d41ebe510 user: serhiy.storchaka
2013-03-19
21:25 • Ticket [3608360fff] Incompatible behaviour of "file exists" status... artifact: eca9f6cbc9 user: nijtmans
21:24 • Closed ticket [3608360fff]. artifact: 707799535f user: nijtmans
18:50 • Ticket [3608360fff]: 4 changes artifact: 4ac98bad95 user: dkf
18:00 • Open ticket [3608360fff]. artifact: 068d1b1c37 user: dkf
2013-03-18
21:42 • Pending ticket [3608360fff]. artifact: 66a6400494 user: dkf
21:40 • Open ticket [3608360fff]. artifact: 877e038cf2 user: dkf
21:39 • Ticket [3608360fff]: 4 changes artifact: cb7dbf23f2 user: nijtmans
21:39 • Closed ticket [3608360fff]. artifact: e6aad0460d user: nijtmans
21:03 • Ticket [3608360fff]: 4 changes artifact: 3a46b75e97 user: nijtmans
20:44 • Open ticket [3608360fff]. artifact: 0cfb7af501 user: dkf
20:13 • Ticket [3608360fff]: 5 changes artifact: 234ba44deb user: nijtmans
20:03 • Closed ticket [3608360fff]. artifact: 97424aa77b user: nijtmans
20:03 • Pending ticket [3608360fff]. artifact: 8c5284e08a user: nijtmans
17:55 • Ticket [3608360fff]: 4 changes artifact: 71ae5cc672 user: nijtmans
16:59 • Ticket [3608360fff]: 6 changes artifact: ecdf3d23e5 user: dkf
08:28 • New ticket [3608360fff]. artifact: c52d2e6c92 user: schmitzu

Incompatible behaviour of "file exists"

Closed / Fixed3608360fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-03-18 08:28:19
There is an incompatibilty concerning "file exists"
in 8.6:

% puts $tcl_patchLevel
8.6.0
% glob *
x.tcl
% file exists *.tcl
1

Whereas in 8.5:
% puts $tcl_patchLevel
8.5.12
% glob *
x.tcl
% file exists *.tcl
0

platform: Win7_x64,
tcl-binaries: ActiveState.

This breaks backward compatibility.
dkfplain2013-03-18 16:59:07
Definitely a problem in implementation of NativeAccess() in tclWinFile.c (the generic layers over that do the right thing) but I really don't know the relevant API. Is this related to 2893771?  (Committed on 2009-11-24 in https://core.tcl.tk/tcl/info/02224b9ef68c so it fits with being an 8.6.* issue.) We're feeding a filename into FindFirstFile which is the directory entry enumerator, which in turn is the only thing that can do that sort of thing with a glob patter AIUI. My knowledge of the deep ins-and-outs of Win32 is too small for me to go further.

Assigning to someone who knows more about the relevant bits than me. Perhaps just testing for glob metacharacters in the name would be enough? I vaguely remember them as being always forbidden in filenames...
nijtmansplain2013-03-18 17:55:09
I will have a look. Thanks!
nijtmansplain2013-03-18 20:03:27
On UNIX (actually Cygwin):
$ tclsh8.5
% puts $tcl_patchLevel
8.5.13
% glob *.tcl
x.tcl
% file exists *.tcl
0

$ tclsh8.6
% puts $tcl_patchLevel
8.6.0
% glob *.tcl
x.tcl
% file exists *.tcl
0
% exit


Conclusion: the fact that using the '*' character this way
in [file exists] worked at all in win32 was an undocumented
feature and is non-portable. On UNIX, the '*' character can be
used in filenames like any other character, only it must be
escaped if the filename goes through a shell.
nijtmans Closed ticket [3608360fff]. [History diff]2013-03-18 20:03:45
nijtmansplain2013-03-18 20:13:17
Apparently, the fix is already backported to 8.4 and 8.5 as well:
======================================
>tclsh84
% puts $tcl_patchLevel
8.4.19
% glob *.tcl
x.tcl
% file exists *.tcl
0
% exit
>tclsh85
% puts $tcl_patchLevel
8.5.13
% glob *.tcl
x.tcl
% file exists *.tcl
0
% exit
dkfplain2013-03-18 20:44:46
I think you're misreading. This is (supposedly) a regression in 8.6 whereby, if 'x.tcl' exists in the current directory (but '*.tcl' does not), [file exists *.tcl] returns 1.

If there's a problem, it exists in that NativeAccess function. (I cannot confirm or deny; I don't have the right platform. I also don't know if the Cygwin build uses the same code; if not, it doesn't count.) I suspect that if there is a problem, it is inside there and related to the use of an API that does expansion. FindFirstFile is such a function, and it is definitely used in the NativeAccess code; the commit I indicated appears to be the one that introduced it. FindFirstFile is documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx

Moreover, I've confirmed that * is an illegal character in a filename on Windows. Search for "reserved characters" in http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

At the very least, we could have a test for this! In fact, I'll write one. [file exists] definitely shouldn't ever do wildcard expansion behind the scenes on any platform.
nijtmansplain2013-03-18 21:03:13
> I think you're misreading. This is (supposedly) a regression in 8.6
> whereby, if 'x.tcl' exists in the current directory (but '*.tcl' does not),
> [file exists *.tcl] returns 1.
If it's a regression, then it's a regression in 8.5.13 as well, because
I cannot reproduce it any more. But I think we fully agree.
> At the very least, we could have a test for this! In fact, I'll write one.
> [file exists] definitely shouldn't ever do wildcard expansion behind the
> scenes on any platform.
I fully agree with that: [file exists] shouldn't do wildcard expansion
on any platform! That means: this change was not a regression,
it was a bug-fix. I welcome your testcase!
nijtmansplain2013-03-18 21:39:18
allow_comments - 1

Thanks, Donal, for your test-case! I tried it on win32 too, and it works fine.

Closing now.
nijtmansplain2013-03-18 21:39:29
allow_comments - 0
dkfplain2013-03-18 21:40:44
Test committed. If that fails on Windows with a non-Cygwin build, we know there's a serious problem. (I suspect this is all caused by the fact that you can't do an access()-equivalent check on a file easily without running into problems with locking. Which seems supremely stupid.)
dkf Pending ticket [3608360fff]. [History diff]2013-03-18 21:42:23
dkfplain2013-03-19 18:00:55
Uwe reports on comp.lang.tcl in message <[email protected]> that:


here my result with cmdAH.test from trunk
(ActiveState tcl8.6 binaries under win7_x64 as before):

>tclsh cmdAH.test


==== cmdAH-19.12 Bug 3608360: [file exists] mustn't do globbing FAILED
==== Contents of test case:

     list [file exists foo.bar] [file exists *.bar]

---- Result was:
1 1
---- Result should have been (exact matching):
1 0
==== cmdAH-19.12 FAILED

cmdAH.test:     Total   308     Passed  132     Skipped 175     Failed  1
Number of tests skipped for each constraint:
         4       nonPortable
         1       tempNotWin
         3       testchmod
         146     testsetplatform
         1       testvolumetype
         20      unix

-----
Summary: it's a real bug in that configuration.
dkfplain2013-03-19 18:50:18
See bug-3608360 for a possible fix. (Warning: untested!)
nijtmansplain2013-03-19 21:24:15
allow_comments - 1

Fixed now in all branches.
nijtmansplain2013-03-19 21:25:47
>Fixed now in all branches.
I mean  on trunk, of course. core-8-5-branch and earlier never had the bug.
Log in (anonymous is fine) to add a comment.