Skip to content

Commit

Permalink
Set file permissions on Linux and macOS after extracting.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNexusAvenger committed Sep 18, 2021
1 parent 3615baf commit 41cebb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Uchu.Tool/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Uchu.Tool/Uchu.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mono.Posix.NETStandard" Version="5.20.1-preview" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
</ItemGroup>
Expand Down

0 comments on commit 41cebb3

Please sign in to comment.