Fix stat/lstat error checking in a few places.

closes #6929. Please review.