@Test public void testCompile() throws Exception { final Session session = new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == Delete.class) { return (T) new Delete() { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) { assertEquals(new Path("/t/a", EnumSet.of(Path.Type.file)), new ArrayList<>(files.keySet()).get(0)); assertEquals(new Path("/t/d/b", EnumSet.of(Path.Type.file)), new ArrayList<>(files.keySet()).get(1)); assertEquals(new Path("/t/d", EnumSet.of(Path.Type.directory)), new ArrayList<>(files.keySet()).get(2)); assertEquals(new Path("/t", EnumSet.of(Path.Type.directory)), new ArrayList<>(files.keySet()).get(3)); } @Override public boolean isRecursive() { return false; } }; } return super._getFeature(type); } @Override public AttributedList<Path> list(final Path file, final ListProgressListener listener) { if(file.equals(new Path("/t", EnumSet.of(Path.Type.directory)))) { return new AttributedList<Path>(Arrays.asList( new Path("/t/a", EnumSet.of(Path.Type.file)), new Path("/t/d", EnumSet.of(Path.Type.directory)) )); } if(file.equals(new Path("/t/d", EnumSet.of(Path.Type.directory)))) { return new AttributedList<Path>(Collections.singletonList( new Path("/t/d/b", EnumSet.of(Path.Type.file)) )); } fail(); return null; } }; final DeleteWorker worker = new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(new Path("/t", EnumSet.of(Path.Type.directory))), PathCache.empty(), new DisabledProgressListener()); assertEquals(4, worker.run(session).size()); }
protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException { final Map<Path, TransferStatus> recursive = new LinkedHashMap<>(); if(file.isFile() || file.isSymbolicLink()) { final Path copy = new Path(file); switch(host.getProtocol().getType()) { case s3: if(!file.attributes().isDuplicate()) { if(!file.getType().contains(Path.Type.upload)) { log.debug(String.format("Nullify version to add delete marker for %s", file)); copy.attributes().setVersionId(null); } } } recursive.put(copy, new TransferStatus().withLockId(this.getLockId(copy))); } else if(file.isDirectory()) { if(!delete.isRecursive()) { for(Path child : list.list(file, listener).filter(filter)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(host, delete, list, listener, child)); } } recursive.put(file, new TransferStatus().withLockId(this.getLockId(file))); } return recursive; }
DeleteWorker extends Worker<List<Path>> { protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException { final Map<Path, TransferStatus> recursive = new LinkedHashMap<>(); if(file.isFile() || file.isSymbolicLink()) { final Path copy = new Path(file); switch(host.getProtocol().getType()) { case s3: if(!file.attributes().isDuplicate()) { if(!file.getType().contains(Path.Type.upload)) { log.debug(String.format("Nullify version to add delete marker for %s", file)); copy.attributes().setVersionId(null); } } } recursive.put(copy, new TransferStatus().withLockId(this.getLockId(copy))); } else if(file.isDirectory()) { if(!delete.isRecursive()) { for(Path child : list.list(file, listener).filter(filter)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(host, delete, list, listener, child)); } } recursive.put(file, new TransferStatus().withLockId(this.getLockId(file))); } return recursive; } }
DeleteWorker extends Worker<List<Path>> { protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException { final Map<Path, TransferStatus> recursive = new LinkedHashMap<>(); if(file.isFile() || file.isSymbolicLink()) { final Path copy = new Path(file); switch(host.getProtocol().getType()) { case s3: if(!file.attributes().isDuplicate()) { if(!file.getType().contains(Path.Type.upload)) { log.debug(String.format("Nullify version to add delete marker for %s", file)); copy.attributes().setVersionId(null); } } } recursive.put(copy, new TransferStatus().withLockId(this.getLockId(copy))); } else if(file.isDirectory()) { if(!delete.isRecursive()) { for(Path child : list.list(file, listener).filter(filter)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(host, delete, list, listener, child)); } } recursive.put(file, new TransferStatus().withLockId(this.getLockId(file))); } return recursive; } DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final ProgressListener listener);  DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final Filter<Path> filter, final ProgressListener listener); }
DeleteWorker extends Worker<List<Path>> { protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException { final Map<Path, TransferStatus> recursive = new LinkedHashMap<>(); if(file.isFile() || file.isSymbolicLink()) { final Path copy = new Path(file); switch(host.getProtocol().getType()) { case s3: if(!file.attributes().isDuplicate()) { if(!file.getType().contains(Path.Type.upload)) { log.debug(String.format("Nullify version to add delete marker for %s", file)); copy.attributes().setVersionId(null); } } } recursive.put(copy, new TransferStatus().withLockId(this.getLockId(copy))); } else if(file.isDirectory()) { if(!delete.isRecursive()) { for(Path child : list.list(file, listener).filter(filter)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(host, delete, list, listener, child)); } } recursive.put(file, new TransferStatus().withLockId(this.getLockId(file))); } return recursive; } DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final ProgressListener listener);  DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final Filter<Path> filter, final ProgressListener listener); @Override List<Path> run(final Session<?> session); @Override void cleanup(final List<Path> deleted); @Override String getActivity(); @Override List<Path> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
DeleteWorker extends Worker<List<Path>> { protected Map<Path, TransferStatus> compile(final Host host, final Delete delete, final ListService list, final ListProgressListener listener, final Path file) throws BackgroundException { final Map<Path, TransferStatus> recursive = new LinkedHashMap<>(); if(file.isFile() || file.isSymbolicLink()) { final Path copy = new Path(file); switch(host.getProtocol().getType()) { case s3: if(!file.attributes().isDuplicate()) { if(!file.getType().contains(Path.Type.upload)) { log.debug(String.format("Nullify version to add delete marker for %s", file)); copy.attributes().setVersionId(null); } } } recursive.put(copy, new TransferStatus().withLockId(this.getLockId(copy))); } else if(file.isDirectory()) { if(!delete.isRecursive()) { for(Path child : list.list(file, listener).filter(filter)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } recursive.putAll(this.compile(host, delete, list, listener, child)); } } recursive.put(file, new TransferStatus().withLockId(this.getLockId(file))); } return recursive; } DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final ProgressListener listener);  DeleteWorker(final LoginCallback prompt, final List<Path> files, final Cache<Path> cache, final Filter<Path> filter, final ProgressListener listener); @Override List<Path> run(final Session<?> session); @Override void cleanup(final List<Path> deleted); @Override String getActivity(); @Override List<Path> initialize(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }