Solving the DIR? problem.
I need your ideas on how best to solve the DIR? problem (bug #602).
The problem simply stated: if you specify a file name (or path) how do we determine if it is a directory.
The current algorithm is:
- Check if the name ends with "/" - if so, it refers to a directory.
- If it does not end with "/", check if the file exists, and if so, determine if it is a file or directory.
So, the algorithm mixes both the lexical check of the filename with the actual check of the local file.
There are two main problems with this:
- If the file name ends with "/", we just assume that it is a directory reference. However, locally a file of that name (without the /) may be present.
- It would be nice if the mechanism worked for URL's as well. So, when processing something like an HTTP request, we can use DIR? along the way. This is problematic if we check local storage, which in many cases is unrelated to the URL itself.
Although it would be nice to believe that there is a simple solution here, the compound behavior of the current DIR? function might cause more confusion than it's worth.
However, it would be nice to have a way to easily check file and URL paths. I often write:
if #"/" = last file-path [...]
and I'd prefer to write something a lot more clear, perhaps:
if dir-name? file-path [...]
or:
if is-dir? file-path [...]
Please let me know your comments soon. I realize it's still summer vacation, but dust that sand off your keyboard and post a comment.
16 Comments
|