aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <daullmer@gmail.com>2020-12-23 21:00:50 +0100
committerDavid <daullmer@gmail.com>2020-12-23 21:00:50 +0100
commita714008b596b108a44020f61ca384b30263df984 (patch)
tree1f259c5e094163f44ccfb4c0720a5457bbf5119e
parent2a574914eaca486f6216db400d9fdf88ad88636e (diff)
Add missing FileStreams
-rw-r--r--Emby.Server.Implementations/Channels/ChannelManager.cs11
-rw-r--r--Emby.Server.Implementations/Library/LiveStreamHelper.cs6
2 files changed, 9 insertions, 8 deletions
diff --git a/Emby.Server.Implementations/Channels/ChannelManager.cs b/Emby.Server.Implementations/Channels/ChannelManager.cs
index b462d7bdc..3663e5094 100644
--- a/Emby.Server.Implementations/Channels/ChannelManager.cs
+++ b/Emby.Server.Implementations/Channels/ChannelManager.cs
@@ -341,7 +341,8 @@ namespace Emby.Server.Implementations.Channels
try
{
using FileStream jsonStream = File.OpenRead(path);
- return JsonSerializer.DeserializeAsync<List<MediaSourceInfo>>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
+ return JsonSerializer.DeserializeAsync<List<MediaSourceInfo>>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult()
+ ?? new List<MediaSourceInfo>();
}
catch
{
@@ -810,8 +811,8 @@ namespace Emby.Server.Implementations.Channels
{
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
{
- var jsonString = await File.ReadAllTextAsync(cachePath, cancellationToken);
- var cachedResult = JsonSerializer.Deserialize<ChannelItemResult>(jsonString);
+ await using FileStream jsonStream = File.OpenRead(cachePath);
+ var cachedResult = await JsonSerializer.DeserializeAsync<ChannelItemResult>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
if (cachedResult != null)
{
return null;
@@ -833,8 +834,8 @@ namespace Emby.Server.Implementations.Channels
{
if (_fileSystem.GetLastWriteTimeUtc(cachePath).Add(cacheLength) > DateTime.UtcNow)
{
- var jsonString = await File.ReadAllTextAsync(cachePath, cancellationToken);
- var cachedResult = JsonSerializer.Deserialize<ChannelItemResult>(jsonString);
+ await using FileStream jsonStream = File.OpenRead(cachePath);
+ var cachedResult = await JsonSerializer.DeserializeAsync<ChannelItemResult>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
if (cachedResult != null)
{
return null;
diff --git a/Emby.Server.Implementations/Library/LiveStreamHelper.cs b/Emby.Server.Implementations/Library/LiveStreamHelper.cs
index 3ceba0fe9..80729a280 100644
--- a/Emby.Server.Implementations/Library/LiveStreamHelper.cs
+++ b/Emby.Server.Implementations/Library/LiveStreamHelper.cs
@@ -47,7 +47,7 @@ namespace Emby.Server.Implementations.Library
try
{
await using FileStream jsonStream = File.OpenRead(cacheFilePath);
- await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
+ mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
// _logger.LogDebug("Found cached media info");
}
@@ -83,8 +83,8 @@ namespace Emby.Server.Implementations.Library
if (cacheFilePath != null)
{
Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
- await using FileStream createStream = File.Create(cacheFilePath);
- await JsonSerializer.SerializeAsync(createStream, mediaInfo, cancellationToken: cancellationToken).ConfigureAwait(false);
+ await using FileStream createStream = File.OpenWrite(cacheFilePath);
+ await JsonSerializer.SerializeAsync(createStream, mediaInfo, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
// _logger.LogDebug("Saved media info to {0}", cacheFilePath);
}