From 4d65f0500043f11e6a2253f0200240904f57464d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 12 Aug 2013 17:22:35 -0700 Subject: [PATCH 1/4] Use SID S-1-1-0 instead of EVERYONE for non-english systems --- NzbDrone.Common/DiskProvider.cs | 13 ++++++------- NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs | 3 ++- NzbDrone.Host/AccessControl/UrlAclAdapter.cs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index e83dc8e1a..f1b780ff4 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Security.AccessControl; +using System.Security.Principal; using NLog; using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnvironmentInfo; @@ -38,7 +39,7 @@ public interface IDiskProvider void FolderSetLastWriteTimeUtc(string path, DateTime dateTime); bool IsFileLocked(FileInfo file); string GetPathRoot(string path); - void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType); + void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType); bool IsParent(string parentPath, string childPath); FileAttributes GetFileAttributes(string path); } @@ -243,7 +244,6 @@ private void TransferFolder(string source, string target, TransferAction transfe break; } } - } } @@ -403,17 +403,16 @@ public string GetPathRoot(string path) return Path.GetPathRoot(path); } - public void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType) + public void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType) { - try { - + var sid = new SecurityIdentifier(accountSid, null); var directoryInfo = new DirectoryInfo(filename); var directorySecurity = directoryInfo.GetAccessControl(); - var accessRule = new FileSystemAccessRule(account, rights, + var accessRule = new FileSystemAccessRule(sid, rights, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, controlType); @@ -423,7 +422,7 @@ public void SetPermissions(string filename, string account, FileSystemRights rig } catch (Exception e) { - Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, account, rights, controlType), e); + Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType), e); throw; } diff --git a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs index 49db460b0..6987c736a 100644 --- a/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs +++ b/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs @@ -2,6 +2,7 @@ using System.IO; using System.Reflection; using System.Security.AccessControl; +using System.Security.Principal; using NLog; namespace NzbDrone.Common.EnvironmentInfo @@ -47,7 +48,7 @@ private void SetPermissions() { try { - _diskProvider.SetPermissions(AppDataFolder, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow); + _diskProvider.SetPermissions(AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.FullControl, AccessControlType.Allow); } catch (Exception ex) { diff --git a/NzbDrone.Host/AccessControl/UrlAclAdapter.cs b/NzbDrone.Host/AccessControl/UrlAclAdapter.cs index 03a0e6c8d..6dc5ff5c4 100644 --- a/NzbDrone.Host/AccessControl/UrlAclAdapter.cs +++ b/NzbDrone.Host/AccessControl/UrlAclAdapter.cs @@ -35,7 +35,7 @@ public void RefreshRegistration() private void RegisterUrl(int portNumber) { - var arguments = String.Format("http add urlacl http://*:{0}/ user=EVERYONE", portNumber); + var arguments = String.Format("http add urlacl http://*:{0}/ sddl=D:(A;;GX;;;S-1-1-0)", portNumber); RunNetsh(arguments); } From 2a44cab54377d19c56362b6e14074d7951d71563 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 12 Aug 2013 17:53:37 -0700 Subject: [PATCH 2/4] Added references to Owin and Owin.Host.HttpListener --- NzbDrone.Host/NzbDrone.Host.csproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj index 025568f03..cfe60fd6f 100644 --- a/NzbDrone.Host/NzbDrone.Host.csproj +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -77,6 +77,14 @@ False ..\packages\Microsoft.AspNet.SignalR.Owin.1.1.2\lib\net40\Microsoft.AspNet.SignalR.Owin.dll + + False + ..\packages\Microsoft.Owin.1.1.0-beta2\lib\net40\Microsoft.Owin.dll + + + False + ..\packages\Microsoft.Owin.Host.HttpListener.1.1.0-beta2\lib\net40\Microsoft.Owin.Host.HttpListener.dll + False ..\packages\Microsoft.Owin.Hosting.1.1.0-beta2\lib\net40\Microsoft.Owin.Hosting.dll From 44772c739139306fac9cb443c52ae63bb4b64210 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 12 Aug 2013 19:01:15 -0700 Subject: [PATCH 3/4] Throw when unable to move file --- .../RenameEpisodeFileServiceFixture.cs | 4 +++ .../MediaFiles/EpisodeFileMovingService.cs | 7 ++--- .../EpisodeImport/ImportApprovedEpisodes.cs | 7 ----- .../MediaFiles/RenameEpisodeFileService.cs | 27 ++++++++++++------- .../MediaFiles/SameFilenameException.cs | 14 ++++++++++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + 6 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 NzbDrone.Core/MediaFiles/SameFilenameException.cs diff --git a/NzbDrone.Core.Test/MediaFileTests/RenameEpisodeFileServiceFixture.cs b/NzbDrone.Core.Test/MediaFileTests/RenameEpisodeFileServiceFixture.cs index 4c76ee406..dbdf35b56 100644 --- a/NzbDrone.Core.Test/MediaFileTests/RenameEpisodeFileServiceFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/RenameEpisodeFileServiceFixture.cs @@ -80,6 +80,10 @@ public void should_not_publish_event_if_no_files_are_renamed() { GivenEpisodeFiles(); + Mocker.GetMock() + .Setup(s => s.MoveEpisodeFile(It.IsAny(), It.IsAny())) + .Throws(new SameFilenameException("Same file name", "Filename")); + Subject.Execute(new RenameSeriesCommand(_series.Id)); Mocker.GetMock() diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index a8dd667be..8eba9e0d4 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -62,15 +62,12 @@ private EpisodeFile MoveFile(EpisodeFile episodeFile, string destinationFilename { if (!_diskProvider.FileExists(episodeFile.Path)) { - _logger.Error("Episode file path does not exist, {0}", episodeFile.Path); - return null; + throw new FileNotFoundException("Episode file path does not exist", episodeFile.Path); } - //Only rename if existing and new filenames don't match if (DiskProvider.PathEquals(episodeFile.Path, destinationFilename)) { - _logger.Debug("Skipping file rename, source and destination are the same: {0}", episodeFile.Path); - return null; + throw new SameFilenameException("File not moved, source and destination are the same", episodeFile.Path); } _diskProvider.CreateFolder(new FileInfo(destinationFilename).DirectoryName); diff --git a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index f0c8b05b2..0757b1495 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -68,13 +68,6 @@ public List Import(List decisions, bool newDownl if (newDownload) { episodeFile = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode); - - if (episodeFile == null) - { - _logger.Error("Failed to move [{0}], aborting processing", localEpisode); - continue; - } - _messageAggregator.PublishEvent(new EpisodeImportedEvent(episodeFile)); } diff --git a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs index 514d34402..f6737a9ef 100644 --- a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs +++ b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Messaging; @@ -35,18 +36,26 @@ private void RenameFiles(List episodeFiles, Series series) foreach (var file in episodeFiles) { - var episodeFile = file; - - _logger.Trace("Renaming episode file: {0}", episodeFile); - episodeFile = _episodeFileMover.MoveEpisodeFile(episodeFile, series); - - if (episodeFile != null) + try { + var episodeFile = file; + + _logger.Trace("Renaming episode file: {0}", episodeFile); + episodeFile = _episodeFileMover.MoveEpisodeFile(episodeFile, series); + _mediaFileService.Update(episodeFile); renamed.Add(episodeFile); - } - _logger.Trace("Renamed episode file: {0}", episodeFile); + _logger.Trace("Renamed episode file: {0}", episodeFile); + } + catch (SameFilenameException ex) + { + _logger.Trace("File not renamed, source and destination are the same: {0}", ex.Filename); + } + catch (Exception ex) + { + _logger.ErrorException("Failed to rename file: " + file.Path, ex); + } } if (renamed.Any()) diff --git a/NzbDrone.Core/MediaFiles/SameFilenameException.cs b/NzbDrone.Core/MediaFiles/SameFilenameException.cs new file mode 100644 index 000000000..d80fe4ba1 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/SameFilenameException.cs @@ -0,0 +1,14 @@ +using System; + +namespace NzbDrone.Core.MediaFiles +{ + public class SameFilenameException : Exception + { + public String Filename { get; set; } + + public SameFilenameException(string message, string filename) : base(message) + { + Filename = filename; + } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 17bfa17b7..b3302845d 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -234,6 +234,7 @@ + From 881686e99485ff2e39c2f3637d5b7f0bfce9f672 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 12 Aug 2013 19:14:03 -0700 Subject: [PATCH 4/4] Throw exception when unable to get size from newznab feed --- NzbDrone.Core/Indexers/Newznab/NewznabParser.cs | 9 ++++++++- .../Indexers/Newznab/SizeParsingException.cs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs diff --git a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs index e04fe077f..519953085 100644 --- a/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs +++ b/NzbDrone.Core/Indexers/Newznab/NewznabParser.cs @@ -2,6 +2,7 @@ using System.Drawing; using System.Linq; using System.Xml.Linq; +using NLog; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Indexers.Newznab @@ -20,7 +21,13 @@ protected override ReportInfo PostProcessor(XElement item, ReportInfo currentRes if (currentResult != null) { var attributes = item.Elements(NewznabNamespace + "attr"); - var sizeElement = attributes.Single(e => e.Attribute("name").Value == "size"); + var sizeElement = attributes.SingleOrDefault(e => e.Attribute("name").Value == "size"); + + if (sizeElement == null) + { + var message = String.Format("Unable to parse size from: {0} [{1}]", currentResult.Title, currentResult.Indexer); + throw new SizeParsingException(message); + } currentResult.Size = Convert.ToInt64(sizeElement.Attribute("value").Value); } diff --git a/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs b/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs new file mode 100644 index 000000000..33735a7ba --- /dev/null +++ b/NzbDrone.Core/Indexers/Newznab/SizeParsingException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core.Indexers.Newznab +{ + public class SizeParsingException : Exception + { + public SizeParsingException(string message) : base(message) + { + } + } +}