-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Make the archives created on Unix have the read permissions by default #70735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adamsitnik
merged 6 commits into
dotnet:main
from
derwasp:derwasp/zip-archive-entry-unix-permissions
Jul 1, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eda01fe
Set the ExternalAttributes to the values from the file.
derwasp 632b858
Add an assert of te SetExternalAttributes
derwasp b3976f1
Move the constants into separate files
derwasp 139850e
Add a test verifying the new behavior
derwasp 424127d
Use the new default permissions on the ZipArchiveEntry
derwasp 5c8920b
Move the zip constants to the common directory
derwasp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Unix.cs
This file contains hidden or 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,23 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| internal static partial class ZipArchiveEntryConstants | ||
| { | ||
| /// <summary> | ||
| /// The default external file attributes are used to support zip archives on multiple platforms. | ||
| /// </summary> | ||
| internal const UnixFileMode DefaultFileEntryPermissions = UnixFileMode.UserRead | UnixFileMode.UserWrite | ||
| | UnixFileMode.GroupRead | ||
| | UnixFileMode.OtherRead; | ||
|
|
||
| /// <summary> | ||
| /// The default external directory attributes are used to support zip archives on multiple platforms. | ||
| /// Directories on Unix require the execute permissions to get into them. | ||
| /// </summary> | ||
| internal const UnixFileMode DefaultDirectoryEntryPermissions = UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute | ||
| | UnixFileMode.GroupRead | UnixFileMode.GroupExecute | ||
| | UnixFileMode.OtherRead | UnixFileMode.OtherExecute; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Windows.cs
This file contains hidden or 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,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| internal static partial class ZipArchiveEntryConstants | ||
| { | ||
| /// <summary> | ||
| /// The default external file attributes are used to support zip archives on multiple platforms. | ||
| /// Since Windows doesn't use file permissions, there's no default value needed. | ||
| /// </summary> | ||
| internal const UnixFileMode DefaultFileEntryPermissions = UnixFileMode.None; | ||
|
|
||
| /// <summary> | ||
| /// The default external directory attributes are used to support zip archives on multiple platforms. | ||
| /// Since Windows doesn't use file permissions, there's no default value needed. | ||
| /// </summary> | ||
| internal const UnixFileMode DefaultDirectoryEntryPermissions = UnixFileMode.None; | ||
| } | ||
| } |
This file contains hidden or 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
13 changes: 12 additions & 1 deletion
13
...Compression.ZipFile/src/System/IO/Compression/ZipFileExtensions.ZipArchive.Create.Unix.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -1,16 +1,27 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| using static System.IO.Compression.ZipArchiveEntryConstants; | ||
|
|
||
| namespace System.IO.Compression | ||
| { | ||
| public static partial class ZipFileExtensions | ||
| { | ||
| static partial void SetExternalAttributes(FileStream fs, ZipArchiveEntry entry) | ||
| { | ||
| Debug.Assert(!OperatingSystem.IsWindows()); | ||
|
|
||
| // SetExternalAttributes is only used to overwrite the default values when reading on the unix systems | ||
| // This assert ensures that nothing else sets values different to the default before | ||
| // overwriting it with the data read from the files | ||
| Debug.Assert(entry.ExternalAttributes == ((uint)DefaultFileEntryPermissions << 16)); | ||
|
|
||
| Interop.Sys.FileStatus status; | ||
| Interop.CheckIo(Interop.Sys.FStat(fs.SafeFileHandle, out status), fs.Name); | ||
|
|
||
| entry.ExternalAttributes |= status.Mode << 16; | ||
| entry.ExternalAttributes = status.Mode << 16; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
src/libraries/System.IO.Compression/tests/ZipArchive/zip_CreateTests.Unix.cs
This file contains hidden or 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,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace System.IO.Compression.Tests | ||
| { | ||
| public partial class zip_CreateTests : ZipFileTestBase | ||
| { | ||
| [Theory] | ||
| [InlineData("folder/", 493 << 16)] | ||
| [InlineData("folder/file", 420 << 16)] | ||
| [InlineData("folder\\file", 420 << 16)] | ||
| public static void Verify_Default_Permissions_Are_Applied_For_Entries(string path, int permissions) | ||
| { | ||
| using var archive = new ZipArchive(new MemoryStream(), ZipArchiveMode.Create, false); | ||
| var newEntry = archive.CreateEntry(path); | ||
| Assert.Equal(newEntry.ExternalAttributes, permissions); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.