1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-02-26 15:52:42 +00:00

Fixed: Update modified times as well as sizes

This commit is contained in:
ta264 2019-07-19 13:41:17 +01:00
parent dc44bbd210
commit 343b27b886
2 changed files with 33 additions and 4 deletions

View file

@ -12,6 +12,7 @@
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
{ {
@ -47,10 +48,15 @@ public static IEnumerable TestCases
private readonly string testdir = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media"); private readonly string testdir = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media");
private string copiedFile; private string copiedFile;
private AudioTag testTags; private AudioTag testTags;
private IDiskProvider _diskProvider;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_diskProvider = Mocker.Resolve<IDiskProvider>("ActualDiskProvider");
Mocker.SetConstant<IDiskProvider>(_diskProvider);
Mocker.GetMock<IConfigService>() Mocker.GetMock<IConfigService>()
.Setup(x => x.WriteAudioTags) .Setup(x => x.WriteAudioTags)
.Returns(WriteAudioTagsType.Sync); .Returns(WriteAudioTagsType.Sync);
@ -344,6 +350,7 @@ private TrackFile GivenPopulatedTrackfile()
var file = Builder<TrackFile>.CreateNew() var file = Builder<TrackFile>.CreateNew()
.With(x => x.Tracks = new List<Track> { tracks[0] }) .With(x => x.Tracks = new List<Track> { tracks[0] })
.With(x => x.Artist = artist)
.Build(); .Build();
return file; return file;
@ -357,5 +364,24 @@ public void get_metadata_should_not_fail_with_missing_country()
tag.MusicBrainzReleaseCountry.Should().BeNull(); tag.MusicBrainzReleaseCountry.Should().BeNull();
} }
[TestCase("nin.mp3")]
public void write_tags_should_update_trackfile_size_and_modified(string filename)
{
Mocker.GetMock<IConfigService>()
.Setup(x => x.ScrubAudioTags)
.Returns(true);
GivenFileCopy(filename);
var file = GivenPopulatedTrackfile();
file.Path = copiedFile;
Subject.WriteTags(file, false, true);
var fileInfo = _diskProvider.GetFileInfo(file.Path);
file.Modified.Should().Be(fileInfo.LastWriteTimeUtc);
file.Size.Should().Be(fileInfo.Length);
}
} }
} }

View file

@ -104,10 +104,13 @@ public AudioTag GetTrackMetadata(TrackFile trackfile)
}; };
} }
private void UpdateTrackfileSize(TrackFile trackfile, string path) private void UpdateTrackfileSizeAndModified(TrackFile trackfile, string path)
{ {
// update the saved file size so that the importer doesn't get confused on the next scan // update the saved file size so that the importer doesn't get confused on the next scan
trackfile.Size = _diskProvider.GetFileSize(path); var fileInfo = _diskProvider.GetFileInfo(path);
trackfile.Size = fileInfo.Length;
trackfile.Modified = fileInfo.LastWriteTimeUtc;
if (trackfile.Id > 0) if (trackfile.Id > 0)
{ {
_mediaFileService.Update(trackfile); _mediaFileService.Update(trackfile);
@ -190,7 +193,7 @@ public void WriteTags(TrackFile trackfile, bool newDownload, bool force = false)
_logger.Debug($"Writing tags for {trackfile}"); _logger.Debug($"Writing tags for {trackfile}");
newTags.Write(path); newTags.Write(path);
UpdateTrackfileSize(trackfile, path); UpdateTrackfileSizeAndModified(trackfile, path);
_eventAggregator.PublishEvent(new TrackFileRetaggedEvent(trackfile.Artist.Value, trackfile, diff, _configService.ScrubAudioTags)); _eventAggregator.PublishEvent(new TrackFileRetaggedEvent(trackfile.Artist.Value, trackfile, diff, _configService.ScrubAudioTags));
} }
@ -276,7 +279,7 @@ public void RemoveMusicBrainzTags(TrackFile trackfile)
RemoveMusicBrainzTags(path); RemoveMusicBrainzTags(path);
UpdateTrackfileSize(trackfile, path); UpdateTrackfileSizeAndModified(trackfile, path);
} }
public List<RetagTrackFilePreview> GetRetagPreviewsByArtist(int artistId) public List<RetagTrackFilePreview> GetRetagPreviewsByArtist(int artistId)