diff --git a/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Unix.cs b/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Unix.cs new file mode 100644 index 0000000000000..6097961679a85 --- /dev/null +++ b/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Unix.cs @@ -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 + { + /// + /// The default external file attributes are used to support zip archives on multiple platforms. + /// + internal const UnixFileMode DefaultFileEntryPermissions = UnixFileMode.UserRead | UnixFileMode.UserWrite + | UnixFileMode.GroupRead + | UnixFileMode.OtherRead; + + /// + /// 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. + /// + internal const UnixFileMode DefaultDirectoryEntryPermissions = UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute + | UnixFileMode.GroupRead | UnixFileMode.GroupExecute + | UnixFileMode.OtherRead | UnixFileMode.OtherExecute; + } +} diff --git a/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Windows.cs b/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Windows.cs new file mode 100644 index 0000000000000..5f685313e7bc5 --- /dev/null +++ b/src/libraries/Common/src/System/IO/Compression/ZipArchiveEntryConstants.Windows.cs @@ -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 + { + /// + /// 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. + /// + internal const UnixFileMode DefaultFileEntryPermissions = UnixFileMode.None; + + /// + /// 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. + /// + internal const UnixFileMode DefaultDirectoryEntryPermissions = UnixFileMode.None; + } +} diff --git a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj index 3287498e587c1..b573949d69995 100644 --- a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj +++ b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj @@ -25,6 +25,7 @@ + + + + + + + diff --git a/src/libraries/System.IO.Compression/tests/ZipArchive/zip_CreateTests.Unix.cs b/src/libraries/System.IO.Compression/tests/ZipArchive/zip_CreateTests.Unix.cs new file mode 100644 index 0000000000000..121ffada3054e --- /dev/null +++ b/src/libraries/System.IO.Compression/tests/ZipArchive/zip_CreateTests.Unix.cs @@ -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); + } + } +}