'Moves temp-file into final destination
Raises:
PluginError if operation fails'

def output(self, task, entry, config):

    if ((u'file' not in entry) and (not task.options.test)):
        log.debug(u'file    missing,    entry:    %s', entry)
        raise plugin.PluginError((u'Entry    `%s`    has    no    temp    file    associated    with' % entry[u'title']))
    try:
        path = entry.get(u'path', config.get(u'path'))
        if (not isinstance(path, str)):
            raise plugin.PluginError((u'Invalid    `path`    in    entry    `%s`' % entry[u'title']))
        if task.options.dl_path:
            path = task.options.dl_path
        try:
            path = os.path.expanduser(entry.render(path))
        except RenderError as e:
            entry.fail((u'Could    not    set    path.    Error    during    string    replacement:    %s' % e))
            return
        path = pathscrub(path)
        if task.options.test:
            log.info(u'Would    write    `%s`    to    `%s`', entry[u'title'], path)
            entry[u'location'] = os.path.join(path, u'TEST_MODE_NO_OUTPUT')
            return
        if (not os.path.isdir(path)):
            log.debug(u'Creating    directory    %s', path)
            try:
                os.makedirs(path)
            except:
                raise plugin.PluginError((u'Cannot    create    path    %s' % path), log)
        if (not os.path.exists(entry[u'file'])):
            log.debug(u'entry:    %s', entry)
            raise plugin.PluginWarning((u"Downloaded    temp    file    `%s`    doesn't    exist!?" % entry[u'file']))
        if config.get(u'filename'):
            try:
                entry[u'filename'] = entry.render(config[u'filename'])
                log.debug((u'set    filename    from    config    %s' % entry[u'filename']))
            except RenderError as e:
                entry.fail((u'Could    not    set    filename.    Error    during    string    replacement:    %s' % e))
                return
        elif (not entry.get(u'filename')):
            entry[u'filename'] = entry[u'title']
            log.debug(u'set    filename    from    title    %s', entry[u'filename'])
            if (u'mime-type' not in entry):
                log.warning(u'Unable    to    figure    proper    filename    for    %s.    Using    title.', entry[u'title'])
            else:
                guess = mimetypes.guess_extension(entry[u'mime-type'])
                if (not guess):
                    log.warning(u'Unable    to    guess    extension    with    mime-type    %s', guess)
                else:
                    self.filename_ext_from_mime(entry)
        name = entry.get(u'filename', entry[u'title'])
        name = pathscrub(name)
        name = name.replace(u'/', u'    ')
        if sys.platform.startswith(u'win'):
            name = name.replace(u'\\', u'    ')
        name = u'    '.join(name.split())
        destfile = os.path.join(path, name)
        log.debug(u'destfile:    %s', destfile)
        if os.path.exists(destfile):
            import filecmp
            if filecmp.cmp(entry[u'file'], destfile):
                log.debug(u"Identical    destination    file    '%s'    already    exists", destfile)
            elif config.get(u'overwrite'):
                log.debug(u'Overwriting    already    existing    file    %s', destfile)
            else:
                log.info(u'File    `%s`    already    exists    and    is    not    identical,    download    failed.', destfile)
                entry.fail((u'File    `%s`    already    exists    and    is    not    identical.' % destfile))
                return
        else:
            log.debug(u'moving    %s    to    %s', entry[u'file'], destfile)
            try:
                shutil.move(entry[u'file'], destfile)
            except (IOError, OSError) as err:
                import errno
                if (not os.path.exists(destfile)):
                    raise plugin.PluginError((u'Unable    to    write    %s:    %s' % (destfile, err)))
                if ((err.errno != errno.EPERM) and (err.errno != errno.EACCES)):
                    raise
        entry[u'location'] = destfile
    finally:
        self.cleanup_temp_file(entry)
