* #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)
==============================
* #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)
============================

View File

@ -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)

View File

@ -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)