From 9f9466ee3e07e159c276af57ddf92a8d1e5ac126 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sat, 1 Jan 2022 12:57:34 -0600 Subject: [PATCH] Add compat.mmap.close to set _bup_closed and always inititalize it Add a compat.mmap.close method that properly maintains the _bup_closed value, and make sure it always exists. Signed-off-by: Rob Browning Tested-by: Rob Browning --- lib/bup/compat.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bup/compat.py b/lib/bup/compat.py index dfeb51a..9def12a 100644 --- a/lib/bup/compat.py +++ b/lib/bup/compat.py @@ -231,16 +231,19 @@ else: # Python 2 class mmap(py_mmap.mmap): def __init__(self, *args, **kwargs): - self._bup_closed = False + self._bup_closed = True # Silence deprecation warnings. mmap's current parent is # object, which accepts no params and as of at least 2.7 # warns about them. if py_mmap.mmap.__init__ is not object.__init__: super(mmap, self).__init__(self, *args, **kwargs) + self._bup_closed = False + def close(self): + self._bup_closed = True + super(mmap, self).close() def __enter__(self): return self def __exit__(self, type, value, traceback): - self._bup_closed = True with pending_raise(value, rethrow=False): self.close() def __del__(self): -- 2.39.2