##// END OF EJS Templates
util: fold ENOENT check into unlinkpath, controlled by new ignoremissing flag...
Mads Kiilerich -
r18143:242d2f4e default
parent child Browse files
Show More
@@ -36,11 +36,7 b' def reporemove(repo, list, unlink=False)'
36 36 try:
37 37 if unlink:
38 38 for f in list:
39 try:
40 util.unlinkpath(repo.wjoin(f))
41 except OSError, inst:
42 if inst.errno != errno.ENOENT:
43 raise
39 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
44 40 repo[None].forget(list)
45 41 finally:
46 42 wlock.release()
@@ -1329,11 +1329,7 b' class queue(object):'
1329 1329 # created while patching
1330 1330 for f in all_files:
1331 1331 if f not in repo.dirstate:
1332 try:
1333 util.unlinkpath(repo.wjoin(f))
1334 except OSError, inst:
1335 if inst.errno != errno.ENOENT:
1336 raise
1332 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
1337 1333 self.ui.warn(_('done\n'))
1338 1334 raise
1339 1335
@@ -1442,11 +1438,7 b' class queue(object):'
1442 1438 self.backup(repo, tobackup)
1443 1439
1444 1440 for f in a:
1445 try:
1446 util.unlinkpath(repo.wjoin(f))
1447 except OSError, e:
1448 if e.errno != errno.ENOENT:
1449 raise
1441 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
1450 1442 repo.dirstate.drop(f)
1451 1443 for f in m + r:
1452 1444 fctx = ctx[f]
@@ -4957,11 +4957,7 b' def remove(ui, repo, *pats, **opts):'
4957 4957 for f in list:
4958 4958 if f in added:
4959 4959 continue # we never unlink added files on remove
4960 try:
4961 util.unlinkpath(repo.wjoin(f))
4962 except OSError, inst:
4963 if inst.errno != errno.ENOENT:
4964 raise
4960 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
4965 4961 repo[None].forget(list)
4966 4962 finally:
4967 4963 wlock.release()
@@ -382,11 +382,10 b' def applyupdates(repo, action, wctx, mct'
382 382 if f == '.hgsubstate': # subrepo states need updating
383 383 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
384 384 try:
385 util.unlinkpath(repo.wjoin(f))
385 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
386 386 except OSError, inst:
387 if inst.errno != errno.ENOENT:
388 repo.ui.warn(_("update failed to remove %s: %s!\n") %
389 (f, inst.strerror))
387 repo.ui.warn(_("update failed to remove %s: %s!\n") %
388 (f, inst.strerror))
390 389 removed += 1
391 390 elif m == "m": # merge
392 391 if f == '.hgsubstate': # subrepo states need updating
@@ -439,11 +439,7 b' class fsbackend(abstractbackend):'
439 439 util.setflags(self._join(fname), False, True)
440 440
441 441 def unlink(self, fname):
442 try:
443 util.unlinkpath(self._join(fname))
444 except OSError, inst:
445 if inst.errno != errno.ENOENT:
446 raise
442 util.unlinkpath(self._join(fname), ignoremissing=True)
447 443
448 444 def writerej(self, fname, failed, total, lines):
449 445 fname = fname + ".rej"
@@ -443,9 +443,13 b' def termwidth():'
443 443 def makedir(path, notindexed):
444 444 os.mkdir(path)
445 445
446 def unlinkpath(f):
446 def unlinkpath(f, ignoremissing=False):
447 447 """unlink and remove the directory if it is empty"""
448 os.unlink(f)
448 try:
449 os.unlink(f)
450 except OSError, e:
451 if not (ignoremissing and e.errno == errno.ENOENT):
452 raise
449 453 # try removing directories that might now be empty
450 454 try:
451 455 os.removedirs(os.path.dirname(f))
@@ -275,9 +275,13 b' def _removedirs(name):'
275 275 break
276 276 head, tail = os.path.split(head)
277 277
278 def unlinkpath(f):
278 def unlinkpath(f, ignoremissing=False):
279 279 """unlink and remove the directory if it is empty"""
280 unlink(f)
280 try:
281 unlink(f)
282 except OSError, e:
283 if not (ignoremissing and e.errno == errno.ENOENT):
284 raise
281 285 # try removing directories that might now be empty
282 286 try:
283 287 _removedirs(os.path.dirname(f))
General Comments 0
You need to be logged in to leave comments. Login now