diff --git a/client/text_rescue.py b/client/text_rescue.py index 5439df576..89b3424e9 100644 --- a/client/text_rescue.py +++ b/client/text_rescue.py @@ -780,11 +780,14 @@ def _database_check(entropy_client): ) return -1 + valid = True try: - valid = True entropy_client.installed_repository().validate() - except SystemDatabaseError: + entropy_client.installed_repository().integrity_check() + except SystemDatabaseError as err: + print_error(repr(err)) valid = False + if valid: client_repository_sanity_check() else: diff --git a/libraries/entropy/db/__init__.py b/libraries/entropy/db/__init__.py index 344527433..69f2b86f0 100644 --- a/libraries/entropy/db/__init__.py +++ b/libraries/entropy/db/__init__.py @@ -42,7 +42,7 @@ from entropy.const import etpConst, const_setup_file, \ from entropy.exceptions import SystemDatabaseError, \ OperationNotPermitted, RepositoryPluginError, SPMError from entropy.output import brown, bold, red, blue, purple, darkred, darkgreen -from entropy.cache import EntropyCacher, MtimePingus +from entropy.cache import EntropyCacher from entropy.spm.plugins.factory import get_default_instance as get_spm from entropy.db.exceptions import IntegrityError, Error, OperationalError, \ DatabaseError @@ -4856,6 +4856,19 @@ class EntropyRepository(EntropyRepositoryBase): self._setSetting("schema_revision", str(EntropyRepository._SCHEMA_REVISION)) + def integrity_check(self): + """ + Reimplemented from EntropyRepositoryBase. + """ + cur = self._cursor().execute("PRAGMA quick_check(1)") + try: + check_data = cur.fetchone()[0] + if check_data != "ok": + raise ValueError() + except (IndexError, ValueError, TypeError,): + raise SystemDatabaseError( + "sqlite3 reports database being corrupted") + def validate(self): """ Reimplemented from EntropyRepositoryBase. @@ -4869,48 +4882,10 @@ class EntropyRepository(EntropyRepositoryBase): # avoid python3.x memleak del cached - # use sqlite3 pragma - pingus = MtimePingus() - # since quick_check is slow, run it every 72 hours - action_str = "EntropyRepository.validate(%s)" % (self.name,) - passed = pingus.hours_passed(action_str, 72) - if passed: - # check if mtime is changed ! - sha = hashlib.sha1() - try: # temporary db can cause this - mtime = repr(self.mtime()) - except OSError: - mtime = "0.0" - hash_str = "%s|%s|%s|%s" % ( - repr(self._db_path), - repr(etpConst['systemroot']), - repr(self.name), - mtime, - ) - if sys.hexversion >= 0x3000000: - hash_str = hash_str.encode("utf-8") - cache_key = "_EntropyRepository_validate_" + sha.hexdigest() - cached = self._cacher.pop(cache_key) - if cached is None: - cur = self._cursor().execute("PRAGMA quick_check(1)") - try: - check_data = cur.fetchone()[0] - if check_data != "ok": - raise ValueError() - except (IndexError, ValueError, TypeError,): - mytxt = "sqlite3 reports database being corrupted" - raise SystemDatabaseError(mytxt) - try: - self._cacher.save(cache_key, True) - except IOError: - # race condition, ignore - pass - pingus.ping(action_str) - mytxt = "Repository is corrupted, missing SQL tables!" cur = self._cursor().execute(""" - SELECT count(name) FROM SQLITE_MASTER WHERE type = "table" AND ( - name = "extrainfo" OR name = "baseinfo" OR name = "keywords") + SELECT count(name) FROM SQLITE_MASTER WHERE type = "table" AND + name IN ("extrainfo", "baseinfo", "keywords") """) rslt = cur.fetchone() if rslt is None: diff --git a/libraries/entropy/qa.py b/libraries/entropy/qa.py index 54a2c25f9..a8e6f7436 100644 --- a/libraries/entropy/qa.py +++ b/libraries/entropy/qa.py @@ -1257,6 +1257,7 @@ class QAInterface(TextInterface, EntropyPluginStore): if valid: try: dbc.validate() + dbc.integrity_check() except SystemDatabaseError: valid = False diff --git a/libraries/tests/tools.py b/libraries/tests/tools.py index 0032483ac..38c3da4b0 100644 --- a/libraries/tests/tools.py +++ b/libraries/tests/tools.py @@ -43,6 +43,7 @@ class ToolsTest(unittest.TestCase): self.assertNotEqual(tmp_path, None) dbconn = client.open_generic_repository(tmp_path) dbconn.validate() + dbconn.integrity_check() dbconn.listAllPackageIds() dbconn.close() diff --git a/services/repository-webinstall-generator b/services/repository-webinstall-generator index f863cca57..0752a56d6 100755 --- a/services/repository-webinstall-generator +++ b/services/repository-webinstall-generator @@ -522,6 +522,7 @@ def _generate(args): xcache = True) try: repo.validate() + repo.integrity_check() except SystemDatabaseError: print_error(brown(_("Invalid repository."))) return 1