If you walk a directory tree recursively using the obvious method, you will run into problems with infinite recursion when a symbolic link points to the parent directory.
The obvious solution would be to simply check symbolic links and not follow them at all. But this can be an unpleasant surprise for a user who does not expect behavior for other purposes, such as a perfectly normal directory, to be ignored silently.
An alternative solution would be to save the hash table of all directories visited so far, and use this to check the loops. But this will require some canonical representation, somehow getting the identity, of the directory in which you are looking now (regardless of the path by which you reached it).
Do Unix users usually find the second solution less unexpected?
If so, is there a way to get a canonical representation / directory identifier that is portable across Unix systems? (I would like it to work through Linux, BSD, Mac OS, Solaris, etc. I expect you to write separate code for Windows.)
rwallace
source share