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"
"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"
)
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.
// 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()
// 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 {
}
// 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
}
// 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
}
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()})
}
}
// 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)
}
}
return nil // ignore errors walking in file system
}
if info.IsDir() {
- os.Chmod(path, 0777)
+ os.Chmod(path, 0o777)
}
return nil
})
tidyGoSum := tidyGoSum(data, keep)
return tidyGoSum, nil
})
-
if err != nil {
return fmt.Errorf("updating go.sum: %w", err)
}