From f21caeb89321e3c028500f02bddb91b134f92bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 24 Apr 2019 17:48:04 +0200 Subject: [PATCH] Copy file: delete destination if it exists, before copying Copying onto a file that already exists isn't allowed when handling files on a Microsoft SMB share. --- flamenco_worker/commands.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flamenco_worker/commands.py b/flamenco_worker/commands.py index afcd84c..baba178 100644 --- a/flamenco_worker/commands.py +++ b/flamenco_worker/commands.py @@ -494,16 +494,18 @@ class CopyFileCommand(AbstractCommand): raise CommandExecutionError('Path %s does not exist, unable to copy' % src) dest = Path(settings['dest']) - if dest.exists(): - msg = 'Destination %s exists, going to overwrite it.' % dest - self._log.info(msg) - await self.worker.register_log('%s: %s', self.command_name, msg) self._log.info('Copying %s to %s', src, dest) await self.worker.register_log('%s: Copying %s to %s', self.command_name, src, dest) await self._mkdir_if_not_exists(dest.parent) + if dest.exists(): + msg = 'Destination %s exists, going to delete it first.' % dest + self._log.info(msg) + await self.worker.register_log('%s: %s', self.command_name, msg) + dest.unlink() + shutil.copy(str(src), str(dest)) self.worker.output_produced(dest)