diff options
| author | Bond_009 <bond.009@outlook.com> | 2019-01-27 17:00:17 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2019-01-27 17:00:17 +0100 |
| commit | ffe79c89829fb232e8ccb4ae4caf4b732ce51600 (patch) | |
| tree | 6938e3f5ebae59fe4baec81e4583abbef3371dae /Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | |
| parent | 1a3543e5a5984d4ec5284f43b7df63a9d19c8a9c (diff) | |
Check if file exists instead of catching exceptions
Diffstat (limited to 'Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs')
| -rw-r--r-- | Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs index ea620cb2e..217f366e0 100644 --- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs @@ -286,28 +286,18 @@ namespace Emby.Server.Implementations.HttpClientManager private HttpResponseInfo GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url) { - try - { - if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow) - { - var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true); - - return new HttpResponseInfo - { - ResponseUrl = url, - Content = stream, - StatusCode = HttpStatusCode.OK, - ContentLength = stream.Length - }; - } - } - catch (FileNotFoundException) // REVIEW: @bond Is this really faster? - { - - } - catch (DirectoryNotFoundException) + if (File.Exists(responseCachePath) + && _fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow) { + var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true); + return new HttpResponseInfo + { + ResponseUrl = url, + Content = stream, + StatusCode = HttpStatusCode.OK, + ContentLength = stream.Length + }; } return null; |
