@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()); }
@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)); } if(parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while(find.withCache(cache).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) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if(log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; }
RenameFilter extends AbstractUploadFilter { @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)); } if(parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while(find.withCache(cache).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) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if(log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; } }
RenameFilter extends AbstractUploadFilter { @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)); } if(parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while(find.withCache(cache).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) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if(log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; } RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session,
                        final UploadFilterOptions options); }
RenameFilter extends AbstractUploadFilter { @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)); } if(parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while(find.withCache(cache).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) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if(log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; } RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session,
                        final UploadFilterOptions options); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress); }
RenameFilter extends AbstractUploadFilter { @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)); } if(parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while(find.withCache(cache).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) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if(log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; } RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Local> symlinkResolver, final Session<?> session,
                        final UploadFilterOptions options); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress);  }