mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-27 04:22:08 +00:00
Check if file exists instead of catching exceptions
This commit is contained in:
@@ -101,17 +101,20 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
|
||||
List<string> previouslyFailedImages;
|
||||
|
||||
try
|
||||
if (File.Exists(failHistoryPath))
|
||||
{
|
||||
previouslyFailedImages = _fileSystem.ReadAllText(failHistoryPath)
|
||||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.ToList();
|
||||
try
|
||||
{
|
||||
previouslyFailedImages = _fileSystem.ReadAllText(failHistoryPath)
|
||||
.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.ToList();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
previouslyFailedImages = new List<string>();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
previouslyFailedImages = new List<string>();
|
||||
}
|
||||
catch (IOException)
|
||||
else
|
||||
{
|
||||
previouslyFailedImages = new List<string>();
|
||||
}
|
||||
|
||||
@@ -129,21 +129,16 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
{
|
||||
if (_lastExecutionResult == null && !_readFromFile)
|
||||
{
|
||||
try
|
||||
if (File.Exists(path))
|
||||
{
|
||||
_lastExecutionResult = JsonSerializer.DeserializeFromFile<TaskResult>(path);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
// File doesn't exist. No biggie
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// File doesn't exist. No biggie
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error deserializing {path}", path);
|
||||
try
|
||||
{
|
||||
_lastExecutionResult = JsonSerializer.DeserializeFromFile<TaskResult>(path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Error deserializing {File}", path);
|
||||
}
|
||||
}
|
||||
_readFromFile = true;
|
||||
}
|
||||
@@ -532,28 +527,16 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
|
||||
private TaskTriggerInfo[] LoadTriggerSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = JsonSerializer.DeserializeFromFile<IEnumerable<TaskTriggerInfo>>(GetConfigurationFilePath());
|
||||
|
||||
if (list != null)
|
||||
{
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
string path = GetConfigurationFilePath();
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
// File doesn't exist. No biggie. Return defaults.
|
||||
GetDefaultTriggers();
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
// File doesn't exist. No biggie. Return defaults.
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
return GetDefaultTriggers();
|
||||
var list = JsonSerializer.DeserializeFromFile<TaskTriggerInfo[]>(path);
|
||||
|
||||
return list ?? GetDefaultTriggers();
|
||||
}
|
||||
|
||||
private TaskTriggerInfo[] GetDefaultTriggers()
|
||||
|
||||
Reference in New Issue
Block a user