diff hgext/largefiles/basestore.py @ 30142:3dcaf1c4e90d

largefiles: use context for file closing Make the code slightly smaller and safer (and more deeply indented).
author Mads Kiilerich <madski@unity3d.com>
date Sat, 08 Oct 2016 00:59:41 +0200
parents 67999697221a
children f1cf6a745264
line wrap: on
line diff
--- a/hgext/largefiles/basestore.py	Sat Oct 08 00:59:40 2016 +0200
+++ b/hgext/largefiles/basestore.py	Sat Oct 08 00:59:41 2016 +0200
@@ -91,15 +91,13 @@
         storefilename = lfutil.storepath(self.repo, hash)
 
         tmpname = storefilename + '.tmp'
-        tmpfile = util.atomictempfile(tmpname,
-                                      createmode=self.repo.store.createmode)
-
-        try:
-            gothash = self._getfile(tmpfile, filename, hash)
-        except StoreError as err:
-            self.ui.warn(err.longmessage())
-            gothash = ""
-        tmpfile.close()
+        with util.atomictempfile(tmpname,
+                createmode=self.repo.store.createmode) as tmpfile:
+            try:
+                gothash = self._getfile(tmpfile, filename, hash)
+            except StoreError as err:
+                self.ui.warn(err.longmessage())
+                gothash = ""
 
         if gothash != hash:
             if gothash != "":