@Test public void testDelete() throws Exception { final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path file = new Path(new LocalHomeFinderFeature(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new LocalTouchFeature(session).touch(file, new TransferStatus()); final Path folder = new Path(new LocalHomeFinderFeature(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory)); new LocalDirectoryFeature(session).mkdir(folder, null, new TransferStatus()); new LocalDeleteFeature(session).delete(new ArrayList<>(Arrays.asList(file, folder)), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(Files.exists(session.toPath(file))); assertFalse(Files.exists(session.toPath(folder.getAbsolute()))); }
@Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files.keySet()) { if(file.isFile() || file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } for(Path file : files.keySet()) { if(file.isDirectory() && !file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } }
LocalDeleteFeature implements Delete { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files.keySet()) { if(file.isFile() || file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } for(Path file : files.keySet()) { if(file.isDirectory() && !file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } } }
LocalDeleteFeature implements Delete { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files.keySet()) { if(file.isFile() || file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } for(Path file : files.keySet()) { if(file.isDirectory() && !file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } } LocalDeleteFeature(final LocalSession session); }
LocalDeleteFeature implements Delete { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files.keySet()) { if(file.isFile() || file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } for(Path file : files.keySet()) { if(file.isDirectory() && !file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } } LocalDeleteFeature(final LocalSession session); @Override void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback); }
LocalDeleteFeature implements Delete { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException { for(Path file : files.keySet()) { if(file.isFile() || file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } for(Path file : files.keySet()) { if(file.isDirectory() && !file.isSymbolicLink()) { callback.delete(file); try { Files.delete(session.toPath(file)); } catch(IOException e) { throw new LocalExceptionMappingService().map("Cannot delete {0}", e, file); } } } } LocalDeleteFeature(final LocalSession session); @Override void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback);  }