Patchwork [3,of,4] vfs: ensure closewrapbase fh doesn't escape by entering context manager

login
register
mail settings
Submitter Matt Harbison
Date Dec. 15, 2018, 8:04 p.m.
Message ID <847613113d3ac24106fc.1544904266@Envy>
Download mbox | patch
Permalink /patch/37192/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 15, 2018, 8:04 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1544900077 18000
#      Sat Dec 15 13:54:37 2018 -0500
# Node ID 847613113d3ac24106fcd3ca727428b6e02022ae
# Parent  d40ef8f0cd2cce5b41e48924fc2a3d486b4c534d
vfs: ensure closewrapbase fh doesn't escape by entering context manager

I'm not sure if there's a problem in practice here, as there's no test failure
either way.  The __exit__() and close() methods raise an exception, so maybe
__exit__() and close() are being called directly on the underlying handle when
delayclosedfile is used on a context manager?  I doubt that was intended.

Patch

diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -525,7 +525,8 @@  class closewrapbase(object):
         return delattr(self._origfh, attr)
 
     def __enter__(self):
-        return self._origfh.__enter__()
+        self._origfh.__enter__()
+        return self
 
     def __exit__(self, exc_type, exc_value, exc_tb):
         raise NotImplementedError('attempted instantiating ' + str(type(self)))