@Test public void testListLexicographicSortOrderAssumption() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials( System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key") )); final AzureSession session = new AzureSession(host); new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()).connect(session, PathCache.empty(), new DisabledCancelCallback()); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory)); final Path directory = new AzureDirectoryFeature(session, null).mkdir( new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null, new TransferStatus()); assertTrue(new AzureObjectListService(session, null).list(directory, new DisabledListProgressListener()).isEmpty()); final List<String> files = Arrays.asList( "aa", "0a", "a", "AAA", "B", "~$a", ".c" ); for(String f : files) { new AzureTouchFeature(session, null).touch(new Path(directory, f, EnumSet.of(Path.Type.file)), new TransferStatus()); } files.sort(session.getHost().getProtocol().getListComparator()); final AttributedList<Path> list = new AzureObjectListService(session, null).list(directory, new DisabledListProgressListener()); for(int i = 0; i < list.size(); i++) { assertEquals(files.get(i), list.get(i).getName()); new AzureDeleteFeature(session, null).delete(Collections.singletonList(list.get(i)), new DisabledLoginCallback(), new Delete.DisabledCallback()); } new AzureDeleteFeature(session, null).delete(Collections.singletonList(directory), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if(!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented( prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for(ListBlobItem object : result.getResults()) { if(new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { hasDirectoryPlaceholder = true; continue; } final PathAttributes attributes = new PathAttributes(); if(object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if(StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } final EnumSet<Path.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while(result.getHasMoreResults()); if(!hasDirectoryPlaceholder && children.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return children; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
AzureObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if(!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented( prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for(ListBlobItem object : result.getResults()) { if(new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { hasDirectoryPlaceholder = true; continue; } final PathAttributes attributes = new PathAttributes(); if(object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if(StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } final EnumSet<Path.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while(result.getHasMoreResults()); if(!hasDirectoryPlaceholder && children.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return children; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } }
AzureObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if(!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented( prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for(ListBlobItem object : result.getResults()) { if(new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { hasDirectoryPlaceholder = true; continue; } final PathAttributes attributes = new PathAttributes(); if(object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if(StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } final EnumSet<Path.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while(result.getHasMoreResults()); if(!hasDirectoryPlaceholder && children.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return children; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureObjectListService(final AzureSession session, final OperationContext context); }
AzureObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if(!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented( prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for(ListBlobItem object : result.getResults()) { if(new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { hasDirectoryPlaceholder = true; continue; } final PathAttributes attributes = new PathAttributes(); if(object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if(StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } final EnumSet<Path.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while(result.getHasMoreResults()); if(!hasDirectoryPlaceholder && children.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return children; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureObjectListService(final AzureSession session, final OperationContext context); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); }
AzureObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final CloudBlobContainer container = session.getClient().getContainerReference(containerService.getContainer(directory).getName()); final AttributedList<Path> children = new AttributedList<Path>(); ResultContinuation token = null; ResultSegment<ListBlobItem> result; String prefix = StringUtils.EMPTY; if(!containerService.isContainer(directory)) { prefix = containerService.getKey(directory); if(!prefix.endsWith(String.valueOf(Path.DELIMITER))) { prefix += Path.DELIMITER; } } boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { final BlobRequestOptions options = new BlobRequestOptions(); result = container.listBlobsSegmented( prefix, false, EnumSet.noneOf(BlobListingDetails.class), PreferencesFactory.get().getInteger("azure.listing.chunksize"), token, options, context); for(ListBlobItem object : result.getResults()) { if(new Path(object.getUri().getPath(), EnumSet.of(Path.Type.directory)).equals(directory)) { hasDirectoryPlaceholder = true; continue; } final PathAttributes attributes = new PathAttributes(); if(object instanceof CloudBlob) { final CloudBlob blob = (CloudBlob) object; attributes.setSize(blob.getProperties().getLength()); attributes.setModificationDate(blob.getProperties().getLastModified().getTime()); attributes.setETag(blob.getProperties().getEtag()); if(StringUtils.isNotBlank(blob.getProperties().getContentMD5())) { attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(blob.getProperties().getContentMD5())))); } } final EnumSet<Path.Type> types = object instanceof CloudBlobDirectory ? EnumSet.of(Path.Type.directory, Path.Type.placeholder) : EnumSet.of(Path.Type.file); final Path child = new Path(directory, PathNormalizer.name(object.getUri().getPath()), types, attributes); children.add(child); } listener.chunk(directory, children); token = result.getContinuationToken(); } while(result.getHasMoreResults()); if(!hasDirectoryPlaceholder && children.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return children; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureObjectListService(final AzureSession session, final OperationContext context); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener);  }