~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-26 00:10:48 UTC
  • Revision ID: mbp@sourcefrog.net-20050826001048-b84148d3ef567d0d
- fix bzr.dev branch url in tutorial
  thanks to madduck

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
128
126
        if isinstance(other, ImmutableStore):
129
127
            return self.copy_multi_immutable(other, to_copy, pb)
130
128
        count = 0
131
 
        failed = set()
132
129
        for id in to_copy:
133
130
            count += 1
134
131
            pb.update('copy', count, len(to_copy))
138
135
                try:
139
136
                    entry = other[id]
140
137
                except IndexError:
141
 
                    failed.add(id)
 
138
                    failures.add(id)
142
139
                    continue
143
140
                self.add(entry, id)
144
141
                
145
 
        if not permit_failure:
146
 
            assert count == len(to_copy)
 
142
        assert count == len(to_copy)
147
143
        pb.clear()
148
 
        return count, failed
 
144
        return count, []
 
145
 
149
146
 
150
147
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
151
148
        from shutil import copyfile