~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Robert Collins
  • Date: 2005-08-25 12:46:42 UTC
  • mfrom: (1116)
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050825124642-45ed1cd74db10370
merge from mpool

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os, tempfile, types, osutils, gzip, errno
25
25
from stat import ST_SIZE
26
26
from StringIO import StringIO
27
 
from bzrlib.errors import BzrError
28
27
from bzrlib.trace import mutter
29
28
import bzrlib.ui
30
29
 
68
67
    def __init__(self, basedir):
69
68
        self._basedir = basedir
70
69
 
71
 
    def _path(self, entry_id):
72
 
        if not isinstance(entry_id, basestring):
73
 
            raise TypeError(type(entry_id))
74
 
        if '\\' in entry_id or '/' in entry_id:
75
 
            raise ValueError("invalid store id %r" % entry_id)
76
 
        return os.path.join(self._basedir, entry_id)
 
70
    def _path(self, id):
 
71
        if '\\' in id or '/' in id:
 
72
            raise ValueError("invalid store id %r" % id)
 
73
        return os.path.join(self._basedir, id)
77
74
 
78
75
    def __repr__(self):
79
76
        return "%s(%r)" % (self.__class__.__name__, self._basedir)
94
91
            
95
92
        p = self._path(fileid)
96
93
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
 
94
            from bzrlib.errors import bailout
97
95
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
98
96
 
99
97
        fn = p
126
124
        pb.update('preparing to copy')
127
125
        to_copy = [id for id in ids if id not in self]
128
126
        if isinstance(other, ImmutableStore):
129
 
            return self.copy_multi_immutable(other, to_copy, pb, 
130
 
                                             permit_failure=permit_failure)
 
127
            return self.copy_multi_immutable(other, to_copy, pb)
131
128
        count = 0
132
 
        failed = set()
133
129
        for id in to_copy:
134
130
            count += 1
135
131
            pb.update('copy', count, len(to_copy))
138
134
            else:
139
135
                try:
140
136
                    entry = other[id]
141
 
                except KeyError:
142
 
                    failed.add(id)
 
137
                except IndexError:
 
138
                    failures.add(id)
143
139
                    continue
144
140
                self.add(entry, id)
145
141
                
146
 
        if not permit_failure:
147
 
            assert count == len(to_copy)
 
142
        assert count == len(to_copy)
148
143
        pb.clear()
149
 
        return count, failed
 
144
        return count, []
150
145
 
151
146
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
152
147
        from shutil import copyfile
214
209
            if e.errno != errno.ENOENT:
215
210
                raise
216
211
 
217
 
        raise KeyError(fileid)
 
212
        raise IndexError(fileid)
218
213
 
219
214
 
220
215
    def total_size(self):