Fix issue with symlink path detection

Fixes #7627
Fixes #7664
Merge pull request #7676 from jimi-c/fix_symlinks

Fix issue with symlink path detection