# HG changeset patch # User Jun Wu # Date 1502468669 25200 # Node ID 09476d758b5910b4b507c3eb46b9480102253eda # Parent b3e41b0d50a2fefdfea1d465016699cfdcf04dcc maps: handle sqlite lock error triggered by PRAGMA statements "self._db.execute('PRAGMA cache_size=%d' % (-cachesize))" could raise "OperationalError: database is locked". Therefore move PRAGMA statements inside "self._transaction" which handles the "locked" error automatically. diff --git a/hgsubversion/maps.py b/hgsubversion/maps.py --- a/hgsubversion/maps.py +++ b/hgsubversion/maps.py @@ -726,18 +726,19 @@ class SqliteRevMap(collections.MutableMa for path, ratio in [(self._filepath, 1.7), (self._dbpath, 1)]: if os.path.exists(path): cachesize += os.stat(path).st_size * ratio // 1000 - self._db.execute('PRAGMA cache_size=%d' % (-cachesize)) - - # PRAGMA statements provided by the user - for pragma in (self._sqlitepragmas or []): - # drop malicious ones - if re.match(r'\A\w+=\w+\Z', pragma): - self._db.execute('PRAGMA %s' % pragma) # disable auto-commit. everything is inside a transaction self._db.isolation_level = 'DEFERRED' with self._transaction('EXCLUSIVE'): + self._db.execute('PRAGMA cache_size=%d' % (-cachesize)) + + # PRAGMA statements provided by the user + for pragma in (self._sqlitepragmas or []): + # drop malicious ones + if re.match(r'\A\w+=\w+\Z', pragma): + self._db.execute('PRAGMA %s' % pragma) + map(self._db.execute, self.TABLESCHEMA) if version == RevMap.VERSION: self.rowcount = 0