@Test public void testDirectoryUpload() throws Exception { final Path directory = new Path("/t", EnumSet.of(Path.Type.directory)); final Path file = new Path(directory, "f", EnumSet.of(Path.Type.file)); final AtomicBoolean found = new AtomicBoolean(); final AtomicBoolean moved = new AtomicBoolean(); final AttributesFinder attributes = new AttributesFinder() { @Override public PathAttributes find(final Path file) { return new PathAttributes(); } }; final Find find = new Find() { @Override public boolean find(final Path f) { if(f.equals(directory)) { found.set(true); return true; } return false; } }; final NullSession session = new NullSession(new Host(new TestProtocol())); final RenameFilter f = new RenameFilter(new DisabledUploadSymlinkResolver(), session); f.withFinder(find).withAttributes(attributes); final TransferStatus directoryStatus = f.prepare(directory, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener()); assertTrue(found.get()); assertNotNull(directoryStatus.getRename()); assertNull(directoryStatus.getRename().local); assertNotNull(directoryStatus.getRename().remote); final TransferStatus fileStatus = f.prepare(file, new NullLocal("t/f"), directoryStatus, new DisabledProgressListener()); assertNotNull(fileStatus.getRename()); assertNull(fileStatus.getRename().local); assertNotNull(fileStatus.getRename().remote); assertEquals(new Path("/t-1/f", EnumSet.of(Path.Type.file)), fileStatus.getRename().remote); }
@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);  }