summaryrefslogtreecommitdiff
path: root/sphinx/builder.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-01-03 11:13:43 +0100
committerGeorg Brandl <georg@python.org>2009-01-03 11:13:43 +0100
commit9b48c13ee8d3fb03a5c6516d63c497c56074e34b (patch)
tree7533c74b33395196c14b0dece959e99a4ff43141 /sphinx/builder.py
parent8af0caea30353cfc39c3f900fed321f6ef23db0a (diff)
downloadsphinx-git-9b48c13ee8d3fb03a5c6516d63c497c56074e34b.tar.gz
* #81: Write environment and search index in a manner that is safe
from exceptions that occur during dumping.
Diffstat (limited to 'sphinx/builder.py')
-rw-r--r--sphinx/builder.py8
1 files changed, 6 insertions, 2 deletions
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)