add utils.path.ensure_dir_exists

Ensures that a directory exists,
and protects against a common race condition when multiple
processes try to create the same directory.
better error message when path exists but is not dir
change default dir permissions to 755

777 is a weird default
test ensure_dir_exists
Merge pull request #5739 from minrk/ipython-dir-race

add utils.path.ensure_dir_exists