Patchwork [05,of,13] largefiles: remove blecch from lfutil.copyandhash - don't close the passed fd

login
register
mail settings
Submitter Mads Kiilerich
Date April 16, 2013, 2:43 a.m.
Message ID <ac3a22732f6b00c73018.1366080202@mk-desktop>
Download mbox | patch
Permalink /patch/1333/
State Accepted
Commit 5083baa6cbf8bb210c9a0612f992359c76747582
Headers show

Comments

Mads Kiilerich - April 16, 2013, 2:43 a.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1366062230 -7200
#      Mon Apr 15 23:43:50 2013 +0200
# Node ID ac3a22732f6b00c7301836016110b73c0383709e
# Parent  2b554516b0868563d22f3907ca3498ce970725b0
largefiles: remove blecch from lfutil.copyandhash - don't close the passed fd

Patch

diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -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):
diff --git a/hgext/largefiles/localstore.py b/hgext/largefiles/localstore.py
--- a/hgext/largefiles/localstore.py
+++ b/hgext/largefiles/localstore.py
@@ -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)
diff --git a/hgext/largefiles/remotestore.py b/hgext/largefiles/remotestore.py
--- a/hgext/largefiles/remotestore.py
+++ b/hgext/largefiles/remotestore.py
@@ -79,6 +79,7 @@ 
                                       tmpfile)
         finally:
             infile.close()
+            tmpfile.close()
 
     def _verifyfile(self, cctx, cset, contents, standin, verified):
         filename = lfutil.splitstandin(standin)