From 81461cc8f4a6355050877363e7e5afc939bc50d8 Mon Sep 17 00:00:00 2001 From: plyshka Date: Mon, 15 Jan 2024 16:23:29 +0500 Subject: [PATCH] Significantly simplify setting file permissions and make it handle spaces --- ADBForwarder/Program.cs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/ADBForwarder/Program.cs b/ADBForwarder/Program.cs index 5e3841d..fe44740 100644 --- a/ADBForwarder/Program.cs +++ b/ADBForwarder/Program.cs @@ -11,6 +11,7 @@ using SharpAdbClient; using ICSharpCode.SharpZipLib.Zip; using Microsoft.Extensions.Configuration; +using UnixFileMode = System.IO.UnixFileMode; namespace ADBForwarder { @@ -76,7 +77,11 @@ private static void Main() DownloadADB(downloadUri).Wait(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - SetExecutable(absoluteAdbPath); + { + Console.WriteLine("Giving adb executable permissions"); + File.SetUnixFileMode(absoluteAdbPath, + UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); + } } Console.WriteLine("Starting ADB Server..."); @@ -161,27 +166,5 @@ private static async Task DownloadADB(string downloadUri) File.Delete("adb.zip"); } - - private static void SetExecutable(string fileName) - { - Console.WriteLine("Giving adb executable permissions"); - - var args = $"chmod u+x {fileName}"; - var escapedArgs = args.Replace("\"", "\\\""); - - using var process = new Process(); - process.StartInfo = new ProcessStartInfo - { - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, - FileName = "/bin/bash", - Arguments = $"-c \"{escapedArgs}\"" - }; - - process.Start(); - process.WaitForExit(); - } } } \ No newline at end of file