Merge pull request #177 from airwoodix/fix-mkdir-force-leaf-exists

Fix 'force' semantics in 'utils.filesystem.mkdir'
This commit is contained in:
Alexandre Aubin 2018-11-22 22:24:25 +01:00 committed by GitHub
commit c2f02cd14b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -196,7 +196,13 @@ def mkdir(path, mode=0777, parents=False, uid=None, gid=None, force=False):
return return
# Create directory and set permissions # Create directory and set permissions
try:
os.mkdir(path, mode) os.mkdir(path, mode)
except OSError:
# mimic Python3.2+ os.makedirs exist_ok behaviour
if not force or not os.path.isdir(path):
raise
if uid is not None or gid is not None: if uid is not None or gid is not None:
chown(path, uid, gid) chown(path, uid, gid)