Skip to content

Commit 0634860

Browse files
authored
[Storage] fix issue in get blob by tag (#17724)
* [Storage] fix issue in get blob by tag * add change log and revise code
1 parent a7ef00f commit 0634860

File tree

3 files changed

+8
-53
lines changed

3 files changed

+8
-53
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed get blob by tag failure on Powershell 7.2.2
22+
- `Get-AzStorageBlobByTag`
2123

2224
## Version 4.4.0
2325
* Updated examples in reference documentation for `Close-AzStorageFileHandle`

src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -379,50 +379,6 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
379379
}
380380
}
381381

382-
/// <summary>
383-
/// list blobs by blob Tag
384-
/// </summary>
385-
/// <param name="containerName">container name</param>
386-
/// <param name="prefix">blob preifx</param>
387-
/// <returns>An enumerable collection of IListBlobItem</returns>
388-
internal async Task ListBlobsByTag(long taskId, IStorageBlobManagement localChannel, string tagFilterSqlExpression)
389-
{
390-
391-
BlobServiceClient blobServiceClient = Util.GetTrack2BlobServiceClient(localChannel.StorageContext, ClientOptions);
392-
393-
int listCount = InternalMaxCount;
394-
int MaxListCount = 5000;
395-
int requestCount = MaxListCount;
396-
int realListCount = 0;
397-
BlobContinuationToken continuationToken = ContinuationToken;
398-
string track2ContinuationToken = this.ContinuationToken is null ? null : this.ContinuationToken.NextMarker;
399-
400-
do
401-
{
402-
requestCount = Math.Min(listCount, MaxListCount);
403-
realListCount = 0;
404-
IAsyncEnumerator<Page<TaggedBlobItem>> enumerator = blobServiceClient.FindBlobsByTagsAsync(tagFilterSqlExpression, CmdletCancellationToken)
405-
.AsPages(track2ContinuationToken, requestCount)
406-
.GetAsyncEnumerator();
407-
408-
Page<TaggedBlobItem> page;
409-
await enumerator.MoveNextAsync().ConfigureAwait(false);
410-
page = enumerator.Current;
411-
foreach (TaggedBlobItem item in page.Values)
412-
{
413-
BlobContainerClient track2container = blobServiceClient.GetBlobContainerClient(item.BlobContainerName);
414-
OutputStream.WriteObject(taskId, GetAzureStorageBlob(item, track2container, localChannel.StorageContext, page.ContinuationToken, ClientOptions));
415-
realListCount++;
416-
}
417-
track2ContinuationToken = page.ContinuationToken;
418-
419-
if (InternalMaxCount != int.MaxValue)
420-
{
421-
listCount -= realListCount;
422-
}
423-
} while (listCount > 0 && !string.IsNullOrEmpty(track2ContinuationToken));
424-
}
425-
426382
public static AzureStorageBlob GetAzureStorageBlob(BlobItem blobItem, BlobContainerClient track2container, AzureStorageContext context, string continuationToken = null, BlobClientOptions options = null)
427383
{
428384
BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType);

src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlobByTag.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public GetAzureStorageBlobByTagCommand(IStorageBlobManagement channel)
9090
/// <summary>
9191
/// list blobs by blob Tag
9292
/// </summary>
93-
internal async Task ListBlobsByTag(long taskId, IStorageBlobManagement localChannel, string tagFilterSqlExpression)
93+
internal void ListBlobsByTag(IStorageBlobManagement localChannel, string tagFilterSqlExpression)
9494
{
9595

9696
BlobServiceClient blobServiceClient = Util.GetTrack2BlobServiceClient(localChannel.StorageContext, ClientOptions);
@@ -106,16 +106,16 @@ internal async Task ListBlobsByTag(long taskId, IStorageBlobManagement localChan
106106
{
107107
requestCount = Math.Min(listCount, MaxListCount);
108108
realListCount = 0;
109-
IAsyncEnumerator<Page<TaggedBlobItem>> enumerator = blobServiceClient.FindBlobsByTagsAsync(tagFilterSqlExpression, CmdletCancellationToken)
109+
IEnumerator<Page<TaggedBlobItem>> enumerator = blobServiceClient.FindBlobsByTags(tagFilterSqlExpression, CmdletCancellationToken)
110110
.AsPages(track2ContinuationToken, requestCount)
111-
.GetAsyncEnumerator();
111+
.GetEnumerator();
112112

113113
Page<TaggedBlobItem> page;
114-
await enumerator.MoveNextAsync().ConfigureAwait(false);
114+
enumerator.MoveNext();
115115
page = enumerator.Current;
116116
foreach (TaggedBlobItem item in page.Values)
117117
{
118-
OutputStream.WriteObject(taskId, new AzureStorageBlob(item, Channel.StorageContext, page.ContinuationToken, ClientOptions, this.GetBlobProperty.IsPresent));
118+
WriteObject(new AzureStorageBlob(item, Channel.StorageContext, page.ContinuationToken, ClientOptions, this.GetBlobProperty.IsPresent));
119119
realListCount++;
120120
}
121121
track2ContinuationToken = page.ContinuationToken;
@@ -133,12 +133,9 @@ internal async Task ListBlobsByTag(long taskId, IStorageBlobManagement localChan
133133
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
134134
public override void ExecuteCmdlet()
135135
{
136-
Func<long, Task> taskGenerator = null;
137136
IStorageBlobManagement localChannel = Channel;
138137

139-
taskGenerator = (taskId) => ListBlobsByTag(taskId, localChannel, this.TagFilterSqlExpression);
140-
141-
RunTask(taskGenerator);
138+
ListBlobsByTag(localChannel, this.TagFilterSqlExpression);
142139
}
143140
}
144141
}

0 commit comments

Comments
 (0)