fix sync errors if multiple threads try and create the same folder, fix spawning 1 thread per sync task

This commit is contained in:
blushingpenguin 2021-06-04 07:56:34 +01:00
parent c1081c6678
commit e7fab75c17
2 changed files with 9 additions and 6 deletions

View File

@ -439,8 +439,9 @@ class DownloadQueueManager(object):
spawn_limit = max_downloads - len(self.worker_threads)
else:
spawn_limit = self._config.limit.downloads.concurrent_max
logger.info('%r tasks to do, can start at most %r threads', work_count, spawn_limit)
for i in range(0, min(work_count, spawn_limit)):
running = len(self.worker_threads)
logger.info('%r tasks to do, can start at most %r threads, %r threads currently running', work_count, spawn_limit, running)
for i in range(0, min(work_count, spawn_limit - running)):
# We have to create a new thread here, there's work to do
logger.info('Starting new worker thread.')

View File

@ -650,9 +650,11 @@ class MP3PlayerDevice(Device):
try:
folder.make_directory_with_parents(None)
except GLib.Error as err:
logger.error('Cannot create folder %s on MP3 player: %s', (folder % err.message))
self.cancel()
return False
# The sync might be multithreaded, so directories can be created by other threads
if not err.matches(Gio.io_error_quark(), Gio.IOErrorEnum.EXISTS):
logger.error('Cannot create folder %s on MP3 player: %s', (folder.get_uri() % err.message))
self.cancel()
return False
if not to_file.query_exists(None):
logger.info('Copying %s => %s',
@ -663,7 +665,7 @@ class MP3PlayerDevice(Device):
hookconvert = lambda current_bytes, total_bytes, user_data : reporthook(current_bytes, 1, total_bytes)
from_file.copy(to_file, Gio.FileCopyFlags.OVERWRITE, None, hookconvert, None)
except GLib.Error as err:
d = {'from_file': from_file, 'to_file': to_file, 'message': err.message}
d = {'from_file': from_file.get_uri(), 'to_file': to_file.get_uri(), 'message': err.message}
self.errors.append(_('Error copying %(from_file)s to %(to_file)s: %(message)s') % d)
self.cancel()
return False