From e6478a60b4b597234433356ec8ac4e222106af19 Mon Sep 17 00:00:00 2001 From: Etienne CARRIERE Date: Fri, 14 Jul 2017 04:27:57 +0200 Subject: [PATCH] Corrections following the remarks on the pull request --- .../storage/AzureStorageServiceImpl.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java b/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java index 416bf0bb0aa42..029227b25b098 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/cloud/azure/storage/AzureStorageServiceImpl.java @@ -282,24 +282,23 @@ public Map listBlobsByPrefix(String account, LocationMode EnumSet enumBlobListingDetails = EnumSet.of(BlobListingDetails.METADATA); CloudBlobClient client = this.getSelectedClient(account, mode); CloudBlobContainer blobContainer = client.getContainerReference(container); - if (blobContainer.exists()) { - for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix == null ? "" : prefix),false,enumBlobListingDetails,null,null)) { - URI uri = blobItem.getUri(); - logger.trace("blob url [{}]", uri); - - // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/ - // this requires 1 + container.length() + 1, with each 1 corresponding to one of the / - String blobPath = uri.getPath().substring(1 + container.length() + 1); - if (!(blobItem instanceof CloudBlockBlob)){ - logger.warn("blob url [{}] is not a CloudBlockBlob",uri); - continue; + SocketAccess.doPrivilegedVoidException(() -> { + if (blobContainer.exists()) { + for (ListBlobItem blobItem : blobContainer.listBlobs(keyPath + (prefix==null ? "" : prefix),false, + enumBlobListingDetails, null, null)) { + URI uri = blobItem.getUri(); + logger.trace("blob url [{}]", uri); + + // uri.getPath is of the form /container/keyPath.* and we want to strip off the /container/ + // this requires 1 + container.length() + 1, with each 1 corresponding to one of the / + String blobPath = uri.getPath().substring(1 + container.length() + 1); + BlobProperties properties = ((CloudBlockBlob) blobItem).getProperties(); + String name = blobPath.substring(keyPath.length()); + logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength()); + blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength())); } - BlobProperties properties = ((CloudBlockBlob) blobItem).getProperties(); - String name = blobPath.substring(keyPath.length()); - logger.trace("blob url [{}], name [{}], size [{}]", uri, name, properties.getLength()); - blobsBuilder.put(name, new PlainBlobMetaData(name, properties.getLength())); } - } + }); return blobsBuilder.immutableMap(); }