~ubuntu-branches/ubuntu/precise/mercurial/precise-updates

« back to all changes in this revision

Viewing changes to mercurial/transaction.py

  • Committer: Bazaar Package Importer
  • Author(s): Javi Merino
  • Date: 2011-03-06 16:01:58 UTC
  • mto: (28.1.2 sid) (1.1.14)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20110306160158-y94pzpmtd7b1xgjk
Tags: upstream-1.8
ImportĀ upstreamĀ versionĀ 1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
from i18n import _
15
15
import os, errno
16
 
import error
 
16
import error, util
17
17
 
18
18
def active(func):
19
19
    def _active(self, *args, **kwds):
27
27
    for f, o, ignore in entries:
28
28
        if o or not unlink:
29
29
            try:
30
 
                opener(f, 'a').truncate(o)
 
30
                fp = opener(f, 'a')
 
31
                fp.truncate(o)
 
32
                fp.close()
31
33
            except IOError:
32
34
                report(_("failed to truncate %s\n") % f)
33
35
                raise
34
36
        else:
35
37
            try:
36
 
                fn = opener(f).name
37
 
                os.unlink(fn)
 
38
                fp = opener(f)
 
39
                fn = fp.name
 
40
                fp.close()
 
41
                util.unlink(fn)
38
42
            except (IOError, OSError), inst:
39
43
                if inst.errno != errno.ENOENT:
40
44
                    raise
41
 
    os.unlink(journal)
 
45
    util.unlink(journal)
42
46
 
43
47
class transaction(object):
44
48
    def __init__(self, report, opener, journal, after=None, createmode=None):
52
56
        self.journal = journal
53
57
        self._queue = []
54
58
 
55
 
        self.file = open(self.journal, "w")
 
59
        self.file = util.posixfile(self.journal, "w")
56
60
        if createmode is not None:
57
61
            os.chmod(self.journal, createmode & 0666)
58
62
 
133
137
        if self.after:
134
138
            self.after()
135
139
        if os.path.isfile(self.journal):
136
 
            os.unlink(self.journal)
 
140
            util.unlink(self.journal)
137
141
        self.journal = None
138
142
 
139
143
    @active
151
155
        try:
152
156
            if not self.entries:
153
157
                if self.journal:
154
 
                    os.unlink(self.journal)
 
158
                    util.unlink(self.journal)
155
159
                return
156
160
 
157
161
            self.report(_("transaction abort!\n"))
169
173
def rollback(opener, file, report):
170
174
    entries = []
171
175
 
172
 
    for l in open(file).readlines():
 
176
    fp = util.posixfile(file)
 
177
    lines = fp.readlines()
 
178
    fp.close()
 
179
    for l in lines:
173
180
        f, o = l.split('\0')
174
181
        entries.append((f, int(o), None))
175
182