[BUG] FileDIrectory>isAFileNamed: considered vile

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Aug 4 00:52:04 UTC 2003


Tim Rowledge <tim at sumeru.stanford.edu> wrote:
	I mean yuck. Blech.
	
	Testing for the existence of a file by trying to open it?  OK,
	if one is utterly restricted to only the support guaranteed in a
	an ansi library maybe we can make an excuse.
	
When I worked on the Quintus Prolog library I faced exactly this question.
The answer turned out to be "distinguish and conquer".
There are several *different* questions:

(1) Does such-and-such a file exist?
    (Answers: yes, no, not allowed to tell you.)
(2) Should I create such-and-such a file because it doesn't exist?
    (Answers: yes, no, not allowed to tell you, it doesn't exist
     but you are not allowed to create it.)
(3) Would I be allowed to read such-and-such a file?
    (Answers: yes, no.)
(4) If I tried to open such-and-such a file for input, would that work?
    (Answers: yes, no, can't tell for sure.)
(5) When I try to open such-and-such a file for input, will that work?

Given the range of operating systems we were trying to support (several
flavours of UNIX, IBM MVS, IBM CMS, DEC VMS, Xerox Interlisp-D) there
was in fact *no* portable method (Xerox Lisp machines didn't run C).
But in all cases, even using undocumented interfaces, the only way to
answer question (4) was to actually *try* to open the file.

Of course, the question people were generally interested in was really
(5), and we never could figure out a way to answer that question, even
if question (4) was answered "yes".  (Because another process might
remove, rename, or change the protection on the file or one of its
ancestral directories, or remove/dismount a (virtual) disc.)

All the cases we were aware of where people asked question (1), they
were tacitly assuming that the only answers were yes and no.  They aren't.

We did provide (1), (3), and (4); each required different code.



More information about the Squeak-dev mailing list