Fixed: Don't handle images in metadata folder as Roksbox images

(cherry picked from commit 95a8f59a32d55550d5367f08a964859a97a0df44)
pull/8745/head
Mark McDowall 2 years ago committed by Bogdan
parent 239109e3dd
commit 77cde138dc

@ -158,6 +158,25 @@ namespace NzbDrone.Common.Test
path.GetParentPath().Should().Be(parentPath);
}
[TestCase(@"C:\Test\mydir", "Test")]
[TestCase(@"C:\Test\", @"C:\")]
[TestCase(@"C:\", null)]
[TestCase(@"\\server\share", null)]
[TestCase(@"\\server\share\test", @"\\server\share")]
public void path_should_return_parent_name_windows(string path, string parentPath)
{
WindowsOnly();
path.GetParentName().Should().Be(parentPath);
}
[TestCase(@"/", null)]
[TestCase(@"/test", "/")]
public void path_should_return_parent_name_mono(string path, string parentPath)
{
PosixOnly();
path.GetParentName().Should().Be(parentPath);
}
[Test]
public void path_should_return_parent_for_oversized_path()
{

@ -87,9 +87,7 @@ namespace NzbDrone.Common.Extensions
public static string GetParentPath(this string childPath)
{
var cleanPath = OsInfo.IsWindows
? PARENT_PATH_END_SLASH_REGEX.Replace(childPath, "")
: childPath.TrimEnd(Path.DirectorySeparatorChar);
var cleanPath = childPath.GetCleanPath();
if (cleanPath.IsNullOrWhiteSpace())
{
@ -99,6 +97,13 @@ namespace NzbDrone.Common.Extensions
return Directory.GetParent(cleanPath)?.FullName;
}
public static string GetParentName(this string childPath)
{
var cleanPath = childPath.GetCleanPath();
return Directory.GetParent(cleanPath)?.Name;
}
public static string GetCleanPath(this string path)
{
var cleanPath = OsInfo.IsWindows

@ -0,0 +1,64 @@
using System;
using System.Linq;
using Dapper;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Datastore.Migration;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.Datastore.Migration
{
[TestFixture]
public class remove_invalid_roksbox_metadata_imagesFixture : MigrationTest<remove_invalid_roksbox_metadata_images>
{
[Test]
public void should_remove_incorrect_roksbox_metadata_images()
{
var db = WithDapperMigrationTestDb(c =>
{
c.Insert.IntoTable("MetadataFiles").Row(new
{
MovieId = 1,
Consumer = "RoksboxMetadata",
Type = 5,
RelativePath = @"metadata\Movie Title (2023).jpg",
LastUpdated = "2023-01-21 00:00:00.000",
Added = "2023-01-21 00:00:00.000",
MovieFileId = 1,
Extension = ".jpg"
});
c.Insert.IntoTable("MetadataFiles").Row(new
{
MovieId = 1,
Consumer = "RoksboxMetadata",
Type = 5,
RelativePath = @"Movie Title (2023).jpg",
LastUpdated = "2023-01-21 00:00:00.000",
MovieFileId = 1,
Added = "2023-01-21 00:00:00.000",
Extension = ".jpg"
});
});
var metadataFiles = db.Query<MetadataFile223>("SELECT * FROM \"MetadataFiles\"");
metadataFiles.Should().HaveCount(1);
metadataFiles.First().RelativePath.Should().NotContain("metadata");
}
}
public class MetadataFile223
{
public int Id { get; set; }
public int MovieId { get; set; }
public int? MovieFileId { get; set; }
public string RelativePath { get; set; }
public DateTime Added { get; set; }
public DateTime LastUpdated { get; set; }
public string Extension { get; set; }
public string Hash { get; set; }
public string Consumer { get; set; }
public int Type { get; set; }
}
}

@ -0,0 +1,15 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Migration(223)]
public class remove_invalid_roksbox_metadata_images : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
IfDatabase("sqlite").Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE 'metadata/%' OR \"RelativePath\" LIKE 'metadata\\%')");
IfDatabase("postgresql").Execute.Sql("DELETE FROM \"MetadataFiles\" WHERE \"Consumer\" = 'RoksboxMetadata' AND \"Type\" = 5 AND (\"RelativePath\" LIKE 'metadata/%' OR \"RelativePath\" LIKE 'metadata\\\\%')");
}
}
}

@ -84,7 +84,8 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Roksbox
if (extension == ".jpg")
{
if (Path.GetFileNameWithoutExtension(filename).Equals(parentdir.Name, StringComparison.InvariantCultureIgnoreCase))
if (Path.GetFileNameWithoutExtension(filename).Equals(parentdir.Name, StringComparison.InvariantCultureIgnoreCase) &&
!path.GetParentName().Equals("metadata", StringComparison.InvariantCultureIgnoreCase))
{
metadata.Type = MetadataType.MovieImage;
return metadata;

Loading…
Cancel
Save