~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-22 17:52:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050822175211-90caf03af7d0cf07
- fix bug where bzr upgrade aborts when trying to fix trees that mention revisions
  which are not locally present

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
            
91
91
        p = self._path(fileid)
92
92
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
 
93
            from bzrlib.errors import bailout
93
94
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
94
95
 
95
96
        fn = p
119
120
        pb = ProgressBar()
120
121
        pb.update('preparing to copy')
121
122
        to_copy = [id for id in ids if id not in self]
 
123
        if isinstance(other, ImmutableStore):
 
124
            return self.copy_multi_immutable(other, to_copy, pb)
122
125
        count = 0
123
126
        for id in to_copy:
124
127
            count += 1
127
130
        assert count == len(to_copy)
128
131
        pb.clear()
129
132
        return count
 
133
 
 
134
 
 
135
    def copy_multi_immutable(self, other, to_copy, pb):
 
136
        from shutil import copyfile
 
137
        count = 0
 
138
        for id in to_copy:
 
139
            p = self._path(id)
 
140
            other_p = other._path(id)
 
141
            try:
 
142
                copyfile(other_p, p)
 
143
            except IOError, e:
 
144
                if e.errno == errno.ENOENT:
 
145
                    copyfile(other_p+".gz", p+".gz")
 
146
                else:
 
147
                    raise
 
148
            
 
149
            count += 1
 
150
            pb.update('copy', count, len(to_copy))
 
151
        assert count == len(to_copy)
 
152
        pb.clear()
 
153
        return count
130
154
    
131
155
 
132
156
    def __contains__(self, fileid):
148
172
    def __len__(self):
149
173
        return len(os.listdir(self._basedir))
150
174
 
 
175
 
151
176
    def __getitem__(self, fileid):
152
177
        """Returns a file reading from a particular entry."""
153
178
        p = self._path(fileid)
154
179
        try:
155
180
            return gzip.GzipFile(p + '.gz', 'rb')
156
181
        except IOError, e:
157
 
            if e.errno == errno.ENOENT:
158
 
                return file(p, 'rb')
159
 
            else:
160
 
                raise e
 
182
            if e.errno != errno.ENOENT:
 
183
                raise
 
184
 
 
185
        try:
 
186
            return file(p, 'rb')
 
187
        except IOError, e:
 
188
            if e.errno != errno.ENOENT:
 
189
                raise
 
190
 
 
191
        raise IndexError(fileid)
 
192
 
161
193
 
162
194
    def total_size(self):
163
195
        """Return (count, bytes)