Tweak cycle avoidance code in FileSystemEntry.visit and add a unit test