@@ -45,9 +45,14 @@ internal class AzureFileSystem : IFileSystem
45
45
private static readonly List < AzureFileSystem > FileSystems = new List < AzureFileSystem > ( ) ;
46
46
47
47
/// <summary>
48
- /// The root url.
48
+ /// The root host url.
49
49
/// </summary>
50
- private readonly string rootBlobUrl ;
50
+ private readonly string rootHostUrl ;
51
+
52
+ /// <summary>
53
+ /// The combined root and container url.
54
+ /// </summary>
55
+ private readonly string rootContainerUrl ;
51
56
52
57
/// <summary>
53
58
/// The cloud media blob container.
@@ -94,12 +99,16 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
94
99
CloudBlobClient cloudBlobClient = cloudStorageAccount . CreateCloudBlobClient ( ) ;
95
100
this . cloudBlobContainer = CreateContainer ( cloudBlobClient , containerName , BlobContainerPublicAccessType . Blob ) ;
96
101
102
+ // First assign a local copy before editing. We use that to track the type.
103
+ // TODO: Do we need this? The container should be an identifer.
104
+ this . rootHostUrl = rootUrl ;
105
+
97
106
if ( ! rootUrl . Trim ( ) . EndsWith ( "/" ) )
98
107
{
99
108
rootUrl = rootUrl . Trim ( ) + "/" ;
100
109
}
101
110
102
- this . rootBlobUrl = rootUrl + containerName + "/" ;
111
+ this . rootContainerUrl = rootUrl + containerName + "/" ;
103
112
this . ContainerName = containerName ;
104
113
this . MaxDays = maxDays ;
105
114
this . UseDefaultRoute = useDefaultRoute ;
@@ -148,11 +157,13 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
148
157
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
149
158
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
150
159
/// <returns>The <see cref="AzureFileSystem"/></returns>
151
- public AzureFileSystem GetInstance ( string containerName , string rootUrl , string connectionString , string maxDays , string useDefaultRoute )
160
+ public static AzureFileSystem GetInstance ( string containerName , string rootUrl , string connectionString , string maxDays , string useDefaultRoute )
152
161
{
153
162
lock ( Locker )
154
163
{
155
- if ( FileSystems . SingleOrDefault ( fs => fs . ContainerName == containerName && fs . rootBlobUrl == rootUrl ) == null )
164
+ AzureFileSystem fileSystem = FileSystems . SingleOrDefault ( fs => fs . ContainerName == containerName && fs . rootHostUrl == rootUrl ) ;
165
+
166
+ if ( fileSystem == null )
156
167
{
157
168
int max ;
158
169
if ( ! int . TryParse ( maxDays , out max ) )
@@ -166,11 +177,11 @@ public AzureFileSystem GetInstance(string containerName, string rootUrl, string
166
177
defaultRoute = true ;
167
178
}
168
179
169
- AzureFileSystem fileSystem = new AzureFileSystem ( containerName , rootUrl , connectionString , max , defaultRoute ) ;
180
+ fileSystem = new AzureFileSystem ( containerName , rootUrl , connectionString , max , defaultRoute ) ;
170
181
FileSystems . Add ( fileSystem ) ;
171
182
}
172
183
173
- return FileSystems . SingleOrDefault ( fs => fs . ContainerName == containerName && fs . rootBlobUrl == rootUrl ) ;
184
+ return fileSystem ;
174
185
}
175
186
}
176
187
@@ -418,14 +429,14 @@ public IEnumerable<string> GetFiles(string path, string filter)
418
429
419
430
if ( filter . Equals ( "*.*" , StringComparison . InvariantCultureIgnoreCase ) )
420
431
{
421
- return url . Substring ( this . rootBlobUrl . Length ) ;
432
+ return url . Substring ( this . rootContainerUrl . Length ) ;
422
433
}
423
434
424
435
// Filter by name.
425
436
filter = filter . TrimStart ( '*' ) ;
426
437
if ( url . IndexOf ( filter , StringComparison . InvariantCultureIgnoreCase ) > - 1 )
427
438
{
428
- return url . Substring ( this . rootBlobUrl . Length ) ;
439
+ return url . Substring ( this . rootContainerUrl . Length ) ;
429
440
}
430
441
431
442
return null ;
@@ -583,7 +594,7 @@ private string ResolveUrl(string path, bool relative)
583
594
// First create the full url
584
595
string fixedPath = this . FixPath ( path ) ;
585
596
586
- Uri url = new Uri ( new Uri ( this . rootBlobUrl , UriKind . Absolute ) , fixedPath ) ;
597
+ Uri url = new Uri ( new Uri ( this . rootContainerUrl , UriKind . Absolute ) , fixedPath ) ;
587
598
588
599
if ( ! relative )
589
600
{
@@ -619,9 +630,9 @@ private string FixPath(string path)
619
630
}
620
631
621
632
// Strip root url
622
- if ( path . StartsWith ( this . rootBlobUrl , StringComparison . InvariantCultureIgnoreCase ) )
633
+ if ( path . StartsWith ( this . rootContainerUrl , StringComparison . InvariantCultureIgnoreCase ) )
623
634
{
624
- path = path . Substring ( this . rootBlobUrl . Length ) ;
635
+ path = path . Substring ( this . rootContainerUrl . Length ) ;
625
636
}
626
637
627
638
// Strip default route
0 commit comments