diff --git a/CHANGES b/CHANGES index c82c5b710..88d91b7a1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ Release 0.5.2 (in development) ============================== +* #81: Write environment and search index in a manner that is safe + from exceptions that occur during dumping. + +* #80: Fix UnicodeErrors when a locale is set with setlocale(). + Release 0.5.1 (Dec 15, 2008) ============================ diff --git a/sphinx/builder.py b/sphinx/builder.py index 81fc24862..3f3ec2c9e 100644 --- a/sphinx/builder.py +++ b/sphinx/builder.py @@ -5,7 +5,7 @@ Builder classes for different output formats. - :copyright: 2007-2008 by Georg Brandl, Sebastian Wiesner, Horst Gutmann. + :copyright: 2007-2009 by Georg Brandl, Sebastian Wiesner, Horst Gutmann. :license: BSD. """ @@ -775,11 +775,15 @@ class StandaloneHTMLBuilder(Builder): def handle_finish(self): self.info(bold('dumping search index... '), nonl=True) self.indexer.prune(self.env.all_docs) - f = open(path.join(self.outdir, self.searchindex_filename), 'wb') + searchindexfn = path.join(self.outdir, self.searchindex_filename) + # first write to a temporary file, so that if dumping fails, the existing + # index won't be overwritten + f = open(searchindexfn + '.tmp', 'wb') try: self.indexer.dump(f, self.indexer_format) finally: f.close() + os.rename(searchindexfn + '.tmp', searchindexfn) self.info('done') self.info(bold('dumping object inventory... '), nonl=True) diff --git a/sphinx/environment.py b/sphinx/environment.py index 795e4594d..62ae4b03b 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -5,7 +5,7 @@ Global creation environment. - :copyright: 2007-2008 by Georg Brandl. + :copyright: 2007-2009 by Georg Brandl. :license: BSD. """ @@ -203,7 +203,9 @@ class BuildEnvironment: self.set_warnfunc(None) values = self.config.values del self.config.values - picklefile = open(filename, 'wb') + # first write to a temporary file, so that if dumping fails, the existing + # environment won't be overwritten + picklefile = open(filename + '.tmp', 'wb') # remove potentially pickling-problematic values from config for key, val in vars(self.config).items(): if key.startswith('_') or \ @@ -215,6 +217,7 @@ class BuildEnvironment: pickle.dump(self, picklefile, pickle.HIGHEST_PROTOCOL) finally: picklefile.close() + os.rename(filename + '.tmp', filename) # reset attributes self.config.values = values self.set_warnfunc(warnfunc)