Improve fix for #2359
More improvements for #2359
Fix again for #2359
Yet another fix for #2359
Merge pull request #2724 from eliangidoni/fix-2359

Improve fix for #2359 (don't rely on . and .. existing in every directory)