sqInt dir_Lookup(char *pathString, sqInt pathStringLength, sqInt index,
char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate,
sqInt *isDirectory, squeakFileOffsetType *sizeIfFile)
Parms:
pathString squeak object, file name, in encoding according to image choice
pathStringLength length of squeak object
index index number which is 1-N ;
return:
0 if a entry is found at the given index
1 if the directory has fewer than index entries
2 if the given path has bad syntax or does not reach a directory
Pointers return
name 256 bytes, name of entry, encoded according to image choice
nameLength length of name
creationDate creation Date of the file in squeak date form
modificationDate Modification Date of the file in squeak date form
isDirectory 1 if entry is a directory, zero otherwise
sizeIfFile size of file, or zero. In squeakFileOffsetType which resolves to operating system file size typedef
From: Interpreter FilePlugin primitiveDirectoryLookup
Why: Need to get Nth entry of given directory.
Responsibility:
Must return directory entry, on unix it must beware of symbolic links, on os-x it must beware of Finder Aliases.
If the pathString is empty then you return the contents of the current working directory (whatever that means for the platform)
Ensure return values are zero to NULL/0 so that caller does not have bogus values if we return BAD_PATH or NO_MORE_ENTRIES
If the pathString does not encode for the file system then return BAD_PATH
If the directory cannot be opened then return BAD_PATH
Attempt to read the "index" directory entry, if unable then return NO_MORE_ENTRIES.
If we find a directory entry then return the encoded directory name, which is not the resolved symbolic link or alias name
and the length of the encoded name, the creation/modification time in squeak time, and if it is a directory and the size of the file (directories may be zero)
Issues:
If the directory changes during iterations then the result is unknown.
If the code attempts to cache the directory information, it must deal with knowing when to invalidate the cache.
{On a dir_Delete we must ensure the cached directory is invalidated.}
A platform might not have the concept of a working directory
MacIntosh
os-9/OSXCarbon
The macintosh port uses a version of the unix code but is more aware of Finder Aliases.
For example when calculating if the entry is a directory it invokes FSResolveAliasFileWithMountFlags since otherwise
a Finder alias file that points to a directory would show as a file, since it is technically a file.
BUG: unsure if resource fork entries '._foobar' would show in directory listing.
Cocoa:
See iPhone
iPhone
NSUTF8StringEncoding is the only file encoding
we read and cache the directory listing, later lookup of a name may fail. It's unclear what to do
it ignores resource fork entries that start with '._', also '.' and '..'
Bugs: if Finder alias is directory entry, it will not be marked as a directory entry. {NEED TO CONFIRM}
Unix
The unix port has some complicated code to ensure it opens the directory then caches the directory and last index number
on the next read it has to decide if the directory should be closed, reopened, or rewind, then read to the entry, or get
the next entry if it is in fact reading from 1 to N in a loop.
It's unclear if the opendir() give you a read stream on a directory that is not affected by other processes manipulation of the directory?
If the stat AND the lstat fails on the file name, it returns ENTRY_FOUND however the create/modification dates and if directory and size of file are all zero.
Directory entries are returned with file size of zero.
It also skips over '.' and '..' in the directory entries.
Bugs: on OSX if Finder alias is directory entry, it will not be marked as a directory entry.
Windows
The code also caches the directory for faster N+1 usage
UNKNOWN how it handles the case where the path name is empty (aka unix working directory)
BUGS
sqInt *isDirectory, squeakFileOffsetType *sizeIfFile)