changeset 19002:5083baa6cbf8

largefiles: remove blecch from lfutil.copyandhash - don't close the passed fd
author Mads Kiilerich <madski@unity3d.com>
date Mon, 15 Apr 2013 23:43:50 +0200
parents 2a35296a6304
children ad993cb7bbb1
files hgext/largefiles/lfutil.py hgext/largefiles/localstore.py hgext/largefiles/remotestore.py
diffstat 3 files changed, 3 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py	Mon Apr 15 23:43:44 2013 +0200
+++ b/hgext/largefiles/lfutil.py	Mon Apr 15 23:43:50 2013 +0200
@@ -289,18 +289,11 @@
 
 def copyandhash(instream, outfile):
     '''Read bytes from instream (iterable) and write them to outfile,
-    computing the SHA-1 hash of the data along the way.  Close outfile
-    when done and return the hash.'''
+    computing the SHA-1 hash of the data along the way. Return the hash.'''
     hasher = util.sha1('')
     for data in instream:
         hasher.update(data)
         outfile.write(data)
-
-    # Blecch: closing a file that somebody else opened is rude and
-    # wrong. But it's so darn convenient and practical! After all,
-    # outfile was opened just to copy and hash.
-    outfile.close()
-
     return hasher.hexdigest()
 
 def hashrepofile(repo, file):
--- a/hgext/largefiles/localstore.py	Mon Apr 15 23:43:44 2013 +0200
+++ b/hgext/largefiles/localstore.py	Mon Apr 15 23:43:50 2013 +0200
@@ -45,6 +45,7 @@
             return lfutil.copyandhash(fd, tmpfile)
         finally:
             fd.close()
+            tmpfile.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)
--- a/hgext/largefiles/remotestore.py	Mon Apr 15 23:43:44 2013 +0200
+++ b/hgext/largefiles/remotestore.py	Mon Apr 15 23:43:50 2013 +0200
@@ -79,6 +79,7 @@
                                       tmpfile)
         finally:
             infile.close()
+            tmpfile.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)