Repository navigation
Expand file tree
/
Copy pathChmod.cs
More file actions
39 lines (34 loc) · 1.33 KB
/
Copy pathChmod.cs
File metadata and controls
39 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Text.RegularExpressions;
using System.Diagnostics;
static class Chmod {
private static readonly Process _proc = new Process() {
StartInfo = new() {
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "chmod",
//WorkingDirectory = "path",
//Arguments = $"args",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
}
};
public static void SetPerimissions(
string path, string permission = "700", bool recursive = false)
{
Console.WriteLine($"[DBG ] Chmod-SetPermission: {permission}");
if (!Regex.Match(permission, "^[0-7]{1,3}$").Success) {
Console.WriteLine("[DBG ] Chmod-SetPermission: input is invalid! [0-7]{1,3}");
}
_proc.StartInfo.Arguments = $"{(recursive ? "-R" : "")} {permission}" +
$" {ExtensionMethods.EscapeForCommand(path)}";
_proc.Start();
_proc.WaitForExit();
var output = _proc.StandardOutput.ReadToEnd();
var error = _proc.StandardError.ReadToEnd();
if (_proc.ExitCode != 0) {
throw new Exception($"Error while changing filepermission " +
$"(exitcode: {_proc.ExitCode}).",
new Exception(error));
}
}
}