33
44using System ;
55using System . Collections . Generic ;
6+ using System . IO ;
67using System . IO . Compression ;
8+ using System . Runtime . InteropServices ;
79using System . Text ;
810
911namespace Microsoft . PowerShell . Archive
@@ -68,7 +70,9 @@ void IArchive.AddFileSystemEntry(ArchiveAddition addition)
6870 entryName += ZipArchiveDirectoryPathTerminator ;
6971 }
7072
71- _zipArchive . CreateEntry ( entryName ) ;
73+ System . IO . Compression . ZipArchiveEntry entry = _zipArchive . CreateEntry ( entryName ) ;
74+
75+ CopyUnixFilePermissions ( entry , addition . FileSystemInfo ) ;
7276 }
7377 }
7478 else
@@ -80,7 +84,9 @@ void IArchive.AddFileSystemEntry(ArchiveAddition addition)
8084 }
8185
8286 // TODO: Add exception handling
83- _zipArchive . CreateEntryFromFile ( sourceFileName : addition . FileSystemInfo . FullName , entryName : entryName , compressionLevel : _compressionLevel ) ;
87+ System . IO . Compression . ZipArchiveEntry entry = _zipArchive . CreateEntryFromFile ( sourceFileName : addition . FileSystemInfo . FullName , entryName : entryName , compressionLevel : _compressionLevel ) ;
88+
89+ CopyUnixFilePermissions ( entry , addition . FileSystemInfo ) ;
8490 }
8591 }
8692
@@ -105,6 +111,14 @@ private static System.IO.Compression.ZipArchiveMode ConvertToZipArchiveMode(Arch
105111 }
106112 }
107113
114+ private static void CopyUnixFilePermissions ( ZipArchiveEntry archiveEntry , FileSystemInfo fileSystemInfo )
115+ {
116+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
117+ {
118+ archiveEntry . ExternalAttributes |= ( int ) fileSystemInfo . UnixFileMode ;
119+ }
120+ }
121+
108122 protected virtual void Dispose ( bool disposing )
109123 {
110124 if ( ! _disposedValue )
0 commit comments