@Override
    public void apply(final Path file, final Local local, final TransferStatus status,
                      final ProgressListener listener) throws BackgroundException {
        if(status.isExists()) {
            if(local.attributes().getSize() == 0) {
                // Placeholder from drag operation
                log.warn(String.format("Skip renaming placeholder file %s", local));
            }
            else {
                Local rename;
                do {
                    String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.download.file.rename.format"),
                        FilenameUtils.getBaseName(file.getName()),
                        UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(local.getDelimiter(), '-').replace(':', '-'),
                        StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY);
                    rename = LocalFactory.get(local.getParent().getAbsolute(), proposal);
                }
                while(rename.exists());
                if(log.isInfoEnabled()) {
                    log.info(String.format("Rename existing file %s to %s", local, rename));
                }
                LocalFactory.get(local.getAbsolute()).rename(rename);
                if(log.isDebugEnabled()) {
                    log.debug(String.format("Clear exist flag for file %s", local));
                }
                status.setExists(false);
            }
        }
        super.apply(file, local, status, listener);
    }
@Test
    public void testPrepare() throws Exception {
        final Host host = new Host(new TestProtocol());
        final DownloadFilterOptions options = new DownloadFilterOptions(host);
        options.icon = false;
        RenameExistingFilter f = new RenameExistingFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(host),
            options);
        final String name = new AsciiRandomStringService().random();
        final Local local = new NullLocal(System.getProperty("java.io.tmpdir"), name) {
            @Override
            public boolean exists() {
                return false;
            }

            @Override
            public void rename(final Local renamed) {
                // Must not rename original file but copy
                fail();
            }
        };
        final Path p = new Path(name, EnumSet.of(Path.Type.file));
        final TransferStatus status = f.prepare(p, local, new TransferStatus(), new DisabledProgressListener());
        assertNull(status.getRename().local);
        assertFalse(status.isExists());
        f.apply(p, local, new TransferStatus(), new DisabledProgressListener());
    }