# HG changeset patch # User Martin Geisler # Date 2011-11-24 17:22:45 # Node ID c9328c829cd9fb17311d5a5c94687911e5660172 # Parent a5e5c64cd90b3f1bd87d0d2834e997cec0c59e2e 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. diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py --- a/hgext/largefiles/lfutil.py +++ b/hgext/largefiles/lfutil.py @@ -393,17 +393,8 @@ def readhash(filename): 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