Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve zip file reproducibility #1602

Merged
merged 2 commits into from
Jul 30, 2024
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 @@ -4,6 +4,7 @@ package universal

import java.net.URI
import java.nio.file.{FileSystem, FileSystems, Files, StandardCopyOption}
import java.nio.file.attribute.FileTime
import java.util.zip.Deflater

import org.apache.commons.compress.archivers.zip._
Expand Down Expand Up @@ -122,9 +123,14 @@ object ZipHelper {
IO createDirectory outputDir
withZipOutput(outputFile) { output =>
for (FileMapping(file, name, mode) <- sources) {
val entry = new ZipArchiveEntry(file, normalizePath(name))
val entryName = {
val n = normalizePath(name)
if (file.isDirectory && !n.endsWith("/")) n + "/" else n
}
val entry = new ZipArchiveEntry(entryName)
sys.env.get("SOURCE_DATE_EPOCH") foreach { epoch =>
entry.setTime(epoch.toLong * 1000)
val millis = epoch.toLong * 1000
entry.setLastModifiedTime(FileTime.fromMillis(millis))
}
// Now check to see if we have permissions for this sucker.
mode foreach (entry.setUnixMode)
Expand Down
Loading