From a64c873284d50a537aa68ce824bbd6dc05694e2c Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 11 Sep 2010 15:38:05 +0200 Subject: [PATCH] [entropy.db] EntropyRepository: commit to disk (calling Connection.commit()) before calling plugin hooks To avoid EntropyRepositoryBase plugin hooks to not see changes in repository not yet committed (leading to tricky hard to debug situations) call Connection.commit() before plugin hooks. --- libraries/entropy/db/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libraries/entropy/db/__init__.py b/libraries/entropy/db/__init__.py index b8b3878f8..8514ae2ff 100644 --- a/libraries/entropy/db/__init__.py +++ b/libraries/entropy/db/__init__.py @@ -636,15 +636,21 @@ class EntropyRepository(EntropyRepositoryBase): Reimplemented from EntropyRepositoryBase. Needs to call superclass method. """ - super(EntropyRepository, self).commitChanges(force = force, - no_plugins = no_plugins) - if force or (not self.readonly): + # NOTE: the actual commit MUST be executed before calling + # the superclass method (that is going to call EntropyRepositoryBase + # plugins). This to avoid that other connection to the same exact + # database file are opened and used before data is actually written + # to disk, causing a tricky race condition hard to exploit. + # So, FIRST commit changes, then call plugins. try: self._connection().commit() except Error: pass + super(EntropyRepository, self).commitChanges(force = force, + no_plugins = no_plugins) + def initializeRepository(self): """ Reimplemented from EntropyRepositoryBase.