@Test public void testListJunction() throws Exception { final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname())); assumeTrue(Factory.Platform.getDefault().equals(Factory.Platform.Name.windows)); assertNotNull(session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback())); assertTrue(session.isConnected()); assertNotNull(session.getClient()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path home = new LocalHomeFinderFeature(session).find(); final AttributedList<Path> list = new LocalListService(session).list(home, new DisabledListProgressListener()); assertTrue(list.contains(new Path(home, "Recent", EnumSet.of(Path.Type.directory)))); final Path recent = list.get(new Path(home, "Recent", EnumSet.of(Path.Type.directory))); assertFalse(recent.attributes().getPermission().isReadable()); assertTrue(recent.attributes().getPermission().isExecutable()); try { new LocalListService(session).list(recent, new DisabledListProgressListener()); fail(); } catch(AccessDeniedException e) { } session.close(); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<ch.cyberduck.core.Path> paths = new AttributedList<>(); try (DirectoryStream<java.nio.file.Path> directoryStream = Files.newDirectoryStream(session.toPath(directory))) { for(java.nio.file.Path path : directoryStream) { if(null == path.getFileName()) { continue; } try { final PathAttributes attributes = feature.convert(path); final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class); if(Files.isDirectory(path)) { type.add(Path.Type.directory); } else { type.add(Path.Type.file); } final Path file = new Path(directory, path.getFileName().toString(), type, attributes); if(this.post(path, file)) { paths.add(file); listener.chunk(directory, paths); } } catch(IOException e) { log.warn(String.format("Failure reading attributes for %s", path)); } } } catch(IOException ex) { throw new LocalExceptionMappingService().map("Listing directory {0} failed", ex, directory); } return paths; }
LocalListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<ch.cyberduck.core.Path> paths = new AttributedList<>(); try (DirectoryStream<java.nio.file.Path> directoryStream = Files.newDirectoryStream(session.toPath(directory))) { for(java.nio.file.Path path : directoryStream) { if(null == path.getFileName()) { continue; } try { final PathAttributes attributes = feature.convert(path); final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class); if(Files.isDirectory(path)) { type.add(Path.Type.directory); } else { type.add(Path.Type.file); } final Path file = new Path(directory, path.getFileName().toString(), type, attributes); if(this.post(path, file)) { paths.add(file); listener.chunk(directory, paths); } } catch(IOException e) { log.warn(String.format("Failure reading attributes for %s", path)); } } } catch(IOException ex) { throw new LocalExceptionMappingService().map("Listing directory {0} failed", ex, directory); } return paths; } }
LocalListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<ch.cyberduck.core.Path> paths = new AttributedList<>(); try (DirectoryStream<java.nio.file.Path> directoryStream = Files.newDirectoryStream(session.toPath(directory))) { for(java.nio.file.Path path : directoryStream) { if(null == path.getFileName()) { continue; } try { final PathAttributes attributes = feature.convert(path); final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class); if(Files.isDirectory(path)) { type.add(Path.Type.directory); } else { type.add(Path.Type.file); } final Path file = new Path(directory, path.getFileName().toString(), type, attributes); if(this.post(path, file)) { paths.add(file); listener.chunk(directory, paths); } } catch(IOException e) { log.warn(String.format("Failure reading attributes for %s", path)); } } } catch(IOException ex) { throw new LocalExceptionMappingService().map("Listing directory {0} failed", ex, directory); } return paths; } LocalListService(final LocalSession session); }
LocalListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<ch.cyberduck.core.Path> paths = new AttributedList<>(); try (DirectoryStream<java.nio.file.Path> directoryStream = Files.newDirectoryStream(session.toPath(directory))) { for(java.nio.file.Path path : directoryStream) { if(null == path.getFileName()) { continue; } try { final PathAttributes attributes = feature.convert(path); final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class); if(Files.isDirectory(path)) { type.add(Path.Type.directory); } else { type.add(Path.Type.file); } final Path file = new Path(directory, path.getFileName().toString(), type, attributes); if(this.post(path, file)) { paths.add(file); listener.chunk(directory, paths); } } catch(IOException e) { log.warn(String.format("Failure reading attributes for %s", path)); } } } catch(IOException ex) { throw new LocalExceptionMappingService().map("Listing directory {0} failed", ex, directory); } return paths; } LocalListService(final LocalSession session); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); }
LocalListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<ch.cyberduck.core.Path> paths = new AttributedList<>(); try (DirectoryStream<java.nio.file.Path> directoryStream = Files.newDirectoryStream(session.toPath(directory))) { for(java.nio.file.Path path : directoryStream) { if(null == path.getFileName()) { continue; } try { final PathAttributes attributes = feature.convert(path); final EnumSet<Path.Type> type = EnumSet.noneOf(Path.Type.class); if(Files.isDirectory(path)) { type.add(Path.Type.directory); } else { type.add(Path.Type.file); } final Path file = new Path(directory, path.getFileName().toString(), type, attributes); if(this.post(path, file)) { paths.add(file); listener.chunk(directory, paths); } } catch(IOException e) { log.warn(String.format("Failure reading attributes for %s", path)); } } } catch(IOException ex) { throw new LocalExceptionMappingService().map("Listing directory {0} failed", ex, directory); } return paths; } LocalListService(final LocalSession session); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener);  }