@Test public void testDirectoryDownload() 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()); } @Override public boolean isFile() { return false; } @Override public boolean isDirectory() { return true; } }; final Path directory = new Path("t", EnumSet.of(Path.Type.directory)); final Path file = new Path(directory, name, EnumSet.of(Path.Type.file)); final TransferStatus directoryStatus = f.prepare(directory, local, new TransferStatus().exists(true), new DisabledProgressListener()); final TransferStatus fileStatus = f.prepare(file, new NullLocal(local, "f"), directoryStatus, new DisabledProgressListener()); assertNotNull(fileStatus.getRename().local); final String s = System.getProperty("file.separator"); assertEquals(String.format("%stmp%st-1%s%s", s, s, s, name), fileStatus.getRename().local.getAbsolute()); }
@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);  }