~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Robert Collins
  • Date: 2005-09-28 09:35:50 UTC
  • mfrom: (1185.1.47)
  • Revision ID: robertc@robertcollins.net-20050928093550-3ca194dfaffc79f1
merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
from stat import ST_SIZE
33
33
from StringIO import StringIO
34
34
 
35
 
from bzrlib.errors import BzrError
 
35
from bzrlib.errors import BzrError, UnlistableStore
36
36
from bzrlib.trace import mutter
37
37
import bzrlib.ui
38
38
import bzrlib.osutils as osutils
159
159
        return count, failed
160
160
 
161
161
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
162
 
        from shutil import copyfile
163
162
        count = 0
164
163
        failed = set()
165
164
        for id in to_copy:
166
165
            p = self._path(id)
167
166
            other_p = other._path(id)
168
167
            try:
169
 
                copyfile(other_p, p)
170
 
            except IOError, e:
 
168
                osutils.link_or_copy(other_p, p)
 
169
            except (IOError, OSError), e:
171
170
                if e.errno == errno.ENOENT:
172
171
                    if not permit_failure:
173
 
                        copyfile(other_p+".gz", p+".gz")
 
172
                        osutils.link_or_copy(other_p+".gz", p+".gz")
174
173
                    else:
175
174
                        try:
176
 
                            copyfile(other_p+".gz", p+".gz")
 
175
                            osutils.link_or_copy(other_p+".gz", p+".gz")
177
176
                        except IOError, e:
178
177
                            if e.errno == errno.ENOENT:
179
178
                                failed.add(id)
265
264
            os.remove(fpath)
266
265
        os.rmdir(self._basedir)
267
266
        mutter("%r destroyed" % self)
 
267
 
 
268
def copy_all(store_from, store_to):
 
269
    """Copy all ids from one store to another."""
 
270
    if not hasattr(store_from, "__iter__"):
 
271
        raise UnlistableStore(store_from)
 
272
    ids = [f for f in store_from]
 
273
    store_to.copy_multi(store_from, ids)