Attempt to lock source file before attempting to open dest.
This commit is contained in:
parent
1a19d608c6
commit
65d0f6f4d1
1 changed files with 8 additions and 8 deletions
|
@ -489,15 +489,18 @@ def copy_file(
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
log.loud('Copying file %s', source.absolute_path)
|
||||||
log.loud('Opening source handle.')
|
log.loud('Opening source handle.')
|
||||||
source_handle = handlehelper(source, 'rb')
|
source_handle = handlehelper(source, 'rb')
|
||||||
log.loud('Opening dest handle.')
|
if source_handle is None:
|
||||||
destination_handle = handlehelper(destination, 'wb')
|
|
||||||
|
|
||||||
if source_handle is None and destination_handle:
|
|
||||||
destination_handle.close()
|
|
||||||
return results
|
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:
|
if destination_handle is None:
|
||||||
source_handle.close()
|
source_handle.close()
|
||||||
return results
|
return results
|
||||||
|
@ -512,9 +515,6 @@ def copy_file(
|
||||||
if dynamic_chunk_size:
|
if dynamic_chunk_size:
|
||||||
chunk_size = bytestring.MEBIBYTE
|
chunk_size = bytestring.MEBIBYTE
|
||||||
|
|
||||||
if portalocker is not None:
|
|
||||||
portalocker.lock(source_handle, portalocker.LockFlags.EXCLUSIVE)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
chunk_start = time.perf_counter()
|
chunk_start = time.perf_counter()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue