public virtual void AddDirectoryAccess(string path, FileAccess access, string user) { DirectorySecurity security = fileSystem.GetDirectoryAccessSecurity(path); foreach (FileSystemAccessRule rule in GetAccessControlRules(access, user)) { security.AddAccessRule(rule); } fileSystem.SetDirectoryAccessSecurity(path, security); }
public virtual void AddDirectoryAccess(string path, FileAccess access, string user) { using (var dirMutex = new System.Threading.Mutex(false, path.Replace('\\', '_'))) { dirMutex.WaitOne(); try { DirectorySecurity security = fileSystem.GetDirectoryAccessSecurity(path); foreach (FileSystemAccessRule rule in GetAccessControlRules(access, user)) { security.AddAccessRule(rule); } fileSystem.SetDirectoryAccessSecurity(path, security); } finally { dirMutex.ReleaseMutex(); } } }