Fixed compilation, added backing db before removing extras

This commit is contained in:
Vasily 2020-05-15 21:49:45 +03:00
parent 034fe97eeb
commit 43dc604e87
2 changed files with 25 additions and 4 deletions

View File

@ -18,7 +18,7 @@ namespace Jellyfin.Server.Migrations
{ {
typeof(Routines.DisableTranscodingThrottling), typeof(Routines.DisableTranscodingThrottling),
typeof(Routines.CreateUserLoggingConfigFile), typeof(Routines.CreateUserLoggingConfigFile),
typeof(Routines.RemoveBuggedExtras) typeof(Routines.RemoveDuplicateExtras)
}; };
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using MediaBrowser.Controller; using MediaBrowser.Controller;
@ -16,7 +17,7 @@ namespace Jellyfin.Server.Migrations.Routines
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IServerApplicationPaths _paths; private readonly IServerApplicationPaths _paths;
public RemoveBuggedExtras(ILogger<RemoveBuggedExtras> logger, IServerApplicationPaths paths) public RemoveDuplicateExtras(ILogger<RemoveDuplicateExtras> logger, IServerApplicationPaths paths)
{ {
_logger = logger; _logger = logger;
_paths = paths; _paths = paths;
@ -26,14 +27,15 @@ namespace Jellyfin.Server.Migrations.Routines
public Guid Id => Guid.Parse("{ACBE17B7-8435-4A83-8B64-6FCF162CB9BD}"); public Guid Id => Guid.Parse("{ACBE17B7-8435-4A83-8B64-6FCF162CB9BD}");
/// <inheritdoc/> /// <inheritdoc/>
public string Name => "RemoveBuggedExtras"; public string Name => "RemoveDuplicateExtras";
/// <inheritdoc/> /// <inheritdoc/>
public void Perform() public void Perform()
{ {
var dataPath = _paths.DataPath; var dataPath = _paths.DataPath;
var dbPath = Path.Combine(dataPath, DbFilename);
using (var connection = SQLite3.Open( using (var connection = SQLite3.Open(
Path.Combine(dataPath, DbFilename), dbPath,
ConnectionFlags.ReadWrite, ConnectionFlags.ReadWrite,
null)) null))
{ {
@ -41,6 +43,25 @@ namespace Jellyfin.Server.Migrations.Routines
var bads = string.Join(", ", queryResult.SelectScalarString()); var bads = string.Join(", ", queryResult.SelectScalarString());
if (bads.Length != 0) if (bads.Length != 0)
{ {
_logger.LogInformation("Found duplicate extras, making {Library} backup", DbFilename);
for (int i = 1; ; i++)
{
var bakPath = string.Format(CultureInfo.InvariantCulture, "{0}.bak{1}", dbPath, i);
if (!File.Exists(bakPath))
{
try
{
File.Copy(dbPath, bakPath);
break;
}
catch (Exception ex)
{
_logger.LogError(ex, "Cannot make a backup of {Library}", DbFilename);
throw;
}
}
}
_logger.LogInformation("Removing found duplicated extras for the following items: {DuplicateExtras}", bads); _logger.LogInformation("Removing found duplicated extras for the following items: {DuplicateExtras}", bads);
connection.Execute("DELETE FROM TypedBaseItems WHERE rowid IN (SELECT t1.rowid FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video')"); connection.Execute("DELETE FROM TypedBaseItems WHERE rowid IN (SELECT t1.rowid FROM TypedBaseItems AS t1, TypedBaseItems AS t2 WHERE t1.Path=t2.Path AND t1.Type!=t2.Type AND t1.Type='MediaBrowser.Controller.Entities.Video')");
} }