From d008768fff9512ffdfe95e84cf349b5f5aa40ff1 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 17 Jun 2023 02:08:40 +0300 Subject: [PATCH] Prevent NullRef when deleting missing backups (cherry picked from commit 0ff0fe2e68f3abf7b8e4d6bf0c1e9dee4eb68227) Closes #8721 --- .../System/Backup/BackupController.cs | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Radarr.Api.V3/System/Backup/BackupController.cs b/src/Radarr.Api.V3/System/Backup/BackupController.cs index 4077fb87a..16d13a315 100644 --- a/src/Radarr.Api.V3/System/Backup/BackupController.cs +++ b/src/Radarr.Api.V3/System/Backup/BackupController.cs @@ -20,7 +20,7 @@ public class BackupController : Controller private readonly IAppFolderInfo _appFolderInfo; private readonly IDiskProvider _diskProvider; - private static readonly List ValidExtensions = new List { ".zip", ".db", ".xml" }; + private static readonly List ValidExtensions = new () { ".zip", ".db", ".xml" }; public BackupController(IBackupService backupService, IAppFolderInfo appFolderInfo, @@ -37,22 +37,28 @@ public List GetBackupFiles() var backups = _backupService.GetBackups(); return backups.Select(b => new BackupResource - { - Id = GetBackupId(b), - Name = b.Name, - Path = $"/backup/{b.Type.ToString().ToLower()}/{b.Name}", - Type = b.Type, - Size = b.Size, - Time = b.Time - }) - .OrderByDescending(b => b.Time) - .ToList(); + { + Id = GetBackupId(b), + Name = b.Name, + Path = $"/backup/{b.Type.ToString().ToLower()}/{b.Name}", + Type = b.Type, + Size = b.Size, + Time = b.Time + }) + .OrderByDescending(b => b.Time) + .ToList(); } [RestDeleteById] public void DeleteBackup(int id) { var backup = GetBackup(id); + + if (backup == null) + { + throw new NotFoundException(); + } + var path = GetBackupPath(backup); if (!_diskProvider.FileExists(path))