Skip to content

Commit 7a70229

Browse files
authored
Merge pull request #49808 from Eng-Fouad/fixed-zip-entry-perms
Set fixed file/dir permissions for zip entries when building an archive
2 parents e5d4f7c + 9cc2b0f commit 7a70229

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 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,7 +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/");
87-
normalizeTimestamps(metaInfArchiveEntry);
91+
normalizeTimestampsAndPermissions(metaInfArchiveEntry);
8892
archive.putArchiveEntry(metaInfArchiveEntry);
8993
archive.closeArchiveEntry();
9094

@@ -93,7 +97,7 @@ public void addManifest(Manifest manifest) throws IOException {
9397
byte[] manifestBytes = baos.toByteArray();
9498

9599
ZipArchiveEntry manifestEntry = new ZipArchiveEntry("META-INF/MANIFEST.MF");
96-
normalizeTimestamps(manifestEntry);
100+
normalizeTimestampsAndPermissions(manifestEntry);
97101
manifestEntry.setSize(manifestBytes.length);
98102
archive.putArchiveEntry(manifestEntry);
99103
archive.write(manifestBytes);
@@ -167,13 +171,13 @@ private void addDirectoryEntry(final ZipArchiveEntry zipArchiveEntry) throws IOE
167171
if (!zipArchiveEntry.isDirectory() || zipArchiveEntry.isUnixSymlink()) {
168172
return;
169173
}
170-
normalizeTimestamps(zipArchiveEntry);
174+
normalizeTimestampsAndPermissions(zipArchiveEntry);
171175
zipArchiveEntry.setMethod(compressionMethod);
172176
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, EMPTY_SUPPLIER));
173177
}
174178

175179
private void addEntry(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier streamSupplier) throws IOException {
176-
normalizeTimestamps(zipArchiveEntry);
180+
normalizeTimestampsAndPermissions(zipArchiveEntry);
177181
zipArchiveEntry.setMethod(compressionMethod);
178182
if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
179183
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));
@@ -208,7 +212,7 @@ private static InputStreamSupplier toInputStreamSupplier(Path path) {
208212
};
209213
}
210214

211-
private void normalizeTimestamps(ZipArchiveEntry archiveEntry) {
215+
private void normalizeTimestampsAndPermissions(ZipArchiveEntry archiveEntry) {
212216
if (entryTimestamp == null) {
213217
return;
214218
}
@@ -217,6 +221,12 @@ private void normalizeTimestamps(ZipArchiveEntry archiveEntry) {
217221
archiveEntry.setCreationTime(entryTimestamp);
218222
archiveEntry.setLastModifiedTime(entryTimestamp);
219223
archiveEntry.setLastAccessTime(entryTimestamp);
224+
225+
if (archiveEntry.isDirectory()) {
226+
archiveEntry.setUnixMode(DIR_UNIX_MODE);
227+
} else {
228+
archiveEntry.setUnixMode(FILE_UNIX_MODE);
229+
}
220230
}
221231

222232
@Override

0 commit comments

Comments
 (0)