-
Notifications
You must be signed in to change notification settings - Fork 645
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
Support blob hierarchy operations with a custom delimiter #10192
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,13 @@ public class AzureStorage : Storage | |
private readonly ILogger<AzureStorage> _logger; | ||
private readonly BlobContainerClient _directory; | ||
private readonly string _path; | ||
private readonly string _delimiter; | ||
|
||
public AzureStorage( | ||
BlobServiceClient account, | ||
string containerName, | ||
string path, | ||
string delimiter, | ||
Uri baseAddress, | ||
bool initializeContainer, | ||
bool enablePublicAccess, | ||
|
@@ -38,6 +40,7 @@ public AzureStorage( | |
logger) | ||
{ | ||
_path = path; | ||
_delimiter = delimiter; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no delimiter is passed, the blob listing will be flat, and you won't get hierarchical groupings like folders in the results. Now with |
||
} | ||
|
||
private AzureStorage( | ||
|
@@ -171,8 +174,14 @@ public override IEnumerable<StorageListItem> List(bool getMetadata) | |
blobTraits |= BlobTraits.Metadata; | ||
} | ||
|
||
foreach (BlobHierarchyItem blob in _directory.GetBlobsByHierarchy(traits: blobTraits, prefix: _path)) | ||
foreach (BlobHierarchyItem blob in _directory.GetBlobsByHierarchy(traits: blobTraits, delimiter: _delimiter, prefix: _path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm running some tests and without the delimiter specified, When delimiter is passed, it only returns immediate children under prefix AND if prefix ends in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest introducing a separate method for listing only immediate children, so there is no ambiguity/confusion as to what it returns. |
||
{ | ||
// if prefix then the blob is a directory and we should skip it | ||
if (blob.IsPrefix) | ||
{ | ||
continue; | ||
} | ||
|
||
yield return GetStorageListItem(_directory.GetBlockBlobClient(blob.Blob.Name)); | ||
} | ||
} | ||
|
@@ -187,8 +196,13 @@ public override async Task<IEnumerable<StorageListItem>> ListAsync(bool getMetad | |
|
||
var blobList = new List<StorageListItem>(); | ||
|
||
await foreach (BlobHierarchyItem blob in _directory.GetBlobsByHierarchyAsync(traits: blobTraits, prefix: _path)) | ||
await foreach (BlobHierarchyItem blob in _directory.GetBlobsByHierarchyAsync(traits: blobTraits, delimiter: _delimiter, prefix: _path, cancellationToken: cancellationToken)) | ||
{ | ||
// if prefix then the blob is a directory and we should skip it | ||
if (blob.IsPrefix) | ||
{ | ||
continue; | ||
} | ||
blobList.Add(await GetStorageListItemAsync(_directory.GetBlockBlobClient(blob.Blob.Name))); | ||
} | ||
|
||
|
@@ -364,7 +378,7 @@ protected override async Task<StorageContent> OnLoad(Uri resourceUri, Cancellati | |
originalStream.Position = 0; | ||
var propertiesResponse = await blob.GetPropertiesAsync(); | ||
var properties = propertiesResponse.Value; | ||
|
||
MemoryStream content; | ||
|
||
if (properties.ContentEncoding == "gzip") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the only delimiter allowed for storage accounts is
/
, I'd say, there is no point to parameterize it. Having a constant should be enough.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By any chance it would be
\
for non-Windows machines? Not sure about actual implementation of Azure storage machines, under the hood it's it's just another VM from my understanding.