Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix the issue of listing blobs with leading slashes #21427

Merged
merged 12 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.13.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Additional information about change #1
-->
## Upcoming Release
* Added a warning message for an upcoming breaking change when getting a single blob
- `Get-AzStorageBlob`
* Fixed the issue of listing blobs with leading slashes
- `Get-AzStorageBlob`
* Added warning messages for an upcoming cmdlet breaking change
- `New-AzStorageAccount`
- `Set-AzStorageAccount`
Expand Down
6 changes: 5 additions & 1 deletion src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
/// <summary>
/// list azure blobs in specified azure container
/// </summary>
[GenericBreakingChange("Leading and trailing slashes on the blob name will not be trimmed when getting a single blob",
OldWay = "Leading and trailing slashes on the blob name are trimmed",
yifanz0 marked this conversation as resolved.
Show resolved Hide resolved
NewWay = "Leading and trailing slashes on the blob name are not trimmed")]
[Cmdlet("Get", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageBlob", DefaultParameterSetName = NameParameterSet),OutputType(typeof(AzureStorageBlob))]
public class GetAzureStorageBlobCommand : StorageCloudBlobCmdletBase
{
Expand Down Expand Up @@ -329,6 +332,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
{
if (blobFilter == null || blobFilter(item.Name))
{
ClientOptions.TrimBlobNameSlashes = false;
yifanz0 marked this conversation as resolved.
Show resolved Hide resolved
OutputStream.WriteObject(taskId, GetAzureStorageBlob(item, track2container, localChannel.StorageContext, page.ContinuationToken, ClientOptions));
}
realListCount++;
Expand Down Expand Up @@ -387,7 +391,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC

public static AzureStorageBlob GetAzureStorageBlob(BlobItem blobItem, BlobContainerClient track2container, AzureStorageContext context, string continuationToken = null, BlobClientOptions options = null)
{
BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType);
BlobBaseClient blobClient = Util.GetTrack2BlobClient(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType, shouldTrimSlash: false);
AzureStorageBlob outputblob = new AzureStorageBlob(blobClient, context, options, blobItem);
if (!string.IsNullOrEmpty(continuationToken))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/Storage/Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ public static Hashtable GetHashtableFromDictionary(IDictionary<string, string> d
}
}

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)
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)
{
//Get Track2 Blob Client Uri
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri)
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, trimBlobNameSlashes: shouldTrimSlash)
{
BlobName = blobName
};
Expand Down
8 changes: 4 additions & 4 deletions src/Storage/Storage/Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.2.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.12.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.13.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.2" />
Expand Down