Handle non-empty delete container in azureblob-sdk

Found via s3-tests.  References #606.
pull/702/head
Andrew Gaul 2024-10-28 15:56:40 -07:00
rodzic ff8e12e631
commit 8ebf6ce84e
1 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -226,6 +226,26 @@ public final class AzureBlobStore extends BaseBlobStore {
}
}
@Override
public boolean deleteContainerIfEmpty(String container) {
var client = blobServiceClient.getBlobContainerClient(container);
try {
var page = client.listBlobsByHierarchy(
/*delimiter=*/ null, /*options=*/ null, /*timeout=*/ null)
.iterableByPage().iterator().next();
if (!page.getValue().isEmpty()) {
return false;
}
blobServiceClient.deleteBlobContainer(container);
return true;
} catch (BlobStorageException bse) {
if (bse.getErrorCode() == BlobErrorCode.CONTAINER_NOT_FOUND) {
return true;
}
throw bse;
}
}
@Override
public boolean blobExists(String container, String key) {
var client = blobServiceClient.getBlobContainerClient(container)