~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-21 00:08:08 UTC
  • mto: (1092.1.41) (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: aaron.bentley@utoronto.ca-20050821000808-2a0e6ef95b1bca59
Changed copy_multi to permit failure and return a tuple, tested missing required revisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
            af.close()
111
111
 
112
112
 
113
 
    def copy_multi(self, other, ids):
 
113
    def copy_multi(self, other, ids, permit_failure=False):
114
114
        """Copy texts for ids from other into self.
115
115
 
116
116
        If an id is present in self, it is skipped.  A count of copied
126
126
        for id in to_copy:
127
127
            count += 1
128
128
            pb.update('copy', count, len(to_copy))
129
 
            self.add(other[id], id)
 
129
            if not permit_failure:
 
130
                self.add(other[id], id)
 
131
            else:
 
132
                try:
 
133
                    entry = other[id]
 
134
                except IndexError:
 
135
                    failures.add(id)
 
136
                    continue
 
137
                self.add(entry, id)
 
138
                
130
139
        assert count == len(to_copy)
131
140
        pb.clear()
132
141
        return count
133
142
 
134
143
 
135
 
    def copy_multi_immutable(self, other, to_copy, pb):
 
144
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
136
145
        from shutil import copyfile
137
146
        count = 0
 
147
        failed = set()
138
148
        for id in to_copy:
139
149
            p = self._path(id)
140
150
            other_p = other._path(id)
142
152
                copyfile(other_p, p)
143
153
            except IOError, e:
144
154
                if e.errno == errno.ENOENT:
145
 
                    copyfile(other_p+".gz", p+".gz")
 
155
                    if not permit_failure:
 
156
                        copyfile(other_p+".gz", p+".gz")
 
157
                    else:
 
158
                        try:
 
159
                            copyfile(other_p+".gz", p+".gz")
 
160
                        except IOError, e:
 
161
                            if e.errno == errno.ENOENT:
 
162
                                failed.add(id)
 
163
                            else:
 
164
                                raise
146
165
                else:
147
166
                    raise
148
167
            
150
169
            pb.update('copy', count, len(to_copy))
151
170
        assert count == len(to_copy)
152
171
        pb.clear()
153
 
        return count
 
172
        return count, failed
154
173
    
155
174
 
156
175
    def __contains__(self, fileid):
172
191
    def __len__(self):
173
192
        return len(os.listdir(self._basedir))
174
193
 
 
194
 
175
195
    def __getitem__(self, fileid):
176
196
        """Returns a file reading from a particular entry."""
177
197
        p = self._path(fileid)
178
198
        try:
179
199
            return gzip.GzipFile(p + '.gz', 'rb')
180
200
        except IOError, e:
181
 
            if e.errno == errno.ENOENT:
182
 
                return file(p, 'rb')
183
 
            else:
184
 
                raise e
 
201
            if e.errno != errno.ENOENT:
 
202
                raise
 
203
 
 
204
        try:
 
205
            return file(p, 'rb')
 
206
        except IOError, e:
 
207
            if e.errno != errno.ENOENT:
 
208
                raise
 
209
 
 
210
        raise IndexError(fileid)
 
211
 
185
212
 
186
213
    def total_size(self):
187
214
        """Return (count, bytes)