Skip to content

Commit

Permalink
cmd/go/internal: remove unused result parameter
Browse files Browse the repository at this point in the history
Incomplete Put operation already returns an error.
  • Loading branch information
AlekSi committed Dec 15, 2024
1 parent ccf4ebb commit 7af2680
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions src/cmd/go/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ type Cache interface {
// As a special case, if the ReadSeeker is of type noVerifyReadSeeker,
// the verification from GODEBUG=goverifycache=1 is skipped.
//
// After a success call to Get, OutputFile(Entry.OutputID) must
// After a success call to Put, OutputFile(Entry.OutputID) must
// exist on disk for until Close is called (at the end of the process).
Put(ActionID, io.ReadSeeker) (_ OutputID, size int64, _ error)
Put(ActionID, io.ReadSeeker) (OutputID, error)

// Close is called at the end of the go process. Implementations can do
// cache cleanup work at this phase, or wait for and report any errors from
Expand Down Expand Up @@ -504,7 +504,7 @@ type noVerifyReadSeeker struct {

// Put stores the given output in the cache as the output for the action ID.
// It may read file twice. The content of file must not change between the two passes.
func (c *DiskCache) Put(id ActionID, file io.ReadSeeker) (OutputID, int64, error) {
func (c *DiskCache) Put(id ActionID, file io.ReadSeeker) (OutputID, error) {
wrapper, isNoVerify := file.(noVerifyReadSeeker)
if isNoVerify {
file = wrapper.ReadSeeker
Expand All @@ -515,7 +515,7 @@ func (c *DiskCache) Put(id ActionID, file io.ReadSeeker) (OutputID, int64, error
// PutExecutable is used to store the output as the output for the action ID into a
// file with the given base name, with the executable mode bit set.
// It may read file twice. The content of file must not change between the two passes.
func (c *DiskCache) PutExecutable(id ActionID, name string, file io.ReadSeeker) (OutputID, int64, error) {
func (c *DiskCache) PutExecutable(id ActionID, name string, file io.ReadSeeker) (OutputID, error) {
if name == "" {
panic("PutExecutable called without a name")
}
Expand All @@ -530,19 +530,19 @@ func (c *DiskCache) PutExecutable(id ActionID, name string, file io.ReadSeeker)
// when GODEBUG=goverifycache=1 is set.
// It is meant for data that is OK to cache but that we expect to vary slightly from run to run,
// like test output containing times and the like.
func PutNoVerify(c Cache, id ActionID, file io.ReadSeeker) (OutputID, int64, error) {
func PutNoVerify(c Cache, id ActionID, file io.ReadSeeker) (OutputID, error) {
return c.Put(id, noVerifyReadSeeker{file})
}

func (c *DiskCache) put(id ActionID, executableName string, file io.ReadSeeker, allowVerify bool) (OutputID, int64, error) {
func (c *DiskCache) put(id ActionID, executableName string, file io.ReadSeeker, allowVerify bool) (OutputID, error) {
// Compute output ID.
h := sha256.New()
if _, err := file.Seek(0, 0); err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}
size, err := io.Copy(h, file)
if err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}
var out OutputID
h.Sum(out[:0])
Expand All @@ -553,16 +553,16 @@ func (c *DiskCache) put(id ActionID, executableName string, file io.ReadSeeker,
fileMode = 0o777
}
if err := c.copyFile(file, executableName, out, size, fileMode); err != nil {
return out, size, err
return out, err
}

// Add to cache index.
return out, size, c.putIndexEntry(id, out, size, allowVerify)
return out, c.putIndexEntry(id, out, size, allowVerify)
}

// PutBytes stores the given bytes in the cache as the output for the action ID.
func PutBytes(c Cache, id ActionID, data []byte) error {
_, _, err := c.Put(id, bytes.NewReader(data))
_, err := c.Put(id, bytes.NewReader(data))
return err
}

Expand Down
16 changes: 8 additions & 8 deletions src/cmd/go/internal/cache/prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,26 +378,26 @@ func (c *ProgCache) OutputFile(o OutputID) string {
return c.outputFile[o]
}

func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64, _ error) {
func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (OutputID, error) {
// Compute output ID.
h := sha256.New()
if _, err := file.Seek(0, 0); err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}
size, err := io.Copy(h, file)
if err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}
var out OutputID
h.Sum(out[:0])

if _, err := file.Seek(0, 0); err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}

if !c.can[cmdPut] {
// Child is a read-only cache. Do nothing.
return out, size, nil
return out, nil
}

// For compatibility with Go 1.23/1.24 GOEXPERIMENT=gocacheprog users, also
Expand All @@ -416,13 +416,13 @@ func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64,
BodySize: size,
})
if err != nil {
return OutputID{}, 0, err
return OutputID{}, err
}
if res.DiskPath == "" {
return OutputID{}, 0, errors.New("GOCACHEPROG didn't return DiskPath in put response")
return OutputID{}, errors.New("GOCACHEPROG didn't return DiskPath in put response")
}
c.noteOutputFile(out, res.DiskPath)
return out, size, err
return out, err
}

func (c *ProgCache) Close() error {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
h := cache.NewHash("testmain")
h.Write([]byte("testmain\n"))
h.Write(data)
out, _, err := c.Put(h.Sum(), bytes.NewReader(data))
out, err := c.Put(h.Sum(), bytes.NewReader(data))
if err != nil {
base.Fatalf("%s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/work/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func (p *pgoActor) Act(b *Builder, ctx context.Context, a *Action) error {
}

c := cache.Default()
outputID, _, err := c.Put(a.actionID, r)
outputID, err := c.Put(a.actionID, r)
r.Close()
if err != nil {
return fmt.Errorf("error adding target to cache: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/work/buildid.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ func (b *Builder) updateBuildID(a *Action, target string) error {
if a.output == nil {
panic("internal error: a.output not set")
}
outputID, _, err := c.Put(a.actionID, r)
outputID, err := c.Put(a.actionID, r)
r.Close()
if err == nil && cfg.BuildX {
sh.ShowCmd("", "%s # internal", joinUnambiguously(str.StringList("cp", target, c.OutputFile(outputID))))
Expand All @@ -770,7 +770,7 @@ func (b *Builder) updateBuildID(a *Action, target string) error {
if name == "" {
name = path.Base(a.Package.ImportPath)
}
outputID, _, err := c.PutExecutable(a.actionID, name+cfg.ExeSuffix, r)
outputID, err := c.PutExecutable(a.actionID, name+cfg.ExeSuffix, r)
r.Close()
if err == nil && cfg.BuildX {
sh.ShowCmd("", "%s # internal", joinUnambiguously(str.StringList("cp", target, c.OutputFile(outputID))))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/go/internal/work/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ func (b *Builder) cacheObjdirFile(a *Action, c cache.Cache, name string) error {
return err
}
defer f.Close()
_, _, err = c.Put(cache.Subkey(a.actionID, name), f)
_, err = c.Put(cache.Subkey(a.actionID, name), f)
return err
}

Expand Down

0 comments on commit 7af2680

Please sign in to comment.