Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/gobuild/gobuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package gobuild

import (
"bytes"
"context"
"errors"
"expvar"
Expand Down Expand Up @@ -121,21 +120,22 @@ func (s *S3Cache) Get(ctx context.Context, actionID string) (outputID, diskPath
return "", "", err
}

object, err := s.S3Client.GetData(ctx, s.outputKey(outputID))
object, size, err := s.S3Client.Get(ctx, s.outputKey(outputID))
if err != nil {
// At this point we know the action exists, so if we can't read the
// object report it as an error rather than a cache miss.
return "", "", fmt.Errorf("[s3] read object %s: %w", outputID, err)
}
defer object.Close()
s.getFaultHit.Add(1)

// Now we should have the body; poke it into the local cache. Preserve the
// modification timestamp recorded with the original action.
diskPath, err = s.Local.Put(ctx, gocache.Object{
ActionID: actionID,
OutputID: outputID,
Size: int64(len(object)),
Body: bytes.NewReader(object),
Size: size,
Body: object,
ModTime: mtime,
})
return outputID, diskPath, err
Expand Down
2 changes: 1 addition & 1 deletion lib/modproxy/modproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *S3Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr
}
defer c.sema.Release(1)

obj, err := c.S3Client.Get(ctx, c.makeKey(hash))
obj, _, err := c.S3Client.Get(ctx, c.makeKey(hash))
if errors.Is(err, fs.ErrNotExist) {
c.getFaultMiss.Add(1)
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions lib/s3util/s3util.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ func (c *Client) Put(ctx context.Context, key string, data io.Reader) error {
// close the reader when finished.
//
// If the key is not found, the resulting error satisfies [fs.ErrNotExist].
func (c *Client) Get(ctx context.Context, key string) (io.ReadCloser, error) {
func (c *Client) Get(ctx context.Context, key string) (io.ReadCloser, int64, error) {
rsp, err := c.Client.GetObject(ctx, &s3.GetObjectInput{
Bucket: &c.Bucket,
Key: &key,
})
if err != nil {
if IsNotExist(err) {
return nil, fmt.Errorf("key %q: %w", key, fs.ErrNotExist)
return nil, -1, fmt.Errorf("key %q: %w", key, fs.ErrNotExist)
}
return nil, err
return nil, -1, err
}
return rsp.Body, nil
return rsp.Body, *rsp.ContentLength, nil
}

// GetData returns the contents of the specified key from S3. It is a shorthand
// for calling Get followed by io.ReadAll on the result.
func (c *Client) GetData(ctx context.Context, key string) ([]byte, error) {
rc, err := c.Get(ctx, key)
rc, _, err := c.Get(ctx, key)
if err != nil {
return nil, err
}
Expand Down