@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()); }
@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().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(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.rename(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; }
RenameFilter extends AbstractDownloadFilter { @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().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(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.rename(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; } }
RenameFilter extends AbstractDownloadFilter { @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().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(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.rename(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; } RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options); }
RenameFilter extends AbstractDownloadFilter { @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().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(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.rename(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; } RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress); }
RenameFilter extends AbstractDownloadFilter { @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().local != null) { status.rename(LocalFactory.get(parent.getRename().local, proposal)); } else { status.rename(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.rename(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; } RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress);  }