From 09929785b016b1c3659a8b52519519fddcfbb151 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 9 Aug 2023 05:43:59 -0400 Subject: [PATCH] fix: close open file handles in `pin_download` --- pins/boards.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pins/boards.py b/pins/boards.py index dc0cdb64..328c9a42 100644 --- a/pins/boards.py +++ b/pins/boards.py @@ -388,17 +388,16 @@ def pin_download(self, name, version=None, hash=None) -> Sequence[str]: # TODO: raise for multiple files # fetch file - f = load_file( + with load_file( meta, self.fs, self.construct_path([pin_name, meta.version.version]) - ) + ) as f: + # could also check whether f isinstance of PinCache + fname = getattr(f, "name", None) - # could also check whether f isinstance of PinCache - fname = getattr(f, "name", None) + if fname is None: + raise PinsError("pin_download requires a cache.") - if fname is None: - raise PinsError("pin_download requires a cache.") - - return [str(Path(fname).absolute())] + return [str(Path(fname).absolute())] def pin_upload( self,