changeset 2400:9a53ed7e5540

stablerangecache: avoid crash when 'cache/' directory is missing If the directory is missing, we create it.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 17 May 2017 18:47:22 +0200
parents 70275407a31e
children 53227fdc83e8
files hgext3rd/evolve/stablerange.py
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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)