Fixed: Update modified times as well as sizes

pull/6/head
ta264 6 years ago
parent dc44bbd210
commit 343b27b886

@ -12,6 +12,7 @@ using System.Linq;
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 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
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 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
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 @@ namespace NzbDrone.Core.Test.MediaFiles.AudioTagServiceFixture
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);
}
} }
} }

@ -104,10 +104,13 @@ namespace NzbDrone.Core.MediaFiles
}; };
} }
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 @@ namespace NzbDrone.Core.MediaFiles
_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 @@ namespace NzbDrone.Core.MediaFiles
RemoveMusicBrainzTags(path); RemoveMusicBrainzTags(path);
UpdateTrackfileSize(trackfile, path); UpdateTrackfileSizeAndModified(trackfile, path);
} }
public List<RetagTrackFilePreview> GetRetagPreviewsByArtist(int artistId) public List<RetagTrackFilePreview> GetRetagPreviewsByArtist(int artistId)

Loading…
Cancel
Save