Mercurial > public > mercurial-scm > hg-stable
diff hgext/largefiles/remotestore.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 | 0ccab84f9630 |
children | 736f92c44656 |
line wrap: on
line diff
--- a/hgext/largefiles/remotestore.py Sat Oct 08 00:59:40 2016 +0200 +++ b/hgext/largefiles/remotestore.py Sat Oct 08 00:59:41 2016 +0200 @@ -45,17 +45,13 @@ def sendfile(self, filename, hash): self.ui.debug('remotestore: sendfile(%s, %s)\n' % (filename, hash)) - fd = None try: - fd = lfutil.httpsendfile(self.ui, filename) - return self._put(hash, fd) + with lfutil.httpsendfile(self.ui, filename) as fd: + return self._put(hash, fd) except IOError as e: raise error.Abort( _('remotestore: could not open file %s: %s') % (filename, str(e))) - finally: - if fd: - fd.close() def _getfile(self, tmpfile, filename, hash): try: