Catching InvalidOperationExceptions when Inheriting folder permissions

Fixed: Issue sorting files when series is on a share running on UFS
This commit is contained in:
Mark McDowall 2013-11-28 00:03:58 -08:00
parent f349f1177e
commit f3fbbf66e0
3 changed files with 99 additions and 8 deletions

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.MediaFiles.EpisodeFileMovingServiceTests
{
[TestFixture]
public class MoveEpisodeFileFixture : CoreTest<EpisodeFileMovingService>
{
private Series _series;
private EpisodeFile _episodeFile;
private LocalEpisode _localEpisode;
[SetUp]
public void Setup()
{
_episodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.Path = @"C:\Test\File.avi")
.Build();
_localEpisode = Builder<LocalEpisode>.CreateNew()
.With(l => l.Series = Builder<Series>.CreateNew().Build())
.With(l => l.Episodes = Builder<Episode>.CreateListOfSize(1).Build().ToList())
.Build();
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.BuildFilename(It.IsAny<List<Episode>>(), It.IsAny<Series>(), It.IsAny<EpisodeFile>()))
.Returns("File Name");
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.BuildFilePath(It.IsAny<Series>(), It.IsAny<Int32>(), It.IsAny<String>(), It.IsAny<String>()))
.Returns(@"C:\Test\File Name.avi");
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.FileExists(It.IsAny<String>()))
.Returns(true);
}
[Test]
public void should_catch_UnauthorizedAccessException_during_folder_inheritance()
{
WindowsOnly();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.InheritFolderPermissions(It.IsAny<String>()))
.Throws<UnauthorizedAccessException>();
Subject.MoveEpisodeFile(_episodeFile, _localEpisode);
}
[Test]
public void should_catch_InvalidOperationException_during_folder_inheritance()
{
WindowsOnly();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.InheritFolderPermissions(It.IsAny<String>()))
.Throws<InvalidOperationException>();
Subject.MoveEpisodeFile(_episodeFile, _localEpisode);
}
[Test]
public void should_not_catch_generic_Exception_during_folder_inheritance()
{
WindowsOnly();
Mocker.GetMock<IDiskProvider>()
.Setup(s => s.InheritFolderPermissions(It.IsAny<String>()))
.Throws<Exception>();
Assert.Throws<Exception>(() => Subject.MoveEpisodeFile(_episodeFile, _localEpisode));
}
}
}

View File

@ -143,6 +143,7 @@
<Compile Include="JobTests\TestJobs.cs" />
<Compile Include="MediaCoverTests\CoverExistsSpecificationFixture.cs" />
<Compile Include="MediaCoverTests\MediaCoverServiceFixture.cs" />
<Compile Include="MediaFiles\EpisodeFileMovingServiceTests\MoveEpisodeFileFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\FreeSpaceSpecificationFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\ImportDecisionMakerFixture.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\NotInUseSpecificationFixture.cs" />

View File

@ -18,23 +18,20 @@ namespace NzbDrone.Core.MediaFiles
string MoveEpisodeFile(EpisodeFile episodeFile, LocalEpisode localEpisode);
}
public class MoveEpisodeFiles : IMoveEpisodeFiles
public class EpisodeFileMovingService : IMoveEpisodeFiles
{
private readonly IEpisodeService _episodeService;
private readonly IBuildFileNames _buildFileNames;
private readonly IEventAggregator _eventAggregator;
private readonly IDiskProvider _diskProvider;
private readonly Logger _logger;
public MoveEpisodeFiles(IEpisodeService episodeService,
public EpisodeFileMovingService(IEpisodeService episodeService,
IBuildFileNames buildFileNames,
IEventAggregator eventAggregator,
IDiskProvider diskProvider,
Logger logger)
{
_episodeService = episodeService;
_buildFileNames = buildFileNames;
_eventAggregator = eventAggregator;
_diskProvider = diskProvider;
_logger = logger;
}
@ -106,10 +103,18 @@ namespace NzbDrone.Core.MediaFiles
{
_diskProvider.InheritFolderPermissions(destinationFilename);
}
catch (UnauthorizedAccessException ex)
catch (Exception ex)
{
_logger.Debug("Unable to apply folder permissions to: ", destinationFilename);
_logger.TraceException(ex.Message, ex);
if (ex is UnauthorizedAccessException || ex is InvalidOperationException)
{
_logger.Debug("Unable to apply folder permissions to: ", destinationFilename);
_logger.TraceException(ex.Message, ex);
}
else
{
throw;
}
}
}
}