Make change suggested by Greg in review.

This add a check to see if we need to create a parent directory and returns
the first error we find that is either mkdir generated, or found by stat but not
a "file or directory does not exist".
A comment was out of date.
Merge pull request #402 from lydia-duncan/mkdir

Take Greg's comment on mkdir into account [reviewed by gbtitus]

This adds a check to see if we need to create a parent directory and returns
the first error we find that is either mkdir generated, or found by stat but not
a "file or directory does not exist" error (which we would've solved by calling
mkdir afterwards).