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
3 changes: 2 additions & 1 deletion src/Storage/Storage/Blob/Cmdlet/GetAzureStorageBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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 +388,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.GetTrack2BlobClientNoSlashTrim(track2container, blobItem.Name, context, blobItem.VersionId, blobItem.IsLatestVersion, blobItem.Snapshot, options, blobItem.Properties.BlobType);
AzureStorageBlob outputblob = new AzureStorageBlob(blobClient, context, options, blobItem);
if (!string.IsNullOrEmpty(continuationToken))
{
Expand Down
19 changes: 19 additions & 0 deletions src/Storage/Storage/Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,25 @@ public static BlobBaseClient GetTrack2BlobClient(BlobContainerClient track2conta
return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType);
}

public static BlobBaseClient GetTrack2BlobClientNoSlashTrim(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)
{
//Get Track2 Blob Client Uri
BlobUriBuilder blobUriBuilder = new BlobUriBuilder(track2container.Uri, false)
yifanz0 marked this conversation as resolved.
Show resolved Hide resolved
{
BlobName = blobName
};
if (versionId != null && (IsCurrentVersion == null || !IsCurrentVersion.Value)) // only none current version blob need versionId in Uri
{
blobUriBuilder.VersionId = versionId;
}
if (snapshot != null)
{
blobUriBuilder.Snapshot = snapshot;
}

return GetTrack2BlobClient(blobUriBuilder.ToUri(), context, options, blobType);
}

public static BlobBaseClient GetTrack2BlobClient(Uri blobUri, AzureStorageContext context, BlobClientOptions options = null, global::Azure.Storage.Blobs.Models.BlobType? blobType = null)
{
BlobBaseClient blobClient;
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