[Python-checkins] r69314 - sandbox/trunk/dbm_sqlite/alt/dbdict.py
raymond.hettinger
python-checkins at python.org
Thu Feb 5 23:04:00 CET 2009
Author: raymond.hettinger
Date: Thu Feb 5 23:04:00 2009
New Revision: 69314
Log:
Can't get tempfile to reliably delete on error and persist otherwise.
Modified:
sandbox/trunk/dbm_sqlite/alt/dbdict.py
Modified: sandbox/trunk/dbm_sqlite/alt/dbdict.py
==============================================================================
--- sandbox/trunk/dbm_sqlite/alt/dbdict.py (original)
+++ sandbox/trunk/dbm_sqlite/alt/dbdict.py Thu Feb 5 23:04:00 2009
@@ -11,7 +11,7 @@
'''
import pickle, json, csv
-import os, shutil, tempfile
+import os, shutil
class DictDB(dict):
@@ -31,13 +31,16 @@
def sync(self):
if self.flag != 'r':
- file = tempfile.NamedTemporaryFile('w+b', delete=False)
+ filename = self.filename
+ tempname = filename + '.tmp'
+ file = __builtins__.open(tempname, 'wb')
try:
self.dump(file)
except Exception:
- file.delete = True
- finally:
file.close()
+ os.remove(tempname)
+ raise
+ file.close()
shutil.move(file.name, self.filename) # atomic commit
if self.mode:
os.chmod(self.filename, self.mode)
More information about the Python-checkins
mailing list