@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));
                }
                final Path renamed = new Path(file.getParent(), proposal, file.getType());
                if(options.temporary) {
                    // Adjust final destination when uploading with temporary filename
                    status.getDisplayname().withRemote(renamed).exists(false);
                }
                else {
                    status.withRename(renamed);
                }
            }
            while(find.find(status.getRename().remote));
            if(log.isInfoEnabled()) {
                log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote));
            }
            if(log.isDebugEnabled()) {
                log.debug(String.format("Clear exist flag for file %s", file));
            }
            status.setExists(false);
        }
        else {
            if(parent.getRename().remote != null) {
                final Path renamed = new Path(parent.getRename().remote, file.getName(), file.getType());
                if(options.temporary) {
                    // Adjust final destination when uploading with temporary filename
                    status.getDisplayname().withRemote(renamed).exists(false);
                }
                else {
                    status.withRename(renamed);
                }
            }
            if(log.isInfoEnabled()) {
                log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote));
            }
        }
        return status;
    }
@Test
    public void testPrepare() throws Exception {
        RenameFilter f = new RenameFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())));
        final Path t = new Path("t", EnumSet.of(Path.Type.file));
        f.prepare(t, new NullLocal("t"), new TransferStatus(), new DisabledProgressListener());
        assertNotSame("t", t.getName());
    }