utils: Teach mkdir_p to fail if the existing target isn't a directory

Existing symlinks to directories will still pass, because isdir()
follows symbolic links.
Merge pull request #664 from wking/mkdir-p-nondir-error

utils: Teach mkdir_p to fail if the existing target isn't a directory