Introduce safe_ensure_dirs as a safe os.makedirs replacement.

It only uses os.makedirs call, which is more atomic than calling 2 proc calls. Thus exception due to already existent directory should not longer occur.