stablerangecache: avoid crash when 'cache/' directory is missing
If the directory is missing, we create it.
--- a/hgext3rd/evolve/stablerange.py Wed May 17 18:40:48 2017 +0200
+++ b/hgext3rd/evolve/stablerange.py Wed May 17 18:47:22 2017 +0200
@@ -719,6 +719,7 @@
def __init__(self, repo):
super(sqlstablerange, self).__init__()
+ self._vfs = repo.vfs
self._path = repo.vfs.join('cache/evoext_stablerange_v0.sqlite')
self._cl = repo.unfiltered().changelog # (okay to keep an old one)
self._ondisktiprev = None
@@ -782,10 +783,20 @@
self._loaddepth()
return super(sqlstablerange, self)._inheritancepoint(*args, **kwargs)
+ def _db(self):
+ try:
+ util.makedirs(self._vfs.dirname(self._path))
+ except OSError:
+ return None
+ con = sqlite3.connect(self._path)
+ con.text_factory = str
+ return con
+
@util.propertycache
def _con(self):
- con = sqlite3.connect(self._path)
- con.text_factory = str
+ con = self._db()
+ if con is None:
+ return None
cur = con.execute(_queryexist)
if cur.fetchone() is None:
return None
@@ -815,8 +826,9 @@
if '_con' in vars(self):
del self._con
- con = sqlite3.connect(self._path)
- con.text_factory = str
+ con = self._db()
+ if con is None:
+ return
with con:
for req in _sqliteschema:
con.execute(req)