25
25
import org .apache .commons .compress .archivers .zip .DefaultBackingStoreSupplier ;
26
26
import org .apache .commons .compress .archivers .zip .ParallelScatterZipCreator ;
27
27
import org .apache .commons .compress .archivers .zip .ScatterZipOutputStream ;
28
+ import org .apache .commons .compress .archivers .zip .UnixStat ;
28
29
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
29
30
import org .apache .commons .compress .archivers .zip .ZipArchiveEntryRequest ;
30
31
import org .apache .commons .compress .archivers .zip .ZipArchiveOutputStream ;
@@ -44,6 +45,9 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {
44
45
45
46
private static final InputStreamSupplier EMPTY_SUPPLIER = () -> new ByteArrayInputStream (new byte [0 ]);
46
47
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
+
47
51
private final Path archivePath ;
48
52
private final FileTime entryTimestamp ;
49
53
private final ZipArchiveOutputStream archive ;
@@ -84,7 +88,7 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {
84
88
public void addManifest (Manifest manifest ) throws IOException {
85
89
// we add the manifest directly to the final archive to make sure it is the first element added
86
90
ZipArchiveEntry metaInfArchiveEntry = new ZipArchiveEntry ("META-INF/" );
87
- normalizeTimestamps (metaInfArchiveEntry );
91
+ normalizeTimestampsAndPermissions (metaInfArchiveEntry );
88
92
archive .putArchiveEntry (metaInfArchiveEntry );
89
93
archive .closeArchiveEntry ();
90
94
@@ -93,7 +97,7 @@ public void addManifest(Manifest manifest) throws IOException {
93
97
byte [] manifestBytes = baos .toByteArray ();
94
98
95
99
ZipArchiveEntry manifestEntry = new ZipArchiveEntry ("META-INF/MANIFEST.MF" );
96
- normalizeTimestamps (manifestEntry );
100
+ normalizeTimestampsAndPermissions (manifestEntry );
97
101
manifestEntry .setSize (manifestBytes .length );
98
102
archive .putArchiveEntry (manifestEntry );
99
103
archive .write (manifestBytes );
@@ -167,13 +171,13 @@ private void addDirectoryEntry(final ZipArchiveEntry zipArchiveEntry) throws IOE
167
171
if (!zipArchiveEntry .isDirectory () || zipArchiveEntry .isUnixSymlink ()) {
168
172
return ;
169
173
}
170
- normalizeTimestamps (zipArchiveEntry );
174
+ normalizeTimestampsAndPermissions (zipArchiveEntry );
171
175
zipArchiveEntry .setMethod (compressionMethod );
172
176
directories .addArchiveEntry (ZipArchiveEntryRequest .createZipArchiveEntryRequest (zipArchiveEntry , EMPTY_SUPPLIER ));
173
177
}
174
178
175
179
private void addEntry (final ZipArchiveEntry zipArchiveEntry , final InputStreamSupplier streamSupplier ) throws IOException {
176
- normalizeTimestamps (zipArchiveEntry );
180
+ normalizeTimestampsAndPermissions (zipArchiveEntry );
177
181
zipArchiveEntry .setMethod (compressionMethod );
178
182
if (zipArchiveEntry .isDirectory () && !zipArchiveEntry .isUnixSymlink ()) {
179
183
directories .addArchiveEntry (ZipArchiveEntryRequest .createZipArchiveEntryRequest (zipArchiveEntry , streamSupplier ));
@@ -208,7 +212,7 @@ private static InputStreamSupplier toInputStreamSupplier(Path path) {
208
212
};
209
213
}
210
214
211
- private void normalizeTimestamps (ZipArchiveEntry archiveEntry ) {
215
+ private void normalizeTimestampsAndPermissions (ZipArchiveEntry archiveEntry ) {
212
216
if (entryTimestamp == null ) {
213
217
return ;
214
218
}
@@ -217,6 +221,12 @@ private void normalizeTimestamps(ZipArchiveEntry archiveEntry) {
217
221
archiveEntry .setCreationTime (entryTimestamp );
218
222
archiveEntry .setLastModifiedTime (entryTimestamp );
219
223
archiveEntry .setLastAccessTime (entryTimestamp );
224
+
225
+ if (archiveEntry .isDirectory ()) {
226
+ archiveEntry .setUnixMode (DIR_UNIX_MODE );
227
+ } else {
228
+ archiveEntry .setUnixMode (FILE_UNIX_MODE );
229
+ }
220
230
}
221
231
222
232
@ Override
0 commit comments