~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-09-22 13:32:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050922133202-347cfd35d2941dd5
- simple weave-based annotate code (not complete)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
unique ID.
25
25
"""
26
26
 
27
 
import errno
28
 
import gzip
29
 
import os
30
 
import tempfile
31
 
import types
 
27
import os, tempfile, types, osutils, gzip, errno
32
28
from stat import ST_SIZE
33
29
from StringIO import StringIO
34
 
 
35
 
from bzrlib.errors import BzrError, UnlistableStore
 
30
from bzrlib.errors import BzrError
36
31
from bzrlib.trace import mutter
37
32
import bzrlib.ui
38
 
import bzrlib.osutils as osutils
39
 
 
40
33
 
41
34
######################################################################
42
35
# stores
136
129
        pb.update('preparing to copy')
137
130
        to_copy = [id for id in ids if id not in self]
138
131
        if isinstance(other, ImmutableStore):
139
 
            return self.copy_multi_immutable(other, to_copy, pb, 
140
 
                                             permit_failure=permit_failure)
 
132
            return self.copy_multi_immutable(other, to_copy, pb)
141
133
        count = 0
142
134
        failed = set()
143
135
        for id in to_copy:
148
140
            else:
149
141
                try:
150
142
                    entry = other[id]
151
 
                except KeyError:
 
143
                except IndexError:
152
144
                    failed.add(id)
153
145
                    continue
154
146
                self.add(entry, id)
159
151
        return count, failed
160
152
 
161
153
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
 
154
        from shutil import copyfile
162
155
        count = 0
163
156
        failed = set()
164
157
        for id in to_copy:
165
158
            p = self._path(id)
166
159
            other_p = other._path(id)
167
160
            try:
168
 
                osutils.link_or_copy(other_p, p)
169
 
            except (IOError, OSError), e:
 
161
                copyfile(other_p, p)
 
162
            except IOError, e:
170
163
                if e.errno == errno.ENOENT:
171
164
                    if not permit_failure:
172
 
                        osutils.link_or_copy(other_p+".gz", p+".gz")
 
165
                        copyfile(other_p+".gz", p+".gz")
173
166
                    else:
174
167
                        try:
175
 
                            osutils.link_or_copy(other_p+".gz", p+".gz")
 
168
                            copyfile(other_p+".gz", p+".gz")
176
169
                        except IOError, e:
177
170
                            if e.errno == errno.ENOENT:
178
171
                                failed.add(id)
224
217
            if e.errno != errno.ENOENT:
225
218
                raise
226
219
 
227
 
        raise KeyError(fileid)
 
220
        raise IndexError(fileid)
228
221
 
229
222
 
230
223
    def total_size(self):
264
257
            os.remove(fpath)
265
258
        os.rmdir(self._basedir)
266
259
        mutter("%r destroyed" % self)
267
 
 
268
 
def copy_all(store_from, store_to):
269
 
    """Copy all ids from one store to another."""
270
 
    if not hasattr(store_from, "__iter__"):
271
 
        raise UnlistableStore(store_from)
272
 
    ids = [f for f in store_from]
273
 
    store_to.copy_multi(store_from, ids)