Skip to content

Commit 5a7b8a9

Browse files
Mkdir non-recursive if recursive mkdir fails
1 parent 93af5d6 commit 5a7b8a9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mongodb_consistent_backup/State.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from time import time
77

88
from mongodb_consistent_backup.Common import Lock
9+
from mongodb_consistent_backup.Errors import OperationError
910

1011

1112
class StateBase(object):
@@ -22,7 +23,14 @@ def __init__(self, base_dir, config, filename="meta.bson", state_version=1, meta
2223
self.lock = Lock(self.state_lock, False)
2324

2425
if not os.path.isdir(self.state_dir):
25-
os.makedirs(self.state_dir)
26+
# try recursive first, fallback to regular mkdir
27+
try:
28+
os.makedirs(self.state_dir)
29+
except:
30+
try:
31+
os.mkdir(self.state_dir)
32+
except Exception, e:
33+
raise OperationError(e)
2634

2735
def merge(self, new, old):
2836
merged = old.copy()

0 commit comments

Comments
 (0)