Skip to content

Commit

Permalink
Significantly simplify setting file permissions and make it handle sp…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
Meister1593 committed Jan 15, 2024
1 parent e68ca37 commit 81461cc
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions ADBForwarder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SharpAdbClient;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.Extensions.Configuration;
using UnixFileMode = System.IO.UnixFileMode;

namespace ADBForwarder
{
Expand Down Expand Up @@ -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...");
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 81461cc

Please sign in to comment.