1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 02:22:31 +01:00

Fixed: Metadata files incorrectly stored in database

This commit is contained in:
Mark McDowall 2016-06-15 23:53:23 -07:00
parent 4783803b6b
commit 8e429239a8
8 changed files with 126 additions and 28 deletions

View File

@ -0,0 +1,65 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Housekeeping.Housekeepers;
using NzbDrone.Core.Metadata;
using NzbDrone.Core.Metadata.Files;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.Housekeeping.Housekeepers
{
[TestFixture]
public class CleanupAbsolutePathMetadataFilesFixture : DbTest<CleanupAbsolutePathMetadataFiles, MetadataFile>
{
[Test]
public void should_not_delete_metadata_files_that_have_a_relative_path()
{
var relativePath = @"C:\Test\".AsOsAgnostic().GetRelativePath(@"C:\Test\Relative\Path");
var file = Builder<MetadataFile>.CreateNew()
.With(m => m.RelativePath = relativePath)
.BuildNew();
Db.Insert(file);
Subject.Clean();
AllStoredModels.Count.Should().Be(1);
}
[Test]
public void should_delete_metadata_files_that_start_with_a_drive_letter()
{
var file = Builder<MetadataFile>.CreateNew()
.With(m => m.RelativePath = @"C:\Relative\Path")
.BuildNew();
Db.Insert(file);
Subject.Clean();
AllStoredModels.Count.Should().Be(0);
}
[Test]
public void should_delete_metadata_files_that_start_with_a_forward_slash()
{
var file = Builder<MetadataFile>.CreateNew()
.With(m => m.RelativePath = @"/Relative/Path")
.BuildNew();
Db.Insert(file);
Subject.Clean();
AllStoredModels.Count.Should().Be(0);
}
[Test]
public void should_delete_metadata_files_that_start_with_a_backslash()
{
var file = Builder<MetadataFile>.CreateNew()
.With(m => m.RelativePath = @"\\Relative\Path")
.BuildNew();
Db.Insert(file);
Subject.Clean();
AllStoredModels.Count.Should().Be(0);
}
}
}

View File

@ -212,6 +212,7 @@
<Compile Include="HistoryTests\HistoryServiceFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalUsersFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecsFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAbsolutePathMetadataFilesFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupDuplicateMetadataFilesFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedBlacklistFixture.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFilesFixture.cs" />

View File

@ -0,0 +1,30 @@
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Housekeeping.Housekeepers
{
public class CleanupAbsolutePathMetadataFiles : IHousekeepingTask
{
private readonly IMainDatabase _database;
public CleanupAbsolutePathMetadataFiles(IMainDatabase database)
{
_database = database;
}
public void Clean()
{
var mapper = _database.GetDataMapper();
mapper.ExecuteNonQuery(@"DELETE FROM MetadataFiles
WHERE Id IN (
SELECT Id FROM MetadataFiles
WHERE RelativePath
LIKE '_:\%'
OR RelativePath
LIKE '\%'
OR RelativePath
LIKE '/%'
)");
}
}
}

View File

@ -88,37 +88,30 @@ public override MetadataFileResult SeriesMetadata(Series series)
tvShow.Add(new XElement("Status", series.Status));
tvShow.Add(new XElement("Network", series.Network));
tvShow.Add(new XElement("Airs_Time", series.AirTime));
//tvShow.Add(new XElement("Airs_DayOfWeek",
if (series.FirstAired.HasValue)
{
tvShow.Add(new XElement("FirstAired", series.FirstAired.Value.ToString("yyyy-MM-dd")));
}
tvShow.Add(new XElement("ContentRating", series.Certification));
tvShow.Add(new XElement("Added", series.Added.ToString("MM/dd/yyyy HH:mm:ss tt")));
tvShow.Add(new XElement("LockData", "false"));
tvShow.Add(new XElement("Overview", series.Overview));
tvShow.Add(new XElement("LocalTitle", series.Title));
if (series.FirstAired.HasValue)
{
tvShow.Add(new XElement("PremiereDate", series.FirstAired.Value.ToString("yyyy-MM-dd")));
}
//tvShow.Add(new XElement("EndDate", series.EndDate.ToString("yyyy-MM-dd")));
tvShow.Add(new XElement("Rating", series.Ratings.Value));
//tvShow.Add(new XElement("VoteCount",
tvShow.Add(new XElement("ProductionYear", series.Year));
//tvShow.Add(new XElement("Website",
tvShow.Add(new XElement("RunningTime", series.Runtime));
tvShow.Add(new XElement("IMDB", series.ImdbId));
//tvShow.Add(new XElement("TMDbId",
//tvShow.Add(new XElement("Zap2itId",
tvShow.Add(new XElement("TVRageId", series.TvRageId));
tvShow.Add(new XElement("Genres", series.Genres.Select(genre => new XElement("Genre", genre))));
// Studios
// Studio
// Studio
// ??
var persons = new XElement("Persons");
foreach (var person in series.Actors)
@ -138,7 +131,7 @@ public override MetadataFileResult SeriesMetadata(Series series)
_logger.Debug("Saving series.xml for {0}", series.Title);
return new MetadataFileResult(Path.Combine(series.Path, "series.xml"), doc.ToString());
return new MetadataFileResult("series.xml", doc.ToString());
}
}

