Skip to content

Commit

Permalink
Fix timezone bug in zips
Browse files Browse the repository at this point in the history
Try to fix #152
  • Loading branch information
ia3andy committed Sep 17, 2019
1 parent 4613e94 commit c253f6b
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipExtraField;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -25,6 +28,7 @@ public class CommonsZipProjectWriter implements ProjectWriter {
private final Set<String> createdDirs = new HashSet<>();
private final Map<String, ZipArchiveEntry> archiveEntriesByPath = new LinkedHashMap<>();
private final Map<String, byte[]> contentByPath = new LinkedHashMap<>();
private final Date creation = new Date();

private CommonsZipProjectWriter(final ArchiveOutputStream aos, final String basePath) {
this.aos = aos;
Expand Down Expand Up @@ -59,12 +63,15 @@ private void mkdirs(Path dirPath) throws IOException {
if (!createdDirs.contains(dirPathText)) {
ZipArchiveEntry ze = new ZipArchiveEntry(dirPathText + "/");
ze.setUnixMode(040755);
ze.setExtraFields(new ZipExtraField[]{getTimestamp()});
aos.putArchiveEntry(ze);
aos.closeArchiveEntry();
createdDirs.add(dirPathText);
}
}



public void write(String path, byte[] contentBytes, boolean allowExec) {
Path filePath = Paths.get(this.basePath, "/", path);
ZipArchiveEntry ze = new ZipArchiveEntry(filePath.toString());
Expand All @@ -73,6 +80,7 @@ public void write(String path, byte[] contentBytes, boolean allowExec) {
} else {
ze.setUnixMode(0100644);
}
ze.setExtraFields(new ZipExtraField[]{getTimestamp()});
archiveEntriesByPath.put(filePath.toString(), ze);
contentByPath.put(filePath.toString(), contentBytes);
}
Expand All @@ -99,4 +107,12 @@ public void close() throws IOException {
aos.close();
}

private X5455_ExtendedTimestamp getTimestamp() {
X5455_ExtendedTimestamp timestamp = new X5455_ExtendedTimestamp();
timestamp.setCreateJavaTime(creation);
timestamp.setModifyJavaTime(creation);
timestamp.setAccessJavaTime(creation);
return timestamp;
}

}

0 comments on commit c253f6b

Please sign in to comment.