Skip to content

Commit 4508161

Browse files
committed
Set fixed file/dir permissions for zip entries when building an archive
1 parent 791693a commit 4508161

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/deployment/src/main/java/io/quarkus/deployment/pkg/jar/ParallelCommonsCompressArchiveCreator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.commons.compress.archivers.zip.DefaultBackingStoreSupplier;
2626
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
2727
import org.apache.commons.compress.archivers.zip.ScatterZipOutputStream;
28+
import org.apache.commons.compress.archivers.zip.UnixStat;
2829
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
2930
import org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest;
3031
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
@@ -44,6 +45,9 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {
4445

4546
private static final InputStreamSupplier EMPTY_SUPPLIER = () -> new ByteArrayInputStream(new byte[0]);
4647

48+
private static final int DIR_UNIX_MODE = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM;
49+
private static final int FILE_UNIX_MODE = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
50+
4751
private final Path archivePath;
4852
private final FileTime entryTimestamp;
4953
private final ZipArchiveOutputStream archive;
@@ -84,6 +88,7 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {
8488
public void addManifest(Manifest manifest) throws IOException {
8589
// we add the manifest directly to the final archive to make sure it is the first element added
8690
ZipArchiveEntry metaInfArchiveEntry = new ZipArchiveEntry("META-INF/");
91+
metaInfArchiveEntry.setUnixMode(DIR_UNIX_MODE);
8792
normalizeTimestamps(metaInfArchiveEntry);
8893
archive.putArchiveEntry(metaInfArchiveEntry);
8994
archive.closeArchiveEntry();
@@ -93,6 +98,7 @@ public void addManifest(Manifest manifest) throws IOException {
9398
byte[] manifestBytes = baos.toByteArray();
9499

95100
ZipArchiveEntry manifestEntry = new ZipArchiveEntry("META-INF/MANIFEST.MF");
101+
manifestEntry.setUnixMode(FILE_UNIX_MODE);
96102
normalizeTimestamps(manifestEntry);
97103
manifestEntry.setSize(manifestBytes.length);
98104
archive.putArchiveEntry(manifestEntry);
@@ -169,15 +175,18 @@ private void addDirectoryEntry(final ZipArchiveEntry zipArchiveEntry) throws IOE
169175
}
170176
normalizeTimestamps(zipArchiveEntry);
171177
zipArchiveEntry.setMethod(compressionMethod);
178+
zipArchiveEntry.setUnixMode(DIR_UNIX_MODE);
172179
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, EMPTY_SUPPLIER));
173180
}
174181

175182
private void addEntry(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier streamSupplier) throws IOException {
176183
normalizeTimestamps(zipArchiveEntry);
177184
zipArchiveEntry.setMethod(compressionMethod);
178185
if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
186+
zipArchiveEntry.setUnixMode(DIR_UNIX_MODE);
179187
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));
180188
} else {
189+
zipArchiveEntry.setUnixMode(FILE_UNIX_MODE);
181190
scatterZipCreator.addArchiveEntry(zipArchiveEntry, streamSupplier);
182191
}
183192
}

0 commit comments

Comments
 (0)