View File

@ -70,18 +70,19 @@ public override List<MetadataFile> AfterRename(Series series, List<MetadataFile>
continue;
}
var existingFilename = Path.Combine(series.Path, metadataFile.RelativePath);
newFilename = Path.Combine(series.Path, newFilename);
var existingPath = Path.Combine(series.Path, metadataFile.RelativePath);
var newPath = Path.Combine(series.Path, newFilename);
if (!newFilename.PathEquals(existingFilename))
if (!newPath.PathEquals(existingPath))
{
_diskProvider.MoveFile(existingFilename, newFilename);
metadataFile.RelativePath = series.Path.GetRelativePath(newFilename);
_diskProvider.MoveFile(existingPath, newPath);
metadataFile.RelativePath = newFilename;
updatedMetadataFiles.Add(metadataFile);
}
}
}
return updatedMetadataFiles;
}
@ -217,7 +218,7 @@ public override List<ImageFileResult> SeriesImages(Series series)
}
var source = _mediaCoverService.GetCoverPath(series.Id, image.CoverType);
var destination = Path.Combine(series.Path, "folder" + Path.GetExtension(source));
var destination = "folder" + Path.GetExtension(source);
return new List<ImageFileResult>
{
@ -250,7 +251,7 @@ public override List<ImageFileResult> SeasonImages(Series series, Season season)
return new List<ImageFileResult>();
}
var path = Path.Combine(series.Path, seasonFolder, "folder.jpg");
var path = Path.Combine(seasonFolder, "folder.jpg");
return new List<ImageFileResult>{ new ImageFileResult(path, image.Url) };
}

View File

@ -222,7 +222,7 @@ public override MetadataFileResult SeriesMetadata(Series series)
_logger.Debug("Saving tvshow.nfo for {0}", series.Title);
return new MetadataFileResult(Path.Combine(series.Path, "tvshow.nfo"), doc.ToString());
return new MetadataFileResult("tvshow.nfo", doc.ToString());
}
}
@ -386,7 +386,7 @@ private IEnumerable<ImageFileResult> ProcessSeriesImages(Series series)
foreach (var image in series.Images)
{
var source = _mediaCoverService.GetCoverPath(series.Id, image.CoverType);
var destination = Path.Combine(series.Path, image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(source));
var destination = image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(source);
yield return new ImageFileResult(destination, source);
}
@ -403,7 +403,7 @@ private IEnumerable<ImageFileResult> ProcessSeasonImages(Series series, Season s
filename = string.Format("season-specials-{0}.jpg", image.CoverType.ToString().ToLower());
}
yield return new ImageFileResult(Path.Combine(series.Path, filename), image.Url);
yield return new ImageFileResult(filename, image.Url);
}
}

View File

@ -183,11 +183,18 @@ private MetadataFile ProcessSeriesMetadata(IMetadata consumer, Series series, Li
{
SeriesId = series.Id,
Consumer = consumer.GetType().Name,
Type = MetadataType.SeriesMetadata,
Type = MetadataType.SeriesMetadata
};
if (hash == metadata.Hash)
{
if (seriesMetadata.RelativePath != metadata.RelativePath)
{
metadata.RelativePath = seriesMetadata.RelativePath;
return metadata;
}
return null;
}
@ -273,7 +280,7 @@ private List<MetadataFile> ProcessSeriesImages(IMetadata consumer, Series series
RelativePath = image.RelativePath
};
_diskProvider.CopyFile(image.Url, image.RelativePath);
_diskProvider.CopyFile(image.Url, Path.Combine(series.Path, image.RelativePath));
_mediaFileAttributeService.SetFilePermissions(image.RelativePath);
result.Add(metadata);
@ -368,16 +375,16 @@ private List<MetadataFile> ProcessEpisodeImages(IMetadata consumer, Series serie
return result;
}
private void DownloadImage(Series series, string url, string path)
private void DownloadImage(Series series, string url, string relativePath)
{
try
{
_httpClient.DownloadFile(url, path);
_mediaFileAttributeService.SetFilePermissions(path);
_httpClient.DownloadFile(url, Path.Combine(series.Path, relativePath));
_mediaFileAttributeService.SetFilePermissions(relativePath);
}
catch (WebException e)
{
_logger.Warn(string.Format("Couldn't download image {0} for {1}. {2}", url, series, e.Message));
_logger.Warn("Couldn't download image {0} for {1}. {2}", url, series, e.Message);
}
catch (Exception e)
{

View File

@ -510,6 +510,7 @@
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalUsers.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAdditionalNamingSpecs.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupCommandQueue.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupAbsolutePathMetadataFiles.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupDuplicateMetadataFiles.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedBlacklist.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedEpisodeFiles.cs" />