posix: use local reference to unlink
We have a local reference to os.unlink in module scope, but we still used
os.unlink inside functions. This changes util to use the local reference,
which will pave the way for combining duplicated code in future patches.
--- a/mercurial/posix.py Tue Mar 21 06:50:42 2017 -0700
+++ b/mercurial/posix.py Tue Mar 21 06:50:28 2017 -0700
@@ -105,7 +105,7 @@
fp = open(f)
data = fp.read()
fp.close()
- os.unlink(f)
+ unlink(f)
try:
os.symlink(data, f)
except OSError:
@@ -118,7 +118,7 @@
if stat.S_ISLNK(s):
# switch link to file
data = os.readlink(f)
- os.unlink(f)
+ unlink(f)
fp = open(f, "w")
fp.write(data)
fp.close()
@@ -187,9 +187,9 @@
# check-exec is exec and check-no-exec is not exec
return True
# checknoexec exists but is exec - delete it
- os.unlink(checknoexec)
+ unlink(checknoexec)
# checkisexec exists but is not exec - delete it
- os.unlink(checkisexec)
+ unlink(checkisexec)
# check using one file, leave it as checkisexec
checkdir = cachedir
@@ -210,7 +210,7 @@
return True
finally:
if fn is not None:
- os.unlink(fn)
+ unlink(fn)
except (IOError, OSError):
# we don't care, the user probably won't be able to commit anyway
return False
@@ -248,12 +248,12 @@
try:
os.symlink(target, name)
if cachedir is None:
- os.unlink(name)
+ unlink(name)
else:
try:
os.rename(name, checklink)
except OSError:
- os.unlink(name)
+ unlink(name)
return True
except OSError as inst:
# link creation might race, try again
@@ -268,7 +268,7 @@
except OSError as inst:
# sshfs might report failure while successfully creating the link
if inst[0] == errno.EIO and os.path.exists(name):
- os.unlink(name)
+ unlink(name)
return False
def checkosfilename(path):
@@ -539,7 +539,7 @@
def unlinkpath(f, ignoremissing=False):
"""unlink and remove the directory if it is empty"""
try:
- os.unlink(f)
+ unlink(f)
except OSError as e:
if not (ignoremissing and e.errno == errno.ENOENT):
raise