From d7ddf15fac6a9acac3e385067604774c04cb809a Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Thu, 2 Jul 2026 00:04:31 +0200 Subject: [PATCH] rescue spmsync: fix handlePackage failure when installed DB is missing Two fixes for `equo rescue spmsync` on a system without an existing installed packages DB: 1. client/interfaces/methods.py: Stop falling back to a GenericRepository (in-memory, read-only for handlePackage) when the DB file is absent. Instead let SQLite create the file; call initializeRepository() on a freshly created DB so validate() succeeds. Corrupted DBs still fall back to RAM via the existing DatabaseError/SystemDatabaseError path. 2. spm/portage_plugin: Also catch OSError (not just tarfile.ReadError) when uncompress_tarball fails on a pure-XPAK temp file; Python 3.14 raises OSError in this case rather than tarfile.ReadError. Co-Authored-By: Claude Sonnet 4.6 --- lib/entropy/client/interfaces/methods.py | 52 +++++++++---------- .../interfaces/portage_plugin/__init__.py | 2 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/lib/entropy/client/interfaces/methods.py b/lib/entropy/client/interfaces/methods.py index dec4510d1..8d649b277 100644 --- a/lib/entropy/client/interfaces/methods.py +++ b/lib/entropy/client/interfaces/methods.py @@ -1085,36 +1085,34 @@ class RepositoryMixin: os.makedirs(db_dir) db_path = repo_path - if (self._installed_repo_enable) and (not os.path.isfile(db_path)): - conn = load_db_from_ram() + db_file_is_new = not os.path.isfile(db_path) + try: + repo_class = self.get_repository(name) + conn = repo_class(readOnly = False, + dbFile = db_path, + xcache = self.xcache, + indexing = self._indexing) + conn.setCloseToken(name) + self._add_plugin_to_client_repository(conn) + if db_file_is_new: + conn.initializeRepository() + # TODO: remove this in future, drop useless data from clientdb + except (DatabaseError,): entropy.tools.print_traceback(f = self.logger) + conn = load_db_from_ram() + else: - - try: - repo_class = self.get_repository(name) - conn = repo_class(readOnly = False, - dbFile = db_path, - xcache = self.xcache, - indexing = self._indexing) - conn.setCloseToken(name) - self._add_plugin_to_client_repository(conn) - # TODO: remove this in future, drop useless data from clientdb - except (DatabaseError,): - entropy.tools.print_traceback(f = self.logger) - conn = load_db_from_ram() - - else: - # validate database - if self._installed_repo_enable: + # validate database + if self._installed_repo_enable: + try: + conn.validate() + except SystemDatabaseError: try: - conn.validate() - except SystemDatabaseError: - try: - conn.close(_token = name) - except (RepositoryPluginError, OSError, IOError): - pass - entropy.tools.print_traceback(f = self.logger) - conn = load_db_from_ram() + conn.close(_token = name) + except (RepositoryPluginError, OSError, IOError): + pass + entropy.tools.print_traceback(f = self.logger) + conn = load_db_from_ram() self._real_installed_repository = conn return conn diff --git a/lib/entropy/spm/plugins/interfaces/portage_plugin/__init__.py b/lib/entropy/spm/plugins/interfaces/portage_plugin/__init__.py index d51993b00..853f1d6fd 100644 --- a/lib/entropy/spm/plugins/interfaces/portage_plugin/__init__.py +++ b/lib/entropy/spm/plugins/interfaces/portage_plugin/__init__.py @@ -1421,7 +1421,7 @@ class PortagePlugin(SpmPlugin): try: entropy.tools.uncompress_tarball(package_file, extract_path = pkg_dir, catch_empty = False) - except tarfile.ReadError: + except (tarfile.ReadError, OSError): empty_content = True env_bz2 = os.path.join(meta_dir, PortagePlugin.ENV_FILE_COMP)