-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EES-2236 Fix missing zip file permissions in Unix environments
Currently, .NET doesn't automatically add Unix file permissions to our zip's file entries. This means that all of the files cannot be opened without setting the permissions manually in the OS. To fix this, we manually add the Unix file permissions ourselves by converting a permission string to an octal literal on the zip entry. I believe that in .NET 6, this should be done automatically for us due to the following change: dotnet/runtime#55531
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/GovUk.Education.ExploreEducationStatistics.Common/Extensions/ZipArchiveExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#nullable enable | ||
using System; | ||
using System.IO.Compression; | ||
|
||
namespace GovUk.Education.ExploreEducationStatistics.Common.Extensions | ||
{ | ||
public static class ZipArchiveExtensions | ||
{ | ||
/// <summary> | ||
/// Adds UNIX file permissions to the zip entry. | ||
/// </summary> | ||
/// <remarks> | ||
/// We need this due to .NET not adding these permissions for us. | ||
/// See: https://github.com/dotnet/runtime/issues/1548 | ||
/// This should be fixed in .NET 6 as part of the following PR: | ||
/// https://github.com/dotnet/runtime/pull/55531 | ||
/// </remarks> | ||
public static ZipArchiveEntry SetUnixPermissions(this ZipArchiveEntry entry, string permissions) | ||
{ | ||
entry.ExternalAttributes |= Convert.ToInt32(permissions, 8) << 16; | ||
return entry; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters