1147
1146
for entry in rename_entries:
1149
1148
self._move_entry(entry)
1151
self._rollback_move(moved)
1152
raise errors.BzrRenameFailedError(entry.from_rel, entry.to_rel,
1154
except errors.BzrError, e:
1155
1150
self._rollback_move(moved)
1157
1152
moved.append(entry)
1159
1154
def _rollback_move(self, moved):
1160
"""Try to rollback a previous move in case of an error in the
1155
"""Try to rollback a previous move in case of an filesystem error."""
1163
1156
inv = self.inventory
1164
1157
for entry in moved:
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])
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)
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.")
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)
1188
if not entry.only_change_inv:
1177
if not entry.only_change_inv:
1189
1179
osutils.rename(from_rel_abs, to_rel_abs)
1190
inv.rename(entry.from_id, entry.to_parent_id, entry.to_tail)
1181
raise errors.BzrMoveFailedError(entry.from_rel,
1183
inv.rename(entry.from_id, entry.to_parent_id, entry.to_tail)
1192
1185
@needs_tree_write_lock
1193
1186
def rename_one(self, from_rel, to_rel, after=False):
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