From 1cb063714c9ab56ffe2e34273db010a487724f4f Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 25 Sep 2010 01:20:14 +0200 Subject: [PATCH] [sulfur] improve locks handling in repositories update function --- sulfur/src/sulfur/__init__.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/sulfur/src/sulfur/__init__.py b/sulfur/src/sulfur/__init__.py index 499b3de8f..d7193caf7 100644 --- a/sulfur/src/sulfur/__init__.py +++ b/sulfur/src/sulfur/__init__.py @@ -1379,6 +1379,25 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): return False with self._privileges: + + # preventive check against other instances + locked = self._entropy.another_entropy_running() + if locked or not entropy.tools.is_root(): + okDialog(self.ui.main, + _("Another Entropy instance is running. Cannot process queue.")) + self.progress.reset_progress() + self.switch_notebook_page('packages') + return False + + self.disable_ugc = True + # acquire Entropy resources here to avoid surpises afterwards + acquired = self._entropy.lock_resources() + if not acquired: + okDialog(self.ui.main, + _("Another Entropy instance is locking this task at the moment. Try in a few minutes.")) + self.disable_ugc = False + return False + force = self.ui.forceRepoUpdate.get_active() try: repoConn = self._entropy.Repositories(repos, force = force) @@ -1386,14 +1405,16 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): msg = "%s: %s" % (_('No repositories specified in'), etpConst['repositoriesconf'],) self.progress_log( msg, extra = "repositories") + self._entropy.unlock_resources() + self.disable_ugc = False return 127 except Exception as e: msg = "%s: %s" % (_('Unhandled exception'), e,) self.progress_log(msg, extra = "repositories") + self._entropy.unlock_resources() + self.disable_ugc = False return 2 - self.disable_ugc = True - # this is in EXACT order to avoid GTK complaining self.show_progress_bars() @@ -1449,6 +1470,7 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): self.progress.set_extraLabel( _('sys-apps/entropy needs to be updated as soon as possible.')) + self._entropy.unlock_resources() self.end_working() self.progress.reset_progress() @@ -1457,7 +1479,6 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): self.gtk_loop() self.setup_application() self.set_package_radio('updates') - initconfig_entropy_constants(etpSys['rootdir']) self.ui_lock(False) self.disable_ugc = False