calibre-server: Auto-create userdb directory if it does not exist

This commit is contained in:
Kovid Goyal 2017-12-05 14:15:18 +05:30
parent 23fe6dc98b
commit f5962cb392
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -76,7 +76,14 @@ class UserManager(object):
def conn(self): def conn(self):
with self.lock: with self.lock:
if self._conn is None: if self._conn is None:
self._conn = apsw.Connection(self.path) try:
self._conn = apsw.Connection(self.path)
except apsw.CantOpenError:
pdir = os.path.dirname(self.path)
if os.path.isdir(pdir):
raise
os.makedirs(pdir)
self._conn = apsw.Connection(self.path)
with self._conn: with self._conn:
c = self._conn.cursor() c = self._conn.cursor()
uv = next(c.execute('PRAGMA user_version'))[0] uv = next(c.execute('PRAGMA user_version'))[0]