Avoid /proc
/dev
(sometimes) and /sys
and you'll be fine. /proc
and /sys
definitely have recursions, and I've seen them in /dev
too.
Basically avoid all fake (what's the correct word?) filesystems.
You can't detect this recursion (simply anyway) because as you've seen the path is recursive, it is not like following ..
then going back into a child of the parent, the paths for two different levels in the recursion are DIFFERENT, where as ./A/B/C
and ./A/../A/../A/B/../B/./././C
are technically the same.
BTW why are you scanning these files? They're not real! What use could you have to be scanning them?
Put that in the question please!
Addendum
Run mount
in a terminal and do not touch anything that isn't from a device. That should certainly help. 'cept /dev/pts
.
For example, I could use sshfs
to mount my other laptop's FS to this laptops, and I could mount this laptop's fs within my computers, and my computer's fs to my other laptops, now if I scan without caution recursion across 3 computers!