Fix stat/lstat error checking in a few places.

closes #6929. Please review.
@erikh Does the test still fail? (That is, is the build still succeeding?)