aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/ScheduledTasks
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/ScheduledTasks')
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs28
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs52
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/TaskManager.cs2
-rw-r--r--Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs2
4 files changed, 35 insertions, 49 deletions
diff --git a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs
index 0ae7ae96c..5373b4392 100644
--- a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs
@@ -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();
- }
- catch (FileNotFoundException)
- {
- previouslyFailedImages = new List<string>();
+ try
+ {
+ previouslyFailedImages = File.ReadAllText(failHistoryPath)
+ .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
+ .ToList();
+ }
+ catch (IOException)
+ {
+ previouslyFailedImages = new List<string>();
+ }
}
- catch (IOException)
+ else
{
previouslyFailedImages = new List<string>();
}
@@ -136,11 +139,12 @@ namespace Emby.Server.Implementations.ScheduledTasks
{
previouslyFailedImages.Add(key);
- var parentPath = _fileSystem.GetDirectoryName(failHistoryPath);
+ var parentPath = Path.GetDirectoryName(failHistoryPath);
- _fileSystem.CreateDirectory(parentPath);
+ Directory.CreateDirectory(parentPath);
- _fileSystem.WriteAllText(failHistoryPath, string.Join("|", previouslyFailedImages.ToArray()));
+ string text = string.Join("|", previouslyFailedImages);
+ File.WriteAllText(failHistoryPath, text);
}
numComplete++;
diff --git a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
index 93a9a0d81..2b648b04b 100644
--- a/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
@@ -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;
}
@@ -156,7 +151,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
_lastExecutionResult = value;
var path = GetHistoryFilePath();
- _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
lock (_lastExecutionResultSyncLock)
{
@@ -532,28 +527,15 @@ namespace Emby.Server.Implementations.ScheduledTasks
private TaskTriggerInfo[] LoadTriggerSettings()
{
- try
+ string path = GetConfigurationFilePath();
+ TaskTriggerInfo[] list = null;
+ if (File.Exists(path))
{
- var list = JsonSerializer.DeserializeFromFile<IEnumerable<TaskTriggerInfo>>(GetConfigurationFilePath());
-
- if (list != null)
- {
- return list.ToArray();
- }
- }
- catch (FileNotFoundException)
- {
- // File doesn't exist. No biggie. Return defaults.
- }
- catch (DirectoryNotFoundException)
- {
- // File doesn't exist. No biggie. Return defaults.
+ list = JsonSerializer.DeserializeFromFile<TaskTriggerInfo[]>(path);
}
- catch
- {
- }
- return GetDefaultTriggers();
+ // Return defaults if file doesn't exist.
+ return list ?? GetDefaultTriggers();
}
private TaskTriggerInfo[] GetDefaultTriggers()
@@ -583,7 +565,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
{
var path = GetConfigurationFilePath();
- _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
JsonSerializer.SerializeToFile(triggers, path);
}
diff --git a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs
index d74c8fe8c..b8479fd26 100644
--- a/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/TaskManager.cs
@@ -86,7 +86,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
try
{
- lines = _fileSystem.ReadAllLines(path).Where(i => !string.IsNullOrWhiteSpace(i)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
+ lines = File.ReadAllLines(path).Where(i => !string.IsNullOrWhiteSpace(i)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
foreach (var key in lines)
{
diff --git a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
index 2590f455c..52077b242 100644
--- a/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
+++ b/Emby.Server.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs
@@ -128,7 +128,7 @@ namespace Emby.Server.Implementations.ScheduledTasks.Tasks
{
try
{
- _fileSystem.DeleteDirectory(directory, false);
+ Directory.Delete(directory, false);
}
catch (UnauthorizedAccessException ex)
{