@Test public void testSearchInDirectory() throws Exception { final Path workdir = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); workdir.attributes().setRegion("us-east-1"); final String name = new AlphanumericRandomStringService().random(); final Path file = new Path(workdir, name, EnumSet.of(Path.Type.file)); session.getFeature(Touch.class).touch(file, new TransferStatus()); final S3SearchFeature feature = new S3SearchFeature(session); assertTrue(feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).contains(file)); { final AttributedList<Path> result = feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()); assertTrue(result.contains(file)); } assertFalse(feature.search(new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new SearchFilter(name), new DisabledListProgressListener()).contains(file)); final Path subdir = new S3DirectoryFeature(session, new S3WriteFeature(session)).mkdir(new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertFalse(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); final Path filesubdir = new S3TouchFeature(session).touch(new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); { final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()), new DisabledListProgressListener()); assertNotNull(result.find(new SimplePathPredicate(filesubdir))); assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent()); } new S3DefaultDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> objects; try { objects = new S3ObjectListService(session).list(workdir, listener, null, PreferencesFactory.get().getInteger("s3.listing.chunksize")); } catch(NotfoundException e) { return AttributedList.emptyList(); } final Set<Path> removal = new HashSet<>(); for(final Path f : objects) { if(!f.getName().contains(regex.toPattern().pattern())) { removal.add(f); } } objects.removeAll(removal); return objects; }
S3SearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> objects; try { objects = new S3ObjectListService(session).list(workdir, listener, null, PreferencesFactory.get().getInteger("s3.listing.chunksize")); } catch(NotfoundException e) { return AttributedList.emptyList(); } final Set<Path> removal = new HashSet<>(); for(final Path f : objects) { if(!f.getName().contains(regex.toPattern().pattern())) { removal.add(f); } } objects.removeAll(removal); return objects; } }
S3SearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> objects; try { objects = new S3ObjectListService(session).list(workdir, listener, null, PreferencesFactory.get().getInteger("s3.listing.chunksize")); } catch(NotfoundException e) { return AttributedList.emptyList(); } final Set<Path> removal = new HashSet<>(); for(final Path f : objects) { if(!f.getName().contains(regex.toPattern().pattern())) { removal.add(f); } } objects.removeAll(removal); return objects; } S3SearchFeature(final S3Session session); }
S3SearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> objects; try { objects = new S3ObjectListService(session).list(workdir, listener, null, PreferencesFactory.get().getInteger("s3.listing.chunksize")); } catch(NotfoundException e) { return AttributedList.emptyList(); } final Set<Path> removal = new HashSet<>(); for(final Path f : objects) { if(!f.getName().contains(regex.toPattern().pattern())) { removal.add(f); } } objects.removeAll(removal); return objects; } S3SearchFeature(final S3Session session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache); }
S3SearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> objects; try { objects = new S3ObjectListService(session).list(workdir, listener, null, PreferencesFactory.get().getInteger("s3.listing.chunksize")); } catch(NotfoundException e) { return AttributedList.emptyList(); } final Set<Path> removal = new HashSet<>(); for(final Path f : objects) { if(!f.getName().contains(regex.toPattern().pattern())) { removal.add(f); } } objects.removeAll(removal); return objects; } S3SearchFeature(final S3Session session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache);  }