Tcl Source Code

View Ticket
Login
Ticket UUID: 1084705
Title: glob -nocomplain swallows all errors.
Type: Bug Version: obsolete: 8.5a4
Submitter: jcw Created on: 2004-12-13 21:53:36
Subsystem: 37. File System Assigned To: vincentdarley
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2006-03-23 18:36:31
Resolution: Fixed Closed By: vincentdarley
    Closed on: 2006-03-19 23:07:51
Description:
(This may be a TclVFS issue, but I'm not sure)

Am writing a VFS driver in Tcl, which needs to throw errors 
(EACCESS) for certain calls to "glob" from Tcl.  The 
"matchindirectory" handles glob, but I cannot make it generate 
errors which get thrown back to the caller of glob.

A TclVFS driver with the following definition in it returns an empty 
list for glob, instead of throwing an error:

     proc matchindirectory {conn path actualpath pattern type} {
         error bah!
     }

A related detail perhaps is mentioned on the wiki at the end of page 
http://mini.net/tcl/12328 - it does not apply to matchindirectory, 
which according to the docs does not use posixerror, but I'll include 
it for completeness:

    % vfs::filesystem posixerror 13
    command returned bad code: -1
    %

My test environment was a couple of different 8.4.9 and 8.5a2 
builds on Mac OS X (tclsh's, wish's, and tclkit's).  None return an 
error from glob.

-jcw
User Comments: jcw added on 2006-03-23 18:36:31:
Logged In: YES 
user_id=1983

To what extent are 8.4 and 8.5 branches different w.r.t. VFS?
And perhaps 2nd Q: why?

I know there are init/encoding differences, but apart from that I've been able 
to keep 8.4/8.5 builds of Tclkit pretty much the same.

And while we're at it: how about making the VFS subsystem more loosely 
coupled?  If the native fs were optional, one could create a secure sandbox 
(by having only support for an end-of-exe VFS with runtime & starpack files).  
And more to the point: more code might be shareable between 8.4 and 8.5.

dkf added on 2006-03-23 17:20:18:
Logged In: YES 
user_id=79902

IIRC, the code I cleaned out was something of a cesspit, in
that it was complicated and very hard to analyse for
correctness. Given that, backporting is a real chore (and I
can't be bothered :-p ).

vincentdarley added on 2006-03-23 16:56:56:
Logged In: YES 
user_id=32170

The code cleanup that I think dkf applied to tclFileName.c a
couple of years ago would need applying to 8.4 before these
changes could be used in 8.4.  So I don't have any current
plans to do that.

dgp added on 2006-03-22 21:11:13:
Logged In: YES 
user_id=80530


any plan to backport the
fix for 8.4.13 ?

vincentdarley added on 2006-03-20 02:16:53:

File Added - 171484: globnoc.diff

vincentdarley added on 2006-03-20 02:16:52:
Logged In: YES 
user_id=32170

Attached is a patch to implement this - given the newer
'glob' code this is actually a decent simplification.  We
should clarify the documentation, of course.

vincentdarley added on 2004-12-15 02:16:15:
Logged In: YES 
user_id=32170

Updated summary line.  You're probably right that this
doesn't need a TIP -- I also think part of the historical
motivation for it was that the code used to be structured so
this was very difficult to achieve.  That's no longer true,
I think.

jcw added on 2004-12-14 23:31:53:
Logged In: YES 
user_id=1983

It would have, indeed.  I apologize for not detecting the difference (I 
always use -nocomplain).

Do we really need a TIP?  The docs do not mention eating errors in glob: 
http://www.tcl.tk/man/tcl8.4/TclCmd/glob.htm#M7

I can of course set a global flag in the driver, and check it at the call site, 
but the current behavior sure took me by surprise.

-jcw

vincentdarley added on 2004-12-14 23:21:08:
Logged In: YES 
user_id=32170

It would've been helpful if you had mentioned that
-nocomplain was  used in the original report!

Tcl's glob has always discarded all errors when using
'-nocomplain'.  Hence you are asking for a changed behaviour
in Tcl.

I think the reason for this behaviour is probably that glob
takes multiple pattern arguments:

glob -nocomplain a* b* ~asdasd

is supposed to concatenate the lists for each pattern in
turn.  Hence -nocomplain's behaviour of ignoring all errors
(else an error in one pattern would mess up a different one).

I don't necessarily agree that this is good, but Tcl has
always done this. In fact I'd be keen to change this
behaviour, but am not sure it is possible without a TIP.

Vince.

jcw added on 2004-12-14 23:06:44:
Logged In: YES 
user_id=1983

Attached a test file errvfs.tcl, which is testvfs.tcl but edited to always 
throw an error in matchindirectory.

Here's the output from this script:

OK: { glob D* } result {Desktop Documents}
OK: { glob -nocomplain D* } result {Desktop Documents}
ERROR: { glob blah* } -> code 1 msg {no files matched glob pattern 
"blah*"}
OK: { glob -nocomplain blah* } result {}
ERROR: { glob root/blah* } -> code 1 msg BOOM!
OK: { glob -nocomplain root/blah* } result {}

The last case explains the problem I ran into: -nocomplain loses all errors, 
not just from returning no match.

vincentdarley added on 2004-12-14 20:58:52:
Logged In: YES 
user_id=32170

Can you please attach the vfs driver and instructions for
reproducing the bug (i.e. a test case of some kind).

Attachments: