mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Prevent NullRef when deleting missing backups
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Prowlarr.Api.V1.System.Backup
|
|||||||
private readonly IAppFolderInfo _appFolderInfo;
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
|
||||||
private static readonly List<string> ValidExtensions = new List<string> { ".zip", ".db", ".xml" };
|
private static readonly List<string> ValidExtensions = new () { ".zip", ".db", ".xml" };
|
||||||
|
|
||||||
public BackupController(IBackupService backupService,
|
public BackupController(IBackupService backupService,
|
||||||
IAppFolderInfo appFolderInfo,
|
IAppFolderInfo appFolderInfo,
|
||||||
@@ -38,22 +38,28 @@ namespace Prowlarr.Api.V1.System.Backup
|
|||||||
var backups = _backupService.GetBackups();
|
var backups = _backupService.GetBackups();
|
||||||
|
|
||||||
return backups.Select(b => new BackupResource
|
return backups.Select(b => new BackupResource
|
||||||
{
|
{
|
||||||
Id = GetBackupId(b),
|
Id = GetBackupId(b),
|
||||||
Name = b.Name,
|
Name = b.Name,
|
||||||
Path = $"/backup/{b.Type.ToString().ToLower()}/{b.Name}",
|
Path = $"/backup/{b.Type.ToString().ToLower()}/{b.Name}",
|
||||||
Type = b.Type,
|
Type = b.Type,
|
||||||
Size = b.Size,
|
Size = b.Size,
|
||||||
Time = b.Time
|
Time = b.Time
|
||||||
})
|
})
|
||||||
.OrderByDescending(b => b.Time)
|
.OrderByDescending(b => b.Time)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
[RestDeleteById]
|
[RestDeleteById]
|
||||||
public void DeleteBackup(int id)
|
public void DeleteBackup(int id)
|
||||||
{
|
{
|
||||||
var backup = GetBackup(id);
|
var backup = GetBackup(id);
|
||||||
|
|
||||||
|
if (backup == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
var path = GetBackupPath(backup);
|
var path = GetBackupPath(backup);
|
||||||
|
|
||||||
if (!_diskProvider.FileExists(path))
|
if (!_diskProvider.FileExists(path))
|
||||||
|
Reference in New Issue
Block a user