Skip to content

Commit

Permalink
Remove more fields from tar file headers
Browse files Browse the repository at this point in the history
Remove unnecessary fields from tar file headers to try to make tars
reproducible.
  • Loading branch information
amisevsk authored and gorkem committed May 2, 2024
1 parent 8df180f commit f5d022c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/lib/storage/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ func writeHeaderToTar(name string, fi os.FileInfo, tw *tar.Writer) error {
return fmt.Errorf("failed to generate header for %s: %w", name, err)
}
header.Name = name
header.AccessTime = time.Time{}
header.ModTime = time.Time{}
header.ChangeTime = time.Time{}
sanitizeTarHeader(header)
if err := tw.WriteHeader(header); err != nil {
return fmt.Errorf("failed to write header: %w", err)
}
Expand Down Expand Up @@ -204,3 +202,13 @@ func removeTempFile(filepath string) {
output.Errorf("Failed to clean up temporary file %s: %s", filepath, err)
}
}

func sanitizeTarHeader(header *tar.Header) {
header.AccessTime = time.Time{}
header.ModTime = time.Time{}
header.ChangeTime = time.Time{}
header.Uid = 0
header.Gid = 0
header.Uname = ""
header.Gname = ""
}

0 comments on commit f5d022c

Please sign in to comment.