~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Marius Kruger
  • Date: 2007-01-19 19:23:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2241.
  • Revision ID: amanic@gmail.com-20070119192353-i96mfa4bsya9thdu
* Fix errors.py import order
* Atemt to handle exceptions better in WorkingTree._move

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
from bzrlib import symbol_versioning
74
74
from bzrlib.decorators import needs_read_lock, needs_write_lock
75
 
 
76
75
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID
77
76
from bzrlib.lockable_files import LockableFiles, TransportLock
78
77
from bzrlib.lockdir import LockDir
1147
1146
        for entry in rename_entries:
1148
1147
            try:
1149
1148
                self._move_entry(entry)
1150
 
            except OSError, e:
1151
 
                self._rollback_move(moved)
1152
 
                raise errors.BzrRenameFailedError(entry.from_rel, entry.to_rel,
1153
 
                    e[1])
1154
 
            except errors.BzrError, e:
 
1149
            except:
1155
1150
                self._rollback_move(moved)
1156
1151
                raise
1157
1152
            moved.append(entry)
1158
1153
 
1159
1154
    def _rollback_move(self, moved):
1160
 
        """Try to rollback a previous move in case of an error in the
1161
 
        filesystem.
1162
 
        """
 
1155
        """Try to rollback a previous move in case of an filesystem error."""
1163
1156
        inv = self.inventory
1164
1157
        for entry in moved:
1165
1158
            try:
1166
 
                self._move_entry(entry, inverse=True)
 
1159
                self._move_entry(_RenameEntry(entry.to_rel, entry.from_id,
 
1160
                    entry.to_tail, entry.to_parent_id, entry.from_rel,
 
1161
                    entry.from_tail, entry.from_parent_id,
 
1162
                    entry.only_change_inv))
1167
1163
            except OSError, e:
1168
 
                raise errors.BzrMoveFailedError( '', '',
1169
 
                    errors.BzrError("Rollback failed."
 
1164
                raise errors.BzrMoveFailedError( '', '', "Rollback failed."
1170
1165
                        " The working tree is in an inconsistent state."
1171
1166
                        " Please consider doing a 'bzr revert'."
1172
 
                        " Error message is: %s" % e[1]))
 
1167
                        " Error message is: %s" % e[1])
1173
1168
 
1174
 
    def _move_entry(self, entry, inverse=False):
 
1169
    def _move_entry(self, entry):
1175
1170
        inv = self.inventory
1176
1171
        from_rel_abs = self.abspath(entry.from_rel)
1177
1172
        to_rel_abs = self.abspath(entry.to_rel)
1178
 
 
1179
1173
        if from_rel_abs == to_rel_abs:
1180
 
            raise errors.BzrMoveFailedError(from_rel, to_rel,
 
1174
            raise errors.BzrMoveFailedError(entry.from_rel, entry.to_rel,
1181
1175
                "Source and target are identical.")
1182
1176
 
1183
 
        if inverse:
1184
 
            if not entry.only_change_inv:
1185
 
                osutils.rename(to_rel_abs, from_rel_abs)
1186
 
            inv.rename(entry.from_id, entry.from_parent_id, entry.from_tail)
1187
 
        else:
1188
 
            if not entry.only_change_inv:
 
1177
        if not entry.only_change_inv:
 
1178
            try:
1189
1179
                osutils.rename(from_rel_abs, to_rel_abs)
1190
 
            inv.rename(entry.from_id, entry.to_parent_id, entry.to_tail)
 
1180
            except OSError, e:
 
1181
                raise errors.BzrMoveFailedError(entry.from_rel,
 
1182
                    entry.to_rel, e[1])
 
1183
        inv.rename(entry.from_id, entry.to_parent_id, entry.to_tail)
1191
1184
 
1192
1185
    @needs_tree_write_lock
1193
1186
    def rename_one(self, from_rel, to_rel, after=False):
1257
1250
 
1258
1251
    class _RenameEntry(object):
1259
1252
        def __init__(self, from_rel, from_id, from_tail, from_parent_id,
1260
 
                     to_rel, to_tail, to_parent_id):
 
1253
                     to_rel, to_tail, to_parent_id, only_change_inv=False):
1261
1254
            self.from_rel = from_rel
1262
1255
            self.from_id = from_id
1263
1256
            self.from_tail = from_tail
1265
1258
            self.to_rel = to_rel
1266
1259
            self.to_tail = to_tail
1267
1260
            self.to_parent_id = to_parent_id
1268
 
            self.only_change_inv = False
 
1261
            self.only_change_inv = only_change_inv
1269
1262
 
1270
1263
    @needs_read_lock
1271
1264
    def unknowns(self):