mercurial/appendfile.py
author Emanuele Aina <faina.mail@tiscali.it>
Tue, 06 Mar 2007 17:45:44 -0300
changeset 4150 cf26f4564000
parent 3877 abaee83ce0a6
child 4258 b11a2fb59cf5
permissions -rw-r--r--
Merge _remove_file() and _remove_dir() in a single function
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     1
# appendfile.py - special classes to make repo updates atomic
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     2
#
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     4
#
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     7
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 2236
diff changeset
     8
import cStringIO, changelog, errno, manifest, os, tempfile, util
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
     9
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    10
# writes to metadata files are ordered.  reads: changelog, manifest,
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    11
# normal files.  writes: normal files, manifest, changelog.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    12
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    13
# manifest contains pointers to offsets in normal files.  changelog
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    14
# contains pointers to offsets in manifest.  if reader reads old
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    15
# changelog while manifest or normal files are written, it has no
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    16
# pointers into new parts of those files that are maybe not consistent
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    17
# yet, so will not read them.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    18
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    19
# localrepo.addchangegroup thinks it writes changelog first, then
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    20
# manifest, then normal files (this is order they are available, and
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    21
# needed for computing linkrev fields), but uses appendfile to hide
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    22
# updates from readers.  data not written to manifest or changelog
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    23
# until all normal files updated.  write manifest first, then
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    24
# changelog.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    25
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    26
# with this write ordering, readers cannot see inconsistent view of
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    27
# repo during update.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    28
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    29
class appendfile(object):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    30
    '''implement enough of file protocol to append to revlog file.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    31
    appended data is written to temp file.  reads and seeks span real
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    32
    file and temp file.  readers cannot see appended data until
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    33
    writedata called.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    34
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    35
    def __init__(self, fp, tmpname):
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    36
        if tmpname:
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    37
            self.tmpname = tmpname
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    38
            self.tmpfp = util.posixfile(self.tmpname, 'ab+')
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    39
        else:
2165
d821918e3bee Use better names (hg-{usage}-{random}.{suffix}) for temporary files.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2102
diff changeset
    40
            fd, self.tmpname = tempfile.mkstemp(prefix="hg-appendfile-")
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    41
            os.close(fd)
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    42
            self.tmpfp = util.posixfile(self.tmpname, 'ab+')
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    43
        self.realfp = fp
2010
db1eb0de286a fix appendfile problem on macos.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1999
diff changeset
    44
        self.offset = fp.tell()
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    45
        # real file is not written by anyone else. cache its size so
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    46
        # seek and read can be fast.
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    47
        self.realsize = util.fstat(fp).st_size
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    48
        self.name = fp.name
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    49
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    50
    def end(self):
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    51
        self.tmpfp.flush() # make sure the stat is correct
2176
9b42304d9896 fix file handling bugs on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2102
diff changeset
    52
        return self.realsize + util.fstat(self.tmpfp).st_size
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    53
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    54
    def tell(self):
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    55
        return self.offset
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    56
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    57
    def flush(self):
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    58
        self.tmpfp.flush()
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    59
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    60
    def close(self):
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    61
        self.realfp.close()
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    62
        self.tmpfp.close()
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    63
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    64
    def seek(self, offset, whence=0):
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    65
        '''virtual file offset spans real file and temp file.'''
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    66
        if whence == 0:
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    67
            self.offset = offset
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    68
        elif whence == 1:
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    69
            self.offset += offset
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    70
        elif whence == 2:
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    71
            self.offset = self.end() + offset
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
    72
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    73
        if self.offset < self.realsize:
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    74
            self.realfp.seek(self.offset)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    75
        else:
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    76
            self.tmpfp.seek(self.offset - self.realsize)
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    77
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    78
    def read(self, count=-1):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    79
        '''only trick here is reads that span real file and temp file.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    80
        fp = cStringIO.StringIO()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    81
        old_offset = self.offset
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    82
        if self.offset < self.realsize:
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    83
            s = self.realfp.read(count)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    84
            fp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    85
            self.offset += len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    86
            if count > 0:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    87
                count -= len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    88
        if count != 0:
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    89
            if old_offset != self.offset:
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
    90
                self.tmpfp.seek(self.offset - self.realsize)
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    91
            s = self.tmpfp.read(count)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    92
            fp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    93
            self.offset += len(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    94
        return fp.getvalue()
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    95
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    96
    def write(self, s):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    97
        '''append to temp file.'''
2027
94d3170399e1 work around python bug on solaris 10.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2010
diff changeset
    98
        self.tmpfp.seek(0, 2)
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
    99
        self.tmpfp.write(s)
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   100
        # all writes are appends, so offset must go to end of file.
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   101
        self.offset = self.realsize + self.tmpfp.tell()
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   102
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   103
class appendopener(object):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   104
    '''special opener for files that only read or append.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   105
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   106
    def __init__(self, opener):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   107
        self.realopener = opener
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   108
        # key: file name, value: appendfile name
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   109
        self.tmpnames = {}
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   110
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   111
    def __call__(self, name, mode='r'):
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   112
        '''open file.'''
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   113
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
   114
        assert mode in 'ra+'
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   115
        try:
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   116
            realfp = self.realopener(name, 'r')
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   117
        except IOError, err:
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   118
            if err.errno != errno.ENOENT: raise
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   119
            realfp = self.realopener(name, 'w+')
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   120
        tmpname = self.tmpnames.get(name)
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   121
        fp = appendfile(realfp, tmpname)
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   122
        if tmpname is None:
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   123
            self.tmpnames[name] = fp.tmpname
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   124
        return fp
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   125
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   126
    def writedata(self):
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   127
        '''copy data from temp files to real files.'''
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   128
        # write .d file before .i file.
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   129
        tmpnames = self.tmpnames.items()
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   130
        tmpnames.sort()
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   131
        for name, tmpname in tmpnames:
2236
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   132
            ifp = open(tmpname, 'rb')
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   133
            ofp = self.realopener(name, 'a')
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   134
            for chunk in util.filechunkiter(ifp):
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   135
                ofp.write(chunk)
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   136
            ifp.close()
2102
c62112815801 remove appendfile data as soon as not needed.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2089
diff changeset
   137
            os.unlink(tmpname)
2232
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   138
            del self.tmpnames[name]
2236
d7f866789d7e reduce memory used when appendfile appends to real file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2232
diff changeset
   139
            ofp.close()
2089
cb99c711c59f make appendfile simpler so it does not break with revlogng on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2082
diff changeset
   140
2232
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   141
    def cleanup(self):
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   142
        '''delete temp files (this discards unwritten data!)'''
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   143
        for tmpname in self.tmpnames.values():
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   144
            os.unlink(tmpname)
ef3c039e7ab8 Always remove appendopener tmp files (fixes issue235).
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2177
diff changeset
   145
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   146
# files for changelog and manifest are in different appendopeners, so
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   147
# not mixed up together.
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   148
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   149
class appendchangelog(changelog.changelog, appendopener):
2082
856f0ba200bc Additional appendfile fixes for interleaved data/index files
mason@suse.com
parents: 2075
diff changeset
   150
    def __init__(self, opener, version):
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   151
        appendopener.__init__(self, opener)
2082
856f0ba200bc Additional appendfile fixes for interleaved data/index files
mason@suse.com
parents: 2075
diff changeset
   152
        changelog.changelog.__init__(self, self, version)
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
   153
    def checkinlinesize(self, fp, tr):
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
   154
        return
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   155
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   156
class appendmanifest(manifest.manifest, appendopener):
2082
856f0ba200bc Additional appendfile fixes for interleaved data/index files
mason@suse.com
parents: 2075
diff changeset
   157
    def __init__(self, opener, version):
1999
fdb3a72ef664 forgot to add new module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
   158
        appendopener.__init__(self, opener)
2082
856f0ba200bc Additional appendfile fixes for interleaved data/index files
mason@suse.com
parents: 2075
diff changeset
   159
        manifest.manifest.__init__(self, self, version)
2075
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
   160
    def checkinlinesize(self, fp, tr):
343aeefb553b Make the appendfile class inline-data index friendly
mason@suse.com
parents: 2027
diff changeset
   161
        return