@Override
    public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
        final AttributedList<Path> children = new AttributedList<Path>();
        try (RemoteDirectory handle = session.sftp().openDir(directory.getAbsolute())) {
            for(List<RemoteResourceInfo> list : ListUtils.partition(handle.scan(new RemoteResourceFilter() {
                        @Override
                        public boolean accept(RemoteResourceInfo remoteResourceInfo) {
                            return true;
                        }
                    }),
                    new HostPreferences(session.getHost()).getInteger("sftp.listing.chunksize"))) {
                for(RemoteResourceInfo f : list) {
                    final PathAttributes attr = attributes.toAttributes(f.getAttributes());
                    final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class);
                    switch(f.getAttributes().getType()) {
                        case DIRECTORY:
                            type.add(Path.Type.directory);
                            break;
                        case SYMLINK:
                            type.add(Path.Type.symboliclink);
                            break;
                        default:
                            type.add(Path.Type.file);
                            break;
                    }
                    final Path file = new Path(directory, f.getName(), type, attr);
                    if(this.post(file)) {
                        children.add(file);
                        listener.chunk(directory, children);
                    }
                }
            }
            return children;
        }
        catch(IOException e) {
            throw new SFTPExceptionMappingService().map("Listing directory {0} failed", e, directory);
        }
    }
@Test
    public void testInvalidSymlinkTarget() throws Exception {
        final Path home = new SFTPHomeDirectoryService(session).find();
        final Path file = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file, Path.Type.symboliclink));
        final String target = new AlphanumericRandomStringService().random();
        new SFTPSymlinkFeature(session).symlink(file, target);
        final AttributedList<Path> list = new SFTPListService(session).list(home, new DisabledListProgressListener());
        assertTrue(list.contains(file));
        assertEquals(new Path(home, target, EnumSet.of(Path.Type.file)), list.get(file).getSymlinkTarget());
        new SFTPDeleteFeature(session).delete(Collections.<Path>singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }