##// END OF EJS Templates
refactor some unlink/remove code and make sure we prune empty dir
Benoit Boissinot -
r1415:c6e6ca96 default
parent child Browse files
Show More
@@ -1441,12 +1441,7 b' def remove(ui, repo, pat, *pats, **opts)'
1441 1441 if okaytoremove(abs, rel, exact):
1442 1442 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1443 1443 names.append(abs)
1444 for name in names:
1445 try:
1446 os.unlink(name)
1447 except OSError, inst:
1448 if inst.errno != errno.ENOENT: raise
1449 repo.remove(names)
1444 repo.remove(names, unlink=True)
1450 1445
1451 1446 def rename(ui, repo, *pats, **opts):
1452 1447 """rename files; equivalent of copy + remove"""
@@ -1454,12 +1449,8 b' def rename(ui, repo, *pats, **opts):'
1454 1449 names = []
1455 1450 for abs, rel, exact in copied:
1456 1451 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1457 try:
1458 os.unlink(rel)
1459 except OSError, inst:
1460 if inst.errno != errno.ENOENT: raise
1461 1452 names.append(abs)
1462 repo.remove(names)
1453 repo.remove(names, unlink=True)
1463 1454 return errs
1464 1455
1465 1456 def revert(ui, repo, *names, **opts):
@@ -536,7 +536,13 b' class localrepository:'
536 536 else:
537 537 self.dirstate.forget([f])
538 538
539 def remove(self, list):
539 def remove(self, list, unlink=False):
540 if unlink:
541 for f in list:
542 try:
543 util.unlink(self.wjoin(f))
544 except OSError, inst:
545 if inst.errno != errno.ENOENT: raise
540 546 for f in list:
541 547 p = self.wjoin(f)
542 548 if os.path.exists(p):
@@ -1264,14 +1270,11 b' class localrepository:'
1264 1270 for f in remove:
1265 1271 self.ui.note(_("removing %s\n") % f)
1266 1272 try:
1267 os.unlink(self.wjoin(f))
1273 util.unlink(self.wjoin(f))
1268 1274 except OSError, inst:
1269 1275 if inst.errno != errno.ENOENT:
1270 1276 self.ui.warn(_("update failed to remove %s: %s!\n") %
1271 1277 (f, inst.strerror))
1272 # try removing directories that might now be empty
1273 try: os.removedirs(os.path.dirname(self.wjoin(f)))
1274 except: pass
1275 1278 if moddirstate:
1276 1279 if branch_merge:
1277 1280 self.dirstate.update(remove, 'r')
@@ -310,6 +310,13 b' def rename(src, dst):'
310 310 os.unlink(dst)
311 311 os.rename(src, dst)
312 312
313 def unlink(f):
314 """unlink and remove the directory if it is empty"""
315 os.unlink(f)
316 # try removing directories that might now be empty
317 try: os.removedirs(os.path.dirname(f))
318 except: pass
319
313 320 def copyfiles(src, dst, hardlink=None):
314 321 """Copy a directory tree using hardlinks if possible"""
315 322
General Comments 0
You need to be logged in to leave comments. Login now