From 41cebb32217cc3066f2c1edc3a7f46296a5f09fa Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Fri, 17 Sep 2021 20:26:27 -0400 Subject: [PATCH] Set file permissions on Linux and macOS after extracting. --- Uchu.Tool/Action/Update.cs | 22 +++++++++++++++++++--- Uchu.Tool/Uchu.Tool.csproj | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Uchu.Tool/Action/Update.cs b/Uchu.Tool/Action/Update.cs index 44f2503..742462e 100644 --- a/Uchu.Tool/Action/Update.cs +++ b/Uchu.Tool/Action/Update.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Mono.Unix; using Newtonsoft.Json; namespace Uchu.Tool.Action @@ -221,9 +222,7 @@ public async Task CheckLatestRelease(bool autoConfirm = false) } var tcs = new TaskCompletionSource(); - - WebClient client = new WebClient(); - + var client = new WebClient(); client.DownloadProgressChanged += (_, e) => { // Set cursor to start of line. @@ -255,6 +254,23 @@ public async Task CheckLatestRelease(bool autoConfirm = false) Directory.Delete(this.ExtractLocation, true); } ZipFile.ExtractToDirectory(this.DownloadLocation, this.ExtractLocation); + + // Set the file permissions. ZipFile.ExtractToDirectory does not do this by default. + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using var archive = ZipFile.Open(this.DownloadLocation, ZipArchiveMode.Read); + foreach (var entry in archive.Entries) + { + // Get the file path and return if it is a directory. + var fileName = Path.Combine(ExtractLocation, entry.FullName); + if (!File.Exists(fileName)) continue; + + // Convert the ZIP file permissions to Unix file permissions and set them in the file. + var filePermissions = (entry.ExternalAttributes >> 16) & 0x1FF; + var fileInfo = new UnixFileInfo(fileName); + fileInfo.FileAccessPermissions = (FileAccessPermissions) filePermissions; + } + } // Determine the directory to copy from. var extractedDirectory = this.ExtractLocation; diff --git a/Uchu.Tool/Uchu.Tool.csproj b/Uchu.Tool/Uchu.Tool.csproj index 1449106..b8a8bb7 100644 --- a/Uchu.Tool/Uchu.Tool.csproj +++ b/Uchu.Tool/Uchu.Tool.csproj @@ -9,6 +9,7 @@ +