Use portalocker to lock files that are being copied by spinal.

This commit is contained in:
voussoir 2022-11-20 13:30:38 -08:00
parent e275cbaef1
commit 1a19d608c6
2 changed files with 12 additions and 1 deletions

View file

@ -11,9 +11,10 @@ setuptools.setup(
long_description_content_type='text/markdown',
url='https://github.com/voussoir/voussoirkit',
install_requires=[
'exifread',
'portalocker',
'pyperclip',
'python-dateutil',
'exifread',
'pywin32;platform_system=="Windows"',
'winshell;platform_system=="Windows"',
]

View file

@ -5,6 +5,10 @@ copying files and folders.
import collections
import hashlib
import os
try:
import portalocker
except ImportError:
portalocker = None
import shutil
import time
@ -508,6 +512,9 @@ 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()
@ -539,6 +546,9 @@ def copy_file(
chunk_time = time.perf_counter() - chunk_start
chunk_size = dynamic_chunk_sizer(chunk_size, chunk_time, IDEAL_CHUNK_TIME)
if portalocker is not None:
portalocker.unlock(source_handle)
progressbar.done()
# Fin