public static bool HasWritePermission(string path) { FileSystemSecurity accessControl; bool flag; try { if (!SambaFile.Exists(path)) { accessControl = Directory.GetAccessControl(Path.GetDirectoryName(path)); } else { accessControl = File.GetAccessControl(path); } AuthorizationRuleCollection accessRules = accessControl.GetAccessRules(true, true, typeof(NTAccount)); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); bool flag1 = false; foreach (FileSystemAccessRule accessRule in accessRules) { if ((int)(accessRule.FileSystemRights & FileSystemRights.Write) == 0) { continue; } if (accessRule.IdentityReference.Value.StartsWith("S-1-")) { if (!windowsPrincipal.IsInRole(new SecurityIdentifier(accessRule.IdentityReference.Value))) { continue; } } else if (!windowsPrincipal.IsInRole(accessRule.IdentityReference.Value)) { continue; } if (accessRule.AccessControlType != AccessControlType.Deny) { if (accessRule.AccessControlType != AccessControlType.Allow) { continue; } flag1 = true; } else { flag = false; return(flag); } } flag = flag1; } catch { flag = false; } return(flag); }
public static void Copy(string sourceFile, string destFile, bool overwrite) { File.Copy(sourceFile, destFile, overwrite); SambaFile.GrantAccess(destFile); }
public static void Copy(string sourceFileName, string destFileName) { File.Copy(sourceFileName, destFileName); SambaFile.GrantAccess(destFileName); }
public static void WriteAllText(string path, string contents) { File.WriteAllText(path, contents); SambaFile.GrantAccess(path); }
public static void WriteAllBytes(string path, byte[] bytes) { File.WriteAllBytes(path, bytes); SambaFile.GrantAccess(path); }
public static void Touch(string path) { SambaFile.GrantAccess(path); }