adobe/brackets — pull request #5943 by iwehrman (2013-11-11 22:08:47+00:00)
Title: [REVIEW ONLY] Avoid symbolic link cycles

This pull request adds symbolic link cycle avoidance to `FileSystemEntry.visit`. It does this by declining to follow symbolic links in subdirectories with the same real path more than once. This ensures that calls to `visit` on directories that form part of a symbolic link cycle always converge.

**Note 1:** Because this change does not affect the results of `Directory.getContents`, it is still possible to recurse into symbolic link cycles indefinitely. For example, this change does not affect manual expansion of link cycles in the file tree. Furthermore, code that naively traverses directory structures can still diverge! The only example I could find in the Brackets source that performs such a naive traversal is the JS code hinter. Pull request #5917 replaces these ad hoc traversals with calls to `visit`, which solves the problem.

**Note 2:** The `visit` method could also have been modified such that the object itself is not visited if its real path has previously been visited instead of performing this check on the children of Directory objects. This would have a somewhat cleaner implementation, but would require an additional `stat` call. Because Brackets is sensitive to the performance of the `visit` method, I opted against the slightly cleaner implementation in favor of a slightly more performant one.

**Note 3:** For this change to have any effect, a change is required in the behavior of `FileSystemImpl.stat` such that when applied to a symbolic link, the returned `FileSystemStats` object should have an additional property, `realPath`, which evaluates to the canonical path of the target of the link. The `size`, `mtime`, `isFile` and `isDirectory` properties must still describe the target of the link, not the link itself. (Do not confuse the semantics of this function with the semantics of POSIX `lstat`, for example.) For non-links, the behavior of `stat` is unchanged.

**Note 4:** *This change has not yet been made to `AppShellFileSystemImpl` and the Brackets shell.* Merging this change before the corresponding shell changes have landed won't make anything worse, but, still, this code should be considered for-review-only. In the meantime, it can be tested using the [Node filesystem branch](https://github.com/adobe/brackets/tree/iwehrman/nodefs), which makes use of the `NodeFileSystemImpl` for which the [semantics of stat have already been updated](https://github.com/iwehrman/brackets-node-filesystem/blob/master/node/NodeFileSystemDomain.js#L45).