changeset 15574:c9328c829cd9

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.
author Martin Geisler <mg@aragost.com>
date Thu, 24 Nov 2011 18:22:45 +0100
parents a5e5c64cd90b
children ad686c818e1c
files hgext/largefiles/lfutil.py
diffstat 1 files changed, 2 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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