@Override public void cleanup(final List<TransferItem> list) { cache.put(directory, new AttributedList<TransferItem>(list)); filter(); } }
/** * @param comparator The comparator to use * @param filter Filter * @return Filtered list sorted with comparator */ public AttributedList<E> filter(final Comparator<E> comparator, final Filter<E> filter) { final AttributedList<E> filtered = new AttributedList<>(impl); if(null != comparator) { this.doSort(filtered.impl, comparator); } if(null != filter) { if(log.isDebugEnabled()) { log.debug(String.format("Filter list %s with filter %s", this, filter)); } filtered.impl.removeIf(new Predicate<E>() { @Override public boolean test(final E e) { return !filter.accept(e); } }); } return filtered; }
public AttributedList<Local> list(final String path, final Filter<String> filter) throws AccessDeniedException { final AttributedList<Local> children = new AttributedList<Local>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(path), new DirectoryStream.Filter<Path>() { @Override public boolean accept(final Path entry) { if(null == entry.getFileName()) { return false; } return filter.accept(entry.getFileName().toString()); } })) { for(Path entry : stream) { children.add(LocalFactory.get(entry.toString())); } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Listing directory {0} failed", "Error"), this.getName()), e); } return children; }
@Override public Transfer withCache(final Cache<Path> cache) { this.cache = cache; // Populate cache for root items. See #8712 for(TransferItem root : roots) { if(!root.remote.isRoot()) { cache.put(root.remote.getParent(), new AttributedList<Path>(Collections.singletonList(root.remote))); } } upload.withCache(cache); download.withCache(cache); return this; }
protected AttributedList<TransferItem> children(final TransferItem directory) { if(null == directory) { // Root if(!cache.isCached(null)) { cache.put(null, new AttributedList<TransferItem>(transfer.getRoots())); this.filter(); } } else if(!cache.isCached(directory)) { controller.background(new WorkerBackgroundAction<List<TransferItem>>(controller, source, new TransferPromptListWorker(transfer, directory.remote, directory.local, controller) { @Override public void cleanup(final List<TransferItem> list) { cache.put(directory, new AttributedList<TransferItem>(list)); filter(); } } )); } return this.get(directory); }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list = new AttributedList<>(); final OneDriveFolder folder = session.toFolder(workdir); // The query text used to search for items. Values may be matched across several fields including filename, metadata, and file content. final Iterator<OneDriveItem.Metadata> iterator = folder.search(regex.toPattern().pattern()).iterator(); while(iterator.hasNext()) { final OneDriveItem.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e); continue; } list.add(new Path(String.format("/%s/%s/%s", metadata.getParentReference().getDriveId(), StringUtils.removeStart(metadata.getParentReference().getPath(), "/drive/root:"), metadata.getName()), metadata.isFolder() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attributes.toAttributes(metadata))); } return list; }
@Override public List<TransferItem> list(final Session<?> session, final Path directory, final Local local, final ListProgressListener listener) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("List children for %s", directory)); } if(directory.isSymbolicLink() && new DownloadSymlinkResolver(roots).resolve(directory)) { if(log.isDebugEnabled()) { log.debug(String.format("Do not list children for symbolic link %s", directory)); } return Collections.emptyList(); } else { final AttributedList<Path> list; if(cache.isCached(directory)) { list = cache.get(directory); } else { list = session.getFeature(ListService.class).list(directory, listener); cache.put(directory, list); } final List<TransferItem> children = new ArrayList<TransferItem>(); // Return copy with filtered result only for(Path f : new AttributedList<Path>(list.filter(comparator, filter))) { children.add(new TransferItem(f, LocalFactory.get(local, f.getName()))); } return children; } }
protected final AttributedList<Path> iterate(final Iterator<OneDriveDrive.Metadata> iterator, final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); while(iterator.hasNext()) { final OneDriveDrive.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); attributes.setSize(metadata.getTotal()); String name = metadata.getName(); if(StringUtils.isBlank(metadata.getName())) { name = metadata.getId(); } children.add(new Path(directory, name, EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public AttributedList<Path> put(final Path folder, final AttributedList<Path> encrypted) { final AttributedList<Path> list = new AttributedList<>(); // Swap with decrypted paths for(int i = 0; i < encrypted.size(); i++) { final Path f = encrypted.get(i); list.add(i, this.toDecrypted(f)); } return delegate.put(this.toDecrypted(folder), list); }
@Override public AttributedList<Path> get(final Path folder) { final AttributedList<Path> decrypted = delegate.get(this.toDecrypted(folder)); final AttributedList<Path> list = new AttributedList<>(); // Swap with encrypted paths for(int i = 0; i < decrypted.size(); i++) { final Path f = decrypted.get(i); list.add(i, this.toEncrypted(f)); } return list; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> children = new AttributedList<Path>(); for(final DavResource resource : this.list(directory)) { // Try to parse as RFC 2396 final String href = PathNormalizer.normalize(resource.getHref().getPath(), true); if(href.equals(directory.getAbsolute())) { log.warn(String.format("Ignore resource %s", href)); // Do not include self if(resource.isDirectory()) { continue; } throw new NotfoundException(directory.getAbsolute()); } final PathAttributes attr = attributes.toAttributes(resource); final Path file = new Path(directory, PathNormalizer.name(href), resource.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attr); children.add(file); listener.chunk(directory, children); } return children; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, directory); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); final GroupsIterator groupsIterator = new GroupsIterator(session.getClient()); while(groupsIterator.hasNext()) { final GroupItem.Metadata metadata; try { metadata = groupsIterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); children.add(new Path(directory, metadata.getDisplayName(), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { return new AttributedList<Path>(Collections.singletonList( new MantaAccountHomeInfo(session.getHost().getCredentials().getUsername(), session.getHost().getDefaultPath()).getNormalizedHomePath())); final AttributedList<Path> children = new AttributedList<>(); final Iterator<MantaObject> objectsIter; try {
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); final OneDriveFolder folder = session.toFolder(directory); try { final Iterator<OneDriveItem.Metadata> iterator = folder.iterator(PreferencesFactory.get().getInteger("onedrive.listing.chunksize")); while(iterator.hasNext()) { final OneDriveItem.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attr = attributes.toAttributes(metadata); children.add(new Path(directory, metadata.getName(), resolveType(metadata), attr)); listener.chunk(directory, children); } } catch(OneDriveRuntimeException e) { // this catches iterator.hasNext() which in return should fail fast throw new GraphExceptionMappingService().map("Listing directory {0} failed", e.getCause(), directory); } return children; }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list = new AttributedList<>(); // avoid searching the "special" folders if users search from the account root if(workdir.getParent().isRoot()) { final Predicate<MantaObject> fastSearchPredicate = o -> session.isWorldReadable(o) || session.isUserWritable(o); final List<Path> homeFolderPaths = findObjectsAsPaths(workdir, fastSearchPredicate); cleanResults(homeFolderPaths, regex); addPaths(list, workdir, listener, homeFolderPaths); /* // disable search of system directories until we can provide incremental results // slowSearchPredicate will prevent us from looking at ~~/public and ~~/stor twice final Predicate<MantaObject> slowSearchPredicate = fastSearchPredicate.negate(); final List<Path> systemFolderObjects = findObjectsAsPaths(workdir, slowSearchPredicate.and(regexPredicate)); cleanResults(systemFolderObjects, regex); addPaths(list, workdir, listener, systemFolderObjects); */ } else { final List<Path> foundPaths = findObjectsAsPaths(workdir, null); cleanResults(foundPaths, regex); addPaths(list, workdir, listener, foundPaths); } return list; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { ResultSegment<CloudBlobContainer> result; ResultContinuation token = null; try { final AttributedList<Path> containers = new AttributedList<Path>(); do { final BlobRequestOptions options = new BlobRequestOptions(); result = session.getClient().listContainersSegmented(null, ContainerListingDetails.NONE, preferences.getInteger("azure.listing.chunksize"), token, options, context); for(CloudBlobContainer container : result.getResults()) { final PathAttributes attributes = new PathAttributes(); attributes.setETag(container.getProperties().getEtag()); attributes.setModificationDate(container.getProperties().getLastModified().getTime()); containers.add(new Path(PathNormalizer.normalize(container.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory), attributes)); } listener.chunk(directory, containers); token = result.getContinuationToken(); } while(result.getHasMoreResults()); return containers; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); list.add(DriveHomeFinderService.MYDRIVE_FOLDER); list.add(DriveHomeFinderService.SHARED_FOLDER_NAME); list.add(DriveHomeFinderService.TEAM_DRIVES_NAME); listener.chunk(directory, list); return list; } else { if(DriveHomeFinderService.SHARED_FOLDER_NAME.equals(directory)) { return new DriveSharedFolderListService(session, fileid).list(directory, listener); } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(directory)) { return new DriveTeamDrivesListService(session).list(directory, listener); } return new DriveDefaultListService(session, fileid).list(directory, listener); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> children = new AttributedList<>(); final String path = directory.isRoot() ? StringUtils.EMPTY : directory.getAbsolute(); ListFolderResult result; this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient()).listFolder(path)); // If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest. while(result.getHasMore()) { this.parse(directory, listener, children, result = new DbxUserFilesRequests(session.getClient()) .listFolderContinue(result.getCursor())); } return children; } catch(DbxException e) { throw new DropboxExceptionMappingService().map(e); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> buckets = new AttributedList<Path>(); for(B2BucketResponse bucket : session.getClient().listBuckets()) { final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(bucket.getBucketId()); switch(bucket.getBucketType()) { case allPublic: attributes.setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); break; } buckets.add(new Path(PathNormalizer.normalize(bucket.getBucketName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); } listener.chunk(directory, buckets); return buckets; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); list.add(DEFAULT_NAME); list.add(GROUPS_NAME); listener.chunk(directory, list); return list; } else { if(DEFAULT_NAME.equals(directory)) { return new GraphDrivesListService(session).list(directory, listener); } else if(GROUPS_NAME.equals(directory)) { return new SharepointGroupListService(session).list(directory, listener); } else if(GROUPS_NAME.equals(directory.getParent())) { return new SharepointGroupDrivesListService(session).list(directory, listener); } return new GraphItemListService(session).list(directory, listener); } }