diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index 81e3caa..29c39e5 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -489,15 +489,18 @@ def copy_file( else: raise + log.loud('Copying file %s', source.absolute_path) log.loud('Opening source handle.') source_handle = handlehelper(source, 'rb') - log.loud('Opening dest handle.') - destination_handle = handlehelper(destination, 'wb') - - if source_handle is None and destination_handle: - destination_handle.close() + if source_handle is None: return results + if portalocker is not None: + log.loud('Locking source file.') + portalocker.lock(source_handle, portalocker.LockFlags.EXCLUSIVE) + + log.loud('Opening dest handle.') + destination_handle = handlehelper(destination, 'wb') if destination_handle is None: source_handle.close() return results @@ -512,9 +515,6 @@ def copy_file( if dynamic_chunk_size: chunk_size = bytestring.MEBIBYTE - if portalocker is not None: - portalocker.lock(source_handle, portalocker.LockFlags.EXCLUSIVE) - while True: chunk_start = time.perf_counter()