By checking the path is already in the list, dead loops caused by symlink to itself can be avoided. (cherry picked from commit 2b993aa7)