largefiles: simplify lfutil.writehash
This was unnecessarily verbose: there is no need to unlink the file
when we open it for write anyway, and there is no need to check if the
file exists after we created it.
--- a/hgext/largefiles/lfutil.py Thu Nov 24 18:22:44 2011 +0100
+++ b/hgext/largefiles/lfutil.py Thu Nov 24 18:22:45 2011 +0100
@@ -393,17 +393,8 @@
def writehash(hash, filename, executable):
util.makedirs(os.path.dirname(filename))
- if os.path.exists(filename):
- os.unlink(filename)
- wfile = open(filename, 'wb')
-
- try:
- wfile.write(hash)
- wfile.write('\n')
- finally:
- wfile.close()
- if os.path.exists(filename):
- os.chmod(filename, getmode(executable))
+ util.writefile(filename, hash + '\n')
+ os.chmod(filename, getmode(executable))
def getexecutable(filename):
mode = os.stat(filename).st_mode