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.trace import mutter
27
from trace import mutter
30
29
######################################################################
92
91
p = self._path(fileid)
93
92
if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
94
from bzrlib.errors import bailout
95
93
raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
114
def copy_multi(self, other, ids, permit_failure=False):
112
def copy_multi(self, other, ids):
115
113
"""Copy texts for ids from other into self.
117
115
If an id is present in self, it is skipped. A count of copied
118
116
ids is returned, which may be less than len(ids).
120
pb = bzrlib.ui.ui_factory.progress_bar()
118
from bzrlib.progress import ProgressBar
122
120
pb.update('preparing to copy')
123
121
to_copy = [id for id in ids if id not in self]
124
if isinstance(other, ImmutableStore):
125
return self.copy_multi_immutable(other, to_copy, pb)
127
123
for id in to_copy:
129
125
pb.update('copy', count, len(to_copy))
130
if not permit_failure:
131
self.add(other[id], id)
126
self.add(other[id], id)
140
127
assert count == len(to_copy)
145
def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
146
from shutil import copyfile
151
other_p = other._path(id)
155
if e.errno == errno.ENOENT:
156
if not permit_failure:
157
copyfile(other_p+".gz", p+".gz")
160
copyfile(other_p+".gz", p+".gz")
162
if e.errno == errno.ENOENT:
170
pb.update('copy', count, len(to_copy))
171
assert count == len(to_copy)
176
132
def __contains__(self, fileid):
192
148
def __len__(self):
193
149
return len(os.listdir(self._basedir))
196
151
def __getitem__(self, fileid):
197
152
"""Returns a file reading from a particular entry."""
198
153
p = self._path(fileid)
200
155
return gzip.GzipFile(p + '.gz', 'rb')
201
156
except IOError, e:
202
if e.errno != errno.ENOENT:
208
if e.errno != errno.ENOENT:
211
raise IndexError(fileid)
157
if e.errno == errno.ENOENT:
214
162
def total_size(self):
215
163
"""Return (count, bytes)