Raise an exception when unable to open datastore, instead of returning False
This commit is contained in:
parent
1b9395ca37
commit
57bbca4e7a
@ -29,18 +29,18 @@ class XML(Abstract):
|
|||||||
def open(self):
|
def open(self):
|
||||||
"""Lock the directory"""
|
"""Lock the directory"""
|
||||||
|
|
||||||
if os.path.isdir(self.basedir):
|
if not os.path.isdir(self.basedir):
|
||||||
lock_file = os.path.join(self.basedir, ".used_by_nemubot")
|
os.mkdir(self.basedir)
|
||||||
if not os.path.exists(lock_file):
|
|
||||||
with open(lock_file, 'w') as lf:
|
|
||||||
lf.write(str(os.getpid()))
|
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
lock_file = os.path.join(self.basedir, ".used_by_nemubot")
|
||||||
with open(lock_file, 'r') as lf:
|
if os.path.exists(lock_file):
|
||||||
pid = lf.readline()
|
with open(lock_file, 'r') as lf:
|
||||||
raise Exception("Data dir already locked, by PID %s" % pid)
|
pid = lf.readline()
|
||||||
return False
|
raise Exception("Data dir already locked, by PID %s" % pid)
|
||||||
|
|
||||||
|
with open(lock_file, 'w') as lf:
|
||||||
|
lf.write(str(os.getpid()))
|
||||||
|
return True
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""Release a locked path"""
|
"""Release a locked path"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user