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