# HG changeset patch # User Pierre-Yves David # Date 1495039642 -7200 # Node ID 9a53ed7e55405561e753560c03e36797fa339316 # Parent 70275407a31e1db80a29122669df6973cd979c0b stablerangecache: avoid crash when 'cache/' directory is missing If the directory is missing, we create it. diff --git a/hgext3rd/evolve/stablerange.py b/hgext3rd/evolve/stablerange.py --- a/hgext3rd/evolve/stablerange.py +++ b/hgext3rd/evolve/stablerange.py @@ -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)