Georg Brandl avatar Georg Brandl committed 9606294

* #81: Write environment and search index in a manner that is safe
from exceptions that occur during dumping.

Comments (0)

Files changed (3)

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

sphinx/builder.py

 
     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.
 """
 
     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)

sphinx/environment.py

 
     Global creation environment.
 
-    :copyright: 2007-2008 by Georg Brandl.
+    :copyright: 2007-2009 by Georg Brandl.
     :license: BSD.
 """
 
         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 \
             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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.