From 0932c4a1c640631958bf040c20b6cb6afedb80e7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 24 Jun 2025 12:04:17 +0100 Subject: [PATCH] Apply permissions consistently when creating uber jars and wars Closes gh-46193 --- .../gradle/tasks/bundling/BootZipCopyAction.java | 12 ++++++++---- .../AbstractBootArchiveIntegrationTests.java | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java index 57b7856f56d..58f816a7e4a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java @@ -256,7 +256,7 @@ class BootZipCopyAction implements CopyAction { private void processDirectory(FileCopyDetails details) throws IOException { String name = details.getRelativePath().getPathString(); ZipArchiveEntry entry = new ZipArchiveEntry(name + '/'); - prepareEntry(entry, name, getTime(details), getFileMode(details)); + prepareEntry(entry, name, getTime(details), getDirMode(details)); this.out.putArchiveEntry(entry); this.out.closeArchiveEntry(); this.writtenDirectories.add(name); @@ -476,17 +476,21 @@ class BootZipCopyAction implements CopyAction { private int getDirMode() { return (BootZipCopyAction.this.dirMode != null) ? BootZipCopyAction.this.dirMode - : UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM; + : UnixStat.DEFAULT_DIR_PERM; } private int getFileMode() { return (BootZipCopyAction.this.fileMode != null) ? BootZipCopyAction.this.fileMode - : UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM; + : UnixStat.DEFAULT_FILE_PERM; + } + + private int getDirMode(FileCopyDetails details) { + return (BootZipCopyAction.this.fileMode != null) ? BootZipCopyAction.this.dirMode : getPermissions(details); } private int getFileMode(FileCopyDetails details) { return (BootZipCopyAction.this.fileMode != null) ? BootZipCopyAction.this.fileMode - : UnixStat.FILE_FLAG | getPermissions(details); + : getPermissions(details); } private int getPermissions(FileCopyDetails details) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java index 1bd2148947e..db6d3824598 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java @@ -598,10 +598,10 @@ abstract class AbstractBootArchiveIntegrationTests { continue; } if (entry.isDirectory()) { - assertEntryMode(entry, UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM); + assertEntryMode(entry, UnixStat.DEFAULT_DIR_PERM); } else { - assertEntryMode(entry, UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM); + assertEntryMode(entry, UnixStat.DEFAULT_FILE_PERM); } } }