Skip to content

Commit 7887ada

Browse files
committed
Copy UnixFilePermissions for Zip Compression
1 parent b783599 commit 7887ada

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/ZipArchive.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.IO.Compression;
8+
using System.Runtime.InteropServices;
79
using System.Text;
810

911
namespace 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

Comments
 (0)