Skip to content

Commit 3bbe56f

Browse files
authored
[Storage] Fix the issue of listing blobs with leading slashes (#21427)
* Fix for slash issue * update GetTrack2BlobClient input * update sdk dependency * Add warning message for breaking change * Update warning message * Update warning message to apply to just the parameter
1 parent 56836bb commit 3bbe56f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Added a warning message for an upcoming breaking change when getting a single blob
22+
- `Get-AzStorageBlob`
23+
* Fixed the issue of listing blobs with leading slashes
24+
- `Get-AzStorageBlob`
2125
* Added support for sticky bit
2226
- `New-AzDataLakeGen2Item`
2327
- `New-AzDataLakeGen2ACLObject`

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase
5757
/// </summary>
5858
private const string SingleBlobVersionIDParameterSet = "SingleBlobVersionID";
5959

60+
[CmdletParameterBreakingChange("Blob", ChangeDescription = "Leading and trailing slashes will not be trimmed in a future release.")]
6061
[Parameter(Position = 0, HelpMessage = "Blob name", ParameterSetName = NameParameterSet)]
6162
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobSnapshotTimeParameterSet)]
6263
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Blob name", ParameterSetName = SingleBlobVersionIDParameterSet)]
@@ -329,6 +330,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
329330
{
330331
if (blobFilter == null || blobFilter(item.Name))
331332
{
333+
ClientOptions.TrimBlobNameSlashes = false;
332334
OutputStream.WriteObject(taskId, GetAzureStorageBlob(item, track2container, localChannel.StorageContext, page.ContinuationToken, ClientOptions));
333335
}
334336
realListCount++;
@@ -387,7 +389,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
387389

388390
public static AzureStorageBlob GetAzureStorageBlob(BlobItem blobItem, BlobContainerClient track2container, AzureStorageContext context, string continuationToken = null, BlobClientOptions options = null)
389391
{
390-
BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType);
392+
BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType, shouldTrimSlash: false);
391393
AzureStorageBlob outputblob = new AzureStorageBlob(blobClient, context, options, blobItem);
392394
if (!string.IsNullOrEmpty(continuationToken))
393395
{

src/Storage/Storage/Common/Util.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ public static Hashtable GetHashtableFromDictionary(IDictionary<string, string> d
400400
}
401401
}
402402

403-
public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null)
403+
public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2container, string blobName, AzureStorageContext context, string versionId = null, bool? IsCurrentVersion = null, string snapshot = null, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null, bool shouldTrimSlash = true)
404404
{
405405
//Get Track2 Blob Client Uri
406-
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri)
406+
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, trimBlobNameSlashes: shouldTrimSlash)
407407
{
408408
BlobName = blobName
409409
};

0 commit comments

Comments
 (0)