Addressing IFileSystem breaking changes

This PR is to address the breaking changes introduced with https://github.com/aspnet/FileSystem/pull/20

@Tratcher @pranavkm
This commit is contained in:
Praburaj 2014-11-26 12:24:56 -08:00
parent fb9fc12cec
commit 1bc4e21c22
3 changed files with 28 additions and 25 deletions

View File

@ -48,19 +48,20 @@ namespace Microsoft.AspNet.StaticFiles
/// <returns></returns>
public Task Invoke(HttpContext context)
{
IEnumerable<IFileInfo> dirContents;
PathString subpath;
if (Helpers.IsGetOrHeadMethod(context.Request.Method)
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out subpath)
&& _options.FileSystem.TryGetDirectoryContents(subpath.Value, out dirContents))
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out subpath))
{
var dirContents = _options.FileSystem.GetDirectoryContents(subpath.Value);
if (dirContents.Exists)
{
// Check if any of our default files exist.
for (int matchIndex = 0; matchIndex < _options.DefaultFileNames.Count; matchIndex++)
{
string defaultFile = _options.DefaultFileNames[matchIndex];
IFileInfo file;
var file = _options.FileSystem.GetFileInfo(subpath + defaultFile);
// TryMatchPath will make sure subpath always ends with a "/" by adding it if needed.
if (_options.FileSystem.TryGetFileInfo(subpath + defaultFile, out file))
if (file.Exists)
{
// If the path matches a directory but does not end in a slash, redirect to add the slash.
// This prevents relative links from breaking.
@ -77,6 +78,7 @@ namespace Microsoft.AspNet.StaticFiles
}
}
}
}
return _next(context);
}

View File

@ -50,7 +50,7 @@ namespace Microsoft.AspNet.StaticFiles
{
// Check if the URL matches any expected paths
PathString subpath;
IEnumerable<IFileInfo> contents;
IDirectoryContents contents;
if (Helpers.IsGetOrHeadMethod(context.Request.Method)
&& Helpers.TryMatchPath(context, _matchUrl, forDirectory: true, subpath: out subpath)
&& TryGetDirectoryInfo(subpath, out contents))
@ -70,9 +70,10 @@ namespace Microsoft.AspNet.StaticFiles
return _next(context);
}
private bool TryGetDirectoryInfo(PathString subpath, out IEnumerable<IFileInfo> contents)
private bool TryGetDirectoryInfo(PathString subpath, out IDirectoryContents contents)
{
return _options.FileSystem.TryGetDirectoryContents(subpath.Value, out contents);
contents = _options.FileSystem.GetDirectoryContents(subpath.Value);
return contents.Exists;
}
}
}

View File

@ -116,8 +116,8 @@ namespace Microsoft.AspNet.StaticFiles
public bool LookupFileInfo()
{
bool found = _options.FileSystem.TryGetFileInfo(_subPath.Value, out _fileInfo);
if (found)
_fileInfo = _options.FileSystem.GetFileInfo(_subPath.Value);
if (_fileInfo.Exists)
{
_length = _fileInfo.Length;
@ -130,7 +130,7 @@ namespace Microsoft.AspNet.StaticFiles
_etag = Convert.ToString(etagHash, 16);
_etagQuoted = '\"' + _etag + '\"';
}
return found;
return _fileInfo.Exists;
}
public void ComprehendRequestHeaders()