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.
This commit is contained in:
2019-04-24 17:48:04 +02:00
parent f4d9573edc
commit f21caeb893

View File

@@ -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)