* #81: Write environment and search index in a manner that is safe

from exceptions that occur during dumping.
This commit is contained in:
Georg Brandl 2009-01-03 11:13:43 +01:00
parent 8af0caea30
commit 9b48c13ee8
3 changed files with 16 additions and 4 deletions

View File

@ -1,6 +1,11 @@
Release 0.5.2 (in development) 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) Release 0.5.1 (Dec 15, 2008)
============================ ============================

View File

@ -5,7 +5,7 @@
Builder classes for different output formats. 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. :license: BSD.
""" """
@ -775,11 +775,15 @@ class StandaloneHTMLBuilder(Builder):
def handle_finish(self): def handle_finish(self):
self.info(bold('dumping search index... '), nonl=True) self.info(bold('dumping search index... '), nonl=True)
self.indexer.prune(self.env.all_docs) 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: try:
self.indexer.dump(f, self.indexer_format) self.indexer.dump(f, self.indexer_format)
finally: finally:
f.close() f.close()
os.rename(searchindexfn + '.tmp', searchindexfn)
self.info('done') self.info('done')
self.info(bold('dumping object inventory... '), nonl=True) self.info(bold('dumping object inventory... '), nonl=True)

View File

@ -5,7 +5,7 @@
Global creation environment. Global creation environment.
:copyright: 2007-2008 by Georg Brandl. :copyright: 2007-2009 by Georg Brandl.
:license: BSD. :license: BSD.
""" """
@ -203,7 +203,9 @@ class BuildEnvironment:
self.set_warnfunc(None) self.set_warnfunc(None)
values = self.config.values values = self.config.values
del 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 # remove potentially pickling-problematic values from config
for key, val in vars(self.config).items(): for key, val in vars(self.config).items():
if key.startswith('_') or \ if key.startswith('_') or \
@ -215,6 +217,7 @@ class BuildEnvironment:
pickle.dump(self, picklefile, pickle.HIGHEST_PROTOCOL) pickle.dump(self, picklefile, pickle.HIGHEST_PROTOCOL)
finally: finally:
picklefile.close() picklefile.close()
os.rename(filename + '.tmp', filename)
# reset attributes # reset attributes
self.config.values = values self.config.values = values
self.set_warnfunc(warnfunc) self.set_warnfunc(warnfunc)