[kupfer] core: Don't write configuration data if we didn't load properly



commit e1654d134b16be802cade9e45bc79c4599e52f60
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Jan 19 02:30:34 2010 +0100

    core: Don't write configuration data if we didn't load properly
    
    Record proper load of the SourceController at the end of initializing
    and caching sources. If we don't reach this point (due to an
    exception), we won't write any configuration data either.

 kupfer/core/sources.py |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 2660478..9dd8ba1 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -245,6 +245,7 @@ class SourceController (pretty.OutputMixin):
 		self.text_sources = set()
 		self.content_decorators = set()
 		self.action_decorators = set()
+		self.loaded_successfully = False
 
 	def add(self, srcs, toplevel=False):
 		srcs = set(self._try_unpickle(srcs))
@@ -385,9 +386,15 @@ class SourceController (pretty.OutputMixin):
 			obj.add_content(content)
 
 	def finish(self):
-		self._pickle_sources(self.sources)
+		if self.loaded_successfully:
+			self._pickle_sources(self.sources)
+		else:
+			self.output_debug("Not writing cache on failed load")
 
 	def save_data(self):
+		if not self.loaded_successfully:
+			self.output_info("Not writing configuration on failed load")
+			return
 		configsaver = SourceDataPickler()
 		for source in self.sources:
 			if configsaver.source_has_config(source):
@@ -445,6 +452,7 @@ class SourceController (pretty.OutputMixin):
 			src.initialize()
 		for src in set(self.toplevel_sources):
 			self._checked_rescan_source(src, force=False)
+		self.loaded_successfully = True
 
 _source_controller = None
 def GetSourceController():



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]