221
221
raise KeyError(fileid)
223
def __init__(self, a_transport, prefixed=False, compressed=False):
223
def __init__(self, a_transport, prefixed=False, compressed=False,
224
dir_mode=None, file_mode=None):
224
225
assert isinstance(a_transport, transport.Transport)
225
226
super(TransportStore, self).__init__()
226
227
self._transport = a_transport
228
229
self._compressed = compressed
229
230
self._suffixes = set()
232
# It is okay for these to be None, it just means they
233
# will just use the filesystem defaults
234
self._dir_mode = dir_mode
235
self._file_mode = file_mode
231
237
def _iter_files_recursive(self):
232
238
"""Iterate through the files in the transport."""
233
239
for quoted_relpath in self._transport.iter_files_recursive():
303
309
return bzrlib.store.text.TextStore(transport.memory.MemoryTransport())
306
class CachedStore(Store):
307
"""A store that caches data locally, to avoid repeated downloads.
308
The precacache method should be used to avoid server round-trips for
312
def __init__(self, store, cache_dir):
313
super(CachedStore, self).__init__()
314
self.source_store = store
315
# This clones the source store type with a locally bound
316
# transport. FIXME: it assumes a constructor is == cloning.
317
# clonable store - it might be nicer to actually have a clone()
318
# or something. RBC 20051003
319
self.cache_store = store.__class__(LocalTransport(cache_dir))
322
mutter("Cache add %s", id)
323
if id not in self.cache_store:
324
self.cache_store.add(self.source_store.get(id), id)
325
return self.cache_store.get(id)
327
def has_id(self, fileid, suffix=None):
328
"""See Store.has_id."""
329
if self.cache_store.has_id(fileid, suffix):
331
if self.source_store.has_id(fileid, suffix):
332
# We could asynchronously copy at this time
337
312
def copy_all(store_from, store_to):
338
313
"""Copy all ids from one store to another."""
339
314
# TODO: Optional progress indicator