FileDirectory>>fileExists: (was: Re: [BUG]Unable to load BFAV,
various problems )
tim at sumeru.stanford.edu
Sat Apr 17 04:40:21 UTC 2004
OK, I'm going to propose a couple of extensions to the FilePlugin. I'm
pretty sure it is possible to wrap them in such a way that older VMs
will be ok and of course old images on a new vm will just work as
I've done a test build of prims to implement primitiveFileExists and
primitiveDirectoryExists. They're essentially identical and it might be
possible to merge them, depending on the various platform constraints.
On RISC OS it would be obvious and trivial but I really don't want to
jump to conclusion about other machines. (Apart from the obvious
truism that they're clearly inferior :-) )
As an example:-
| dirName dirNameIndex dirNameSize okToAccess exists|
"does the named directory exists?"
self var: #dirNameIndex type: 'char *'.
self export: true.
dirName _ interpreterProxy stackValue: 0.
(interpreterProxy isBytes: dirName) ifFalse: [^ interpreterProxy primitiveFail].
dirNameIndex _ interpreterProxy firstIndexableField: dirName.
dirNameSize _ interpreterProxy byteSizeOf: dirName.
"If the security plugin can be loaded, use it to check for permission.
If not, assume it's ok"
sCDPfn ~= 0
ifTrue: [okToAccess _ self cCode: ' ((int (*) (char *, int)) sCLPfn)(dirNameIndex, dirNameSize)'.
okToAccess ifFalse: [^ interpreterProxy primitiveFail]].
"dir_Exists() is implemented as a macro that does interpreterProxy>primitiveFail by default"
exists _ (self cCode: 'dir_Exists((char *) dirNameIndex, dirNameSize)'
ifFalse: [interpreterProxy pop: 1; pushBool: exists].
I would suggest a default macro in sq.h that simply implements
dir_Exists as interpreterProxy->primitiveFail. Unless of course, all the
platformers buy into the idea really quickly and make it pointless.
A further extension I'd like to suggest is a prim to canonicalize
filenames. I certainly have a nice OS call to do that much faster and
much more comprehensively than the current image code (you try
understanding the RISC OS filename rules!) and I think *nix can use
'realpath()' at least for directory names. I'd imagine most OSs would
have something appropriate. Obviously, the backup code would be the
current checkName:fixErros: or similar.
Tim Rowledge, tim at sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Useful random insult:- So dumb, his dog teaches him tricks.
More information about the Squeak-dev