When dealing with folderitems, there’s one case where one can get unexpected errors; that’s with a symbolic link.
I’m experiencing this right now:
item as FolderItem is a symbolic link for which the original item is a folder.
item.Directory and item.IsFolder both return false, so my code naturally tries to read the file as a binary stream, thinking it’s a file. This raises an IOException with code 21 (found a folder instead of a file).
However, the relevant folderitem properties don’t help figuring out if item is a symbolic link. Here are the values for item:
Alias/IsAlias=true: with a true alias, one can still read its content, including the resource fork if the original item is stored there, so it doesn’t withdraw reading item as a file
Directory/IsDirectory=false: I’d be tempted to be allowed to read something that is not a folder if I can’t know it’s a symbolic link otherwise
IsReadable=True/IsWriteable=False: fine for reading, no problem.
Length=26: if the item has a length, it contains data (this is the actual path to the original item, but is still data)! Why on earth would a specific item with proper permissions and having content not be readable?
Name=Resources: no extension identifies a symbolic link; same principle for paths
Actually, the MacType could be used to identify a symbolic link (it’s slnk), but Xojo removed MacType and MacCreator; I knew those 2 properties were still useful (so, please, add them back)
Other built-in properties are irrelevant here.
I’m sure there’s a terminal command to tell whether an item is a symbolic link; I’ve not searched, but it’s obvious. That’s not my point. When iterating thru several items, invoking a shell multiplies needed time.
This is a 2 parts problem:
1: we can’t easily know in Xojo if an item is a symbolic link, other than invoking a shell (it seems)
2: Xojo’s folderitem refers to the link (length=26, alias=true, etc.) while once you try to read with a binary stream, it tries to read the original item (which becomes a folder, invalid for reading).
Am I missing the obvious?