Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libearth: Ignore EEXIST during mkdir #36

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions libearth/repository.py
Expand Up @@ -37,6 +37,7 @@

"""
import collections
import errno
import io
import os
import os.path
Expand Down Expand Up @@ -321,7 +322,13 @@ def from_url(cls, url):
def __init__(self, path, mkdir=True, atomic=IRON_PYTHON):
if not os.path.exists(path):
if mkdir:
os.makedirs(path)
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
else:
raise FileNotFoundError(repr(path) + ' does not exist')
if not os.path.isdir(path):
Expand All @@ -347,7 +354,13 @@ def write(self, key, iterable):
for i in xrange(len(dirpath)):
p = os.path.join(*dirpath[:i + 1])
if not os.path.exists(p):
os.mkdir(p)
try:
os.mkdir(p)
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
elif not os.path.isdir(p):
raise RepositoryKeyError(key)
filename = os.path.join(self.path, *key)
Expand Down