Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.compress.archivers.zip.DefaultBackingStoreSupplier;
import org.apache.commons.compress.archivers.zip.ParallelScatterZipCreator;
import org.apache.commons.compress.archivers.zip.ScatterZipOutputStream;
import org.apache.commons.compress.archivers.zip.UnixStat;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntryRequest;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
Expand All @@ -44,6 +45,9 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {

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

private static final int DIR_UNIX_MODE = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM;
private static final int FILE_UNIX_MODE = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;

private final Path archivePath;
private final FileTime entryTimestamp;
private final ZipArchiveOutputStream archive;
Expand Down Expand Up @@ -84,7 +88,7 @@ public class ParallelCommonsCompressArchiveCreator implements ArchiveCreator {
public void addManifest(Manifest manifest) throws IOException {
// we add the manifest directly to the final archive to make sure it is the first element added
ZipArchiveEntry metaInfArchiveEntry = new ZipArchiveEntry("META-INF/");
normalizeTimestamps(metaInfArchiveEntry);
normalizeTimestampsAndPermissions(metaInfArchiveEntry);
archive.putArchiveEntry(metaInfArchiveEntry);
archive.closeArchiveEntry();

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

ZipArchiveEntry manifestEntry = new ZipArchiveEntry("META-INF/MANIFEST.MF");
normalizeTimestamps(manifestEntry);
normalizeTimestampsAndPermissions(manifestEntry);
manifestEntry.setSize(manifestBytes.length);
archive.putArchiveEntry(manifestEntry);
archive.write(manifestBytes);
Expand Down Expand Up @@ -167,13 +171,13 @@ private void addDirectoryEntry(final ZipArchiveEntry zipArchiveEntry) throws IOE
if (!zipArchiveEntry.isDirectory() || zipArchiveEntry.isUnixSymlink()) {
return;
}
normalizeTimestamps(zipArchiveEntry);
normalizeTimestampsAndPermissions(zipArchiveEntry);
zipArchiveEntry.setMethod(compressionMethod);
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, EMPTY_SUPPLIER));
}

private void addEntry(final ZipArchiveEntry zipArchiveEntry, final InputStreamSupplier streamSupplier) throws IOException {
normalizeTimestamps(zipArchiveEntry);
normalizeTimestampsAndPermissions(zipArchiveEntry);
zipArchiveEntry.setMethod(compressionMethod);
if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
directories.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));
Expand Down Expand Up @@ -208,7 +212,7 @@ private static InputStreamSupplier toInputStreamSupplier(Path path) {
};
}

private void normalizeTimestamps(ZipArchiveEntry archiveEntry) {
private void normalizeTimestampsAndPermissions(ZipArchiveEntry archiveEntry) {
if (entryTimestamp == null) {
return;
}
Expand All @@ -217,6 +221,12 @@ private void normalizeTimestamps(ZipArchiveEntry archiveEntry) {
archiveEntry.setCreationTime(entryTimestamp);
archiveEntry.setLastModifiedTime(entryTimestamp);
archiveEntry.setLastAccessTime(entryTimestamp);

if (archiveEntry.isDirectory()) {
archiveEntry.setUnixMode(DIR_UNIX_MODE);
} else {
archiveEntry.setUnixMode(FILE_UNIX_MODE);
}
}

@Override
Expand Down
Loading