mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 23:42:33 +01:00
Fixed: Bad extension when importing extra files
This commit is contained in:
parent
47e221d9a0
commit
47915d5e05
@ -0,0 +1,61 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class fix_extra_file_extensionsFixture : MigrationTest<fix_extra_file_extension>
|
||||
{
|
||||
[Test]
|
||||
public void should_fix_double_extension()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("SubtitleFiles").Row(new
|
||||
{
|
||||
SeriesId = 1,
|
||||
SeasonNumber = 1,
|
||||
EpisodeFileId = 1,
|
||||
RelativePath = "Series.Title.S01E01.en.srt",
|
||||
Added = "2016-05-30 20:23:02.3725923",
|
||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
||||
Language = Language.English,
|
||||
Extension = "en.srt"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query("Select * from SubtitleFiles");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First()["Extension"].Should().Be(".srt");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fix_extension_missing_a_leading_period()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("ExtraFiles").Row(new
|
||||
{
|
||||
SeriesId = 1,
|
||||
SeasonNumber = 1,
|
||||
EpisodeFileId = 1,
|
||||
RelativePath = "Series.Title.S01E01.nfo-orig",
|
||||
Added = "2016-05-30 20:23:02.3725923",
|
||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
||||
Extension = "nfo-orig"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query("Select * from ExtraFiles");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First()["Extension"].Should().Be(".nfo-orig");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -124,6 +124,7 @@
|
||||
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
|
||||
<Compile Include="Datastore\MappingExtentionFixture.cs" />
|
||||
<Compile Include="Datastore\MarrDataLazyLoadingFixture.cs" />
|
||||
<Compile Include="Datastore\Migration\108_fix_metadata_file_extensionsFixture.cs" />
|
||||
<Compile Include="Datastore\Migration\106_update_btn_urlFixture.cs" />
|
||||
<Compile Include="Datastore\Migration\103_fix_metadata_file_extensionsFixture.cs" />
|
||||
<Compile Include="Datastore\Migration\099_extra_and_subtitle_filesFixture.cs" />
|
||||
|
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(108)]
|
||||
public class fix_extra_file_extension : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Execute.WithConnection(FixExtraFileExtension);
|
||||
}
|
||||
|
||||
private void FixExtraFileExtension(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
FixExtraFileExtensionForTable(conn, tran, "ExtraFiles");
|
||||
FixExtraFileExtensionForTable(conn, tran, "SubtitleFiles");
|
||||
}
|
||||
|
||||
private void FixExtraFileExtensionForTable(IDbConnection conn, IDbTransaction tran, string table)
|
||||
{
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.Transaction = tran;
|
||||
cmd.CommandText = $"SELECT Id, RelativePath FROM {table}";
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = reader.GetInt32(0);
|
||||
var relativePath = reader.GetString(1);
|
||||
var extension = relativePath.Substring(relativePath.LastIndexOf(".", StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
using (var updateCmd = conn.CreateCommand())
|
||||
{
|
||||
updateCmd.Transaction = tran;
|
||||
updateCmd.CommandText = $"UPDATE {table} SET Extension = ? WHERE Id = ?";
|
||||
updateCmd.AddParameter(extension);
|
||||
updateCmd.AddParameter(id);
|
||||
|
||||
updateCmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -81,7 +81,8 @@ namespace NzbDrone.Core.Extras
|
||||
{
|
||||
foreach (var extraFileManager in _extraFileManagers)
|
||||
{
|
||||
var extraFile = extraFileManager.Import(series, episodeFile, matchingFilename, matchingExtension, isReadOnly);
|
||||
var extension = Path.GetExtension(matchingFilename);
|
||||
var extraFile = extraFileManager.Import(series, episodeFile, matchingFilename, extension, isReadOnly);
|
||||
|
||||
if (extraFile != null)
|
||||
{
|
||||
|
@ -90,6 +90,7 @@ namespace NzbDrone.Core.Extras.Files
|
||||
filenameBuilder.Append(fileNameSuffix);
|
||||
}
|
||||
|
||||
filenameBuilder.Append(".");
|
||||
filenameBuilder.Append(extraFile.Extension);
|
||||
|
||||
var existingFileName = Path.Combine(series.Path, extraFile.RelativePath);
|
||||
|
@ -101,24 +101,21 @@ namespace NzbDrone.Core.Extras.Subtitles
|
||||
|
||||
private string GetSuffix(Language language, int copy, bool multipleCopies = false)
|
||||
{
|
||||
var extensionBuilder = new StringBuilder(".");
|
||||
var suffixBuilder = new StringBuilder();
|
||||
|
||||
if (multipleCopies)
|
||||
{
|
||||
extensionBuilder.Append(copy);
|
||||
}
|
||||
|
||||
if (multipleCopies && language != Language.Unknown)
|
||||
{
|
||||
extensionBuilder.Append(".");
|
||||
suffixBuilder.Append(".");
|
||||
suffixBuilder.Append(copy);
|
||||
}
|
||||
|
||||
if (language != Language.Unknown)
|
||||
{
|
||||
extensionBuilder.Append(IsoLanguages.Get(language).TwoLetterCode);
|
||||
suffixBuilder.Append(".");
|
||||
suffixBuilder.Append(IsoLanguages.Get(language).TwoLetterCode);
|
||||
}
|
||||
|
||||
return extensionBuilder.ToString();
|
||||
return suffixBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -249,6 +249,7 @@
|
||||
<Compile Include="Datastore\Migration\068_add_release_restrictions.cs" />
|
||||
<Compile Include="Datastore\Migration\069_quality_proper.cs" />
|
||||
<Compile Include="Datastore\Migration\070_delay_profile.cs" />
|
||||
<Compile Include="Datastore\Migration\108_fix_extra_file_extension.cs" />
|
||||
<Compile Include="Datastore\Migration\107_remove_wombles.cs" />
|
||||
<Compile Include="Datastore\Migration\106_update_btn_url.cs" />
|
||||
<Compile Include="Datastore\Migration\096_disable_kickass.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user