From 67661c689362a9073a9799c52918c87eef362b60 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 25 Jul 2013 22:55:19 -0700 Subject: [PATCH] more linux fixes --- .../EnviromentProviderTest.cs | 5 ++-- NzbDrone.Common/DiskProvider.cs | 30 +++++++++++++------ NzbDrone.Test.Common/StringExtensions.cs | 3 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/NzbDrone.Common.Test/EnviromentProviderTest.cs b/NzbDrone.Common.Test/EnviromentProviderTest.cs index c927030d2..d8ba3c4f9 100644 --- a/NzbDrone.Common.Test/EnviromentProviderTest.cs +++ b/NzbDrone.Common.Test/EnviromentProviderTest.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Diagnostics; +using System.IO; using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.EnvironmentInfo; @@ -30,7 +31,7 @@ namespace NzbDrone.Common.Test [Test] public void IsProduction_should_return_false_when_run_within_nunit() { - RuntimeInfo.IsProduction.Should().BeFalse(); + RuntimeInfo.IsProduction.Should().BeFalse("Process name is " + Process.GetCurrentProcess().ProcessName); } } } diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index a7aac8b8a..1e9e3f69d 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -101,7 +101,7 @@ namespace NzbDrone.Common Ensure.That(() => path).IsValidPath(); return Directory.Exists(path); } - + public virtual bool FolderExists(string path, bool caseSensitive) { if (caseSensitive) @@ -394,16 +394,28 @@ namespace NzbDrone.Common public void SetPermissions(string filename, string account, FileSystemRights rights, AccessControlType controlType) { - var directoryInfo = new DirectoryInfo(filename); - var directorySecurity = directoryInfo.GetAccessControl(); - var accessRule = new FileSystemAccessRule(account, rights, - InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, - PropagationFlags.None, controlType); + try + { + + var directoryInfo = new DirectoryInfo(filename); + var directorySecurity = directoryInfo.GetAccessControl(); + + var accessRule = new FileSystemAccessRule(account, rights, + InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, + PropagationFlags.None, controlType); + + + directorySecurity.AddAccessRule(accessRule); + directoryInfo.SetAccessControl(directorySecurity); + } + catch (Exception e) + { + Logger.WarnException(string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, account, rights, controlType), e); + throw; + } - directorySecurity.AddAccessRule(accessRule); - directoryInfo.SetAccessControl(directorySecurity); } public bool IsParent(string parent, string subfolder) @@ -420,7 +432,7 @@ namespace NzbDrone.Common { return true; } - + diSubfolder = diSubfolder.Parent; } diff --git a/NzbDrone.Test.Common/StringExtensions.cs b/NzbDrone.Test.Common/StringExtensions.cs index 19da86cc1..7ec3f4698 100644 --- a/NzbDrone.Test.Common/StringExtensions.cs +++ b/NzbDrone.Test.Common/StringExtensions.cs @@ -11,7 +11,8 @@ namespace NzbDrone.Test.Common { if (path.Length > 2 && path[1] == ':') { - path = path.Replace(':', Path.DirectorySeparatorChar); + path = path.Replace(":", ""); + path = Path.DirectorySeparatorChar + path; } path = path.Replace("\\", Path.DirectorySeparatorChar.ToString()); }