Don't set ACL if already set.

pull/6/head
Taloth Saldono 9 years ago
parent 9b42dc7082
commit 3ea59cd91b

@ -293,18 +293,30 @@ namespace NzbDrone.Common.Disk
var sid = new SecurityIdentifier(accountSid, null); var sid = new SecurityIdentifier(accountSid, null);
var directoryInfo = new DirectoryInfo(filename); var directoryInfo = new DirectoryInfo(filename);
var directorySecurity = directoryInfo.GetAccessControl(); var directorySecurity = directoryInfo.GetAccessControl(AccessControlSections.Access);
var rules = directorySecurity.GetAccessRules(true, false, typeof(SecurityIdentifier));
if (rules.OfType<FileSystemAccessRule>().Any(acl => acl.AccessControlType == controlType && (acl.FileSystemRights & rights) == rights && acl.IdentityReference.Equals(sid)))
{
return;
}
var accessRule = new FileSystemAccessRule(sid, rights, var accessRule = new FileSystemAccessRule(sid, rights,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, controlType); PropagationFlags.InheritOnly, controlType);
directorySecurity.AddAccessRule(accessRule); bool modified;
directoryInfo.SetAccessControl(directorySecurity); directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out modified);
if (modified)
{
directoryInfo.SetAccessControl(directorySecurity);
}
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Warn(e, string.Format("Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType)); Logger.Warn(e, "Couldn't set permission for {0}. account:{1} rights:{2} accessControlType:{3}", filename, accountSid, rights, controlType);
throw; throw;
} }

@ -39,7 +39,7 @@ namespace NzbDrone.Common.EnvironmentInfo
{ {
try try
{ {
_diskProvider.SetPermissions(_appFolderInfo.AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.FullControl, AccessControlType.Allow); _diskProvider.SetPermissions(_appFolderInfo.AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.Modify, AccessControlType.Allow);
} }
catch (Exception ex) catch (Exception ex)
{ {

Loading…
Cancel
Save