]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: remove fips140 dependency on global Fetcher_
authorIan Alexander <jitsu@google.com>
Tue, 18 Nov 2025 17:40:06 +0000 (12:40 -0500)
committerIan Alexander <jitsu@google.com>
Tue, 25 Nov 2025 23:17:20 +0000 (15:17 -0800)
This commit makes Unzip a method on the *Fetcher type, and updates
fips140 initialization to use a new Fetcher instance instead of the
global Fetcher_ variable.

Change-Id: Iea8d9ee4dd6e6a2be43520c144aaec6e75c9cd63
Reviewed-on: https://go-review.googlesource.com/c/go/+/722581
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
src/cmd/go/internal/fips140/fips140.go
src/cmd/go/internal/modfetch/fetch.go

index 4194f0ff6aa99743e256b720d3631d5c581a2289..09e4141f9975bff843de62f227b8289fcee2578a 100644 (file)
 package fips140
 
 import (
-       "cmd/go/internal/base"
-       "cmd/go/internal/cfg"
-       "cmd/go/internal/fsys"
-       "cmd/go/internal/modfetch"
-       "cmd/go/internal/str"
        "context"
        "os"
        "path"
@@ -97,6 +92,12 @@ import (
        "slices"
        "strings"
 
+       "cmd/go/internal/base"
+       "cmd/go/internal/cfg"
+       "cmd/go/internal/fsys"
+       "cmd/go/internal/modfetch"
+       "cmd/go/internal/str"
+
        "golang.org/x/mod/module"
        "golang.org/x/mod/semver"
 )
@@ -224,12 +225,11 @@ func initDir() {
 
        mod := module.Version{Path: "golang.org/fips140", Version: v}
        file := filepath.Join(cfg.GOROOT, "lib/fips140", v+".zip")
-       zdir, err := modfetch.Unzip(context.Background(), mod, file)
+       zdir, err := modfetch.NewFetcher().Unzip(context.Background(), mod, file)
        if err != nil {
                base.Fatalf("go: unpacking GOFIPS140=%v: %v", v, err)
        }
        dir = filepath.Join(zdir, "fips140")
-       return
 }
 
 // ResolveImport resolves the import path imp.
index 767bec4cd1341dedc9a42bed3a42cca0d0a6d46a..0d77ed29715b4ade5826626a340e90c3942a5f3a 100644 (file)
@@ -73,12 +73,12 @@ func Download(ctx context.Context, mod module.Version) (dir string, err error) {
 // Unzip is like Download but is given the explicit zip file to use,
 // rather than downloading it. This is used for the GOFIPS140 zip files,
 // which ship in the Go distribution itself.
-func Unzip(ctx context.Context, mod module.Version, zipfile string) (dir string, err error) {
+func (f *Fetcher) Unzip(ctx context.Context, mod module.Version, zipfile string) (dir string, err error) {
        if err := checkCacheDir(ctx); err != nil {
                base.Fatal(err)
        }
 
-       return Fetcher_.downloadCache.Do(mod, func() (string, error) {
+       return f.downloadCache.Do(mod, func() (string, error) {
                ctx, span := trace.StartSpan(ctx, "modfetch.Unzip "+mod.String())
                defer span.Done()
 
@@ -171,10 +171,10 @@ func unzip(ctx context.Context, mod module.Version, zipfile string) (dir string,
        // Go 1.14.2 and higher respect .partial files. Older versions may use
        // partially extracted directories. 'go mod verify' can detect this,
        // and 'go clean -modcache' can fix it.
-       if err := os.MkdirAll(parentDir, 0777); err != nil {
+       if err := os.MkdirAll(parentDir, 0o777); err != nil {
                return "", err
        }
-       if err := os.WriteFile(partialPath, nil, 0666); err != nil {
+       if err := os.WriteFile(partialPath, nil, 0o666); err != nil {
                return "", err
        }
        if err := modzip.Unzip(dir, mod, zipfile); err != nil {
@@ -264,7 +264,7 @@ func downloadZip(ctx context.Context, mod module.Version, zipfile string) (err e
        }
 
        // Create parent directories.
-       if err := os.MkdirAll(filepath.Dir(zipfile), 0777); err != nil {
+       if err := os.MkdirAll(filepath.Dir(zipfile), 0o777); err != nil {
                return err
        }
 
@@ -289,7 +289,7 @@ func downloadZip(ctx context.Context, mod module.Version, zipfile string) (err e
        // contents of the file (by hashing it) before we commit it. Because the file
        // is zip-compressed, we need an actual file — or at least an io.ReaderAt — to
        // validate it: we can't just tee the stream as we write it.
-       f, err := tempFile(ctx, filepath.Dir(zipfile), filepath.Base(zipfile), 0666)
+       f, err := tempFile(ctx, filepath.Dir(zipfile), filepath.Base(zipfile), 0o666)
        if err != nil {
                return err
        }
@@ -404,7 +404,7 @@ func makeDirsReadOnly(dir string) {
        filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
                if err == nil && d.IsDir() {
                        info, err := d.Info()
-                       if err == nil && info.Mode()&0222 != 0 {
+                       if err == nil && info.Mode()&0o222 != 0 {
                                dirs = append(dirs, pathMode{path, info.Mode()})
                        }
                }
@@ -413,7 +413,7 @@ func makeDirsReadOnly(dir string) {
 
        // Run over list backward to chmod children before parents.
        for i := len(dirs) - 1; i >= 0; i-- {
-               os.Chmod(dirs[i].path, dirs[i].mode&^0222)
+               os.Chmod(dirs[i].path, dirs[i].mode&^0o222)
        }
 }
 
@@ -426,7 +426,7 @@ func RemoveAll(dir string) error {
                        return nil // ignore errors walking in file system
                }
                if info.IsDir() {
-                       os.Chmod(path, 0777)
+                       os.Chmod(path, 0o777)
                }
                return nil
        })
@@ -970,7 +970,6 @@ Outer:
                tidyGoSum := tidyGoSum(data, keep)
                return tidyGoSum, nil
        })
-
        if err != nil {
                return fmt.Errorf("updating go.sum: %w", err)
        }