Skip to content

Commit f035811

Browse files
committed
Use released version of Azure.Storage.Blobs
1 parent 570a1d7 commit f035811

File tree

2 files changed

+11
-46
lines changed

2 files changed

+11
-46
lines changed

src/SourceBrowser/src/SourceIndexServer/Models/AzureBlobFileSystem.cs

+10-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
1-
using System;
1+
using Azure.Storage.Blobs;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
5-
using System.Reflection;
6-
using Azure.Core.Pipeline;
7-
using Azure.Storage;
8-
using Azure.Storage.Blobs;
9-
using Azure.Storage.Blobs.Models;
106

117
namespace Microsoft.SourceBrowser.SourceIndexServer.Models
128
{
139
public class AzureBlobFileSystem : IFileSystem
1410
{
15-
private class AnonContainerClient : BlobContainerClient
16-
{
17-
public override Uri Uri { get; }
18-
protected override HttpPipeline Pipeline { get; }
19-
20-
public AnonContainerClient(string uri)
21-
{
22-
Uri = new Uri(uri);
23-
Pipeline = HttpPipelineBuilder.Build(new BlobClientOptions());
24-
}
25-
26-
public override BlobClient GetBlobClient(string blobName)
27-
{
28-
return (BlobClient)typeof(BlobClient).GetTypeInfo().DeclaredConstructors.Single(ctor => ctor.ToString() == "Void .ctor(System.Uri, Azure.Core.Pipeline.HttpPipeline)").Invoke(new object[] { AppendToPath(this.Uri, blobName), this.Pipeline });
29-
}
30-
31-
private static Uri AppendToPath(Uri uri, string segment)
32-
{
33-
UriBuilder uriBuilder = new UriBuilder(uri);
34-
string path = uriBuilder.Path;
35-
uriBuilder.Path = uriBuilder.Path + (path.Length == 0 || path[path.Length - 1] != '/' ? "/" : "") + segment;
36-
return uriBuilder.Uri;
37-
}
38-
}
39-
4011
private readonly BlobContainerClient container;
12+
4113
public AzureBlobFileSystem(string uri)
4214
{
43-
container = new AnonContainerClient(uri);
15+
container = new BlobContainerClient(new Uri(uri));
4416
}
4517

4618
public bool DirectoryExists(string name)
@@ -57,25 +29,18 @@ public IEnumerable<string> ListFiles(string dirName)
5729
dirName += "/";
5830
}
5931

60-
return container.GetBlobsByHierarchy("/", new GetBlobsOptions
61-
{
62-
Prefix = dirName,
63-
}).Select(res => res.Value).Where(item => item.IsBlob).Select(item => item.Blob.Name).ToList();
32+
return container.GetBlobsByHierarchy(prefix: dirName)
33+
.Where(item => item.IsBlob)
34+
.Select(item => item.Blob.Name)
35+
.ToList();
6436
}
6537

6638
public bool FileExists(string name)
6739
{
6840
name = name.ToLowerInvariant();
6941
var blob = container.GetBlobClient(name);
70-
try
71-
{
72-
blob.GetProperties();
73-
return true;
74-
}
75-
catch (StorageRequestFailedException ex) when (string.Equals(ex.ErrorCode, "BlobNotFound"))
76-
{
77-
return false;
78-
}
42+
43+
return blob.Exists();
7944
}
8045

8146
public Stream OpenSequentialReadStream(string name)

src/SourceBrowser/src/SourceIndexServer/SourceIndexServer.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Azure.Storage.Blobs" Version="12.0.0-preview.3" />
11+
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)