From 2dad632122091a430f244d3b2453068a3c837158 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 3 Feb 2020 19:29:27 -0800 Subject: [PATCH] If one handle gets permissionerror, close other one before return. --- voussoirkit/spinal.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index 9440cd6..5dd3160 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -409,7 +409,13 @@ def copy_file( log.debug('Opening handles.') source_handle = handlehelper(source, 'rb') destination_handle = handlehelper(destination, 'wb') - if None in (source_handle, destination_handle): + + if source_handle is None and destination_handle: + destination_handle.close() + return [destination, 0] + + if destination_handle is None: + source_handle.close() return [destination, 0] if validate_hash: