@Override
    public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException {
        final TransferStatus status = super.prepare(file, local, parent, progress);
        if(status.isExists()) {
            final String filename = file.getName();
            int no = 0;
            do {
                String proposal = String.format("%s-%d", FilenameUtils.getBaseName(filename), ++no);
                if(StringUtils.isNotBlank(Path.getExtension(filename))) {
                    proposal += String.format(".%s", Path.getExtension(filename));
                }
                status.withRename(LocalFactory.get(local.getParent(), proposal));
            }
            while(status.getRename().local.exists());
            if(log.isInfoEnabled()) {
                log.info(String.format("Changed download target from %s to %s", local, status.getRename().local));
            }
            if(log.isDebugEnabled()) {
                log.debug(String.format("Clear exist flag for file %s", local));
            }
            status.setExists(false);
        }
        else {
            if(parent.getRename().local != null) {
                status.withRename(LocalFactory.get(parent.getRename().local, file.getName()));
            }
            if(log.isInfoEnabled()) {
                log.info(String.format("Changed download target from %s to %s", local, status.getRename().local));
            }
        }
        return status;
    }
@Test
    public void testPrepare() throws Exception {
        RenameFilter f = new RenameFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol())));
        final String name = new AsciiRandomStringService().random();
        final NullLocal local = new NullLocal("/tmp", name) {
            @Override
            public boolean exists() {
                return name.equals(this.getName());
            }
        };
        final Path t = new Path(name, EnumSet.of(Path.Type.file));
        final TransferStatus status = f.prepare(t, local, new TransferStatus().exists(true), new DisabledProgressListener());
        assertNotNull(status.getRename().local);
        assertEquals(String.format("%s-1", name), status.getRename().local.getName());
    }