1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // Mkzip writes a zoneinfo.zip with the content of the current directory
8 // and its subdirectories, with no compression, suitable for package time.
12 // go run ../../mkzip.go ../../zoneinfo.zip
14 // We use this program instead of 'zip -0 -r ../../zoneinfo.zip *' to get
15 // a reproducible generator that does not depend on which version of the
16 // external zip tool is used or the ordering of file names in a directory
17 // or the current time.
34 fmt.Fprintf(os.Stderr, "usage: go run mkzip.go ../../zoneinfo.zip\n")
39 log.SetPrefix("mkzip: ")
44 if len(args) != 1 || !strings.HasSuffix(args[0], ".zip") {
49 zw := zip.NewWriter(&zb)
50 seen := make(map[string]bool)
51 err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
55 data, err := os.ReadFile(path)
59 if strings.HasSuffix(path, ".zip") {
60 log.Fatalf("unexpected file during walk: %s", path)
62 name := filepath.ToSlash(path)
63 w, err := zw.CreateRaw(&zip.FileHeader{
66 CompressedSize64: uint64(len(data)),
67 UncompressedSize64: uint64(len(data)),
68 CRC32: crc32.ChecksumIEEE(data),
73 if _, err := w.Write(data); err != nil {
82 if err := zw.Close(); err != nil {
86 log.Fatalf("did not find any files to add")
88 if !seen["US/Eastern"] {
89 log.Fatalf("did not find US/Eastern to add")
91 if err := os.WriteFile(args[0], zb.Bytes(), 0666); err != nil {