transaction: use posixfile and unlink from util

instead of open() and os.unlink()

Avoids potential issues with file access on Windows (e.g. AV-scanners).
This commit is contained in:
Adrian Buehlmann 2011-02-15 14:41:49 +01:00
parent f9d396be75
commit 76e8469c0d

View File

@ -13,7 +13,7 @@
from i18n import _
import os, errno
import error
import error, util
def active(func):
def _active(self, *args, **kwds):
@ -38,11 +38,11 @@ def _playback(journal, report, opener, entries, unlink=True):
fp = opener(f)
fn = fp.name
fp.close()
os.unlink(fn)
util.unlink(fn)
except (IOError, OSError), inst:
if inst.errno != errno.ENOENT:
raise
os.unlink(journal)
util.unlink(journal)
class transaction(object):
def __init__(self, report, opener, journal, after=None, createmode=None):
@ -56,7 +56,7 @@ class transaction(object):
self.journal = journal
self._queue = []
self.file = open(self.journal, "w")
self.file = util.posixfile(self.journal, "w")
if createmode is not None:
os.chmod(self.journal, createmode & 0666)
@ -137,7 +137,7 @@ class transaction(object):
if self.after:
self.after()
if os.path.isfile(self.journal):
os.unlink(self.journal)
util.unlink(self.journal)
self.journal = None
@active
@ -155,7 +155,7 @@ class transaction(object):
try:
if not self.entries:
if self.journal:
os.unlink(self.journal)
util.unlink(self.journal)
return
self.report(_("transaction abort!\n"))
@ -173,7 +173,7 @@ class transaction(object):
def rollback(opener, file, report):
entries = []
fp = open(file)
fp = util.posixfile(file)
lines = fp.readlines()
fp.close()
for l in lines: