diff --git a/api/tech/oras/client.go b/api/tech/oras/client.go index 76138dc39a..a73e0003a9 100644 --- a/api/tech/oras/client.go +++ b/api/tech/oras/client.go @@ -24,7 +24,7 @@ type Client struct { client *auth.Client plainHTTP bool ref string - mu sync.Mutex + mu sync.RWMutex } var ( @@ -38,10 +38,34 @@ func New(opts ClientOptions) *Client { return &Client{client: opts.Client, plainHTTP: opts.PlainHTTP} } -func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descriptor, error) { +func (c *Client) Fetcher(ctx context.Context, ref string) (Fetcher, error) { + c.mu.Lock() + defer c.mu.Unlock() + + c.ref = ref + return c, nil +} + +func (c *Client) Pusher(ctx context.Context, ref string) (Pusher, error) { c.mu.Lock() defer c.mu.Unlock() + c.ref = ref + return c, nil +} + +func (c *Client) Lister(ctx context.Context, ref string) (Lister, error) { + c.mu.Lock() + defer c.mu.Unlock() + + c.ref = ref + return c, nil +} + +func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descriptor, error) { + c.mu.RLock() + defer c.mu.RUnlock() + src, err := c.createRepository(ref) if err != nil { return "", ociv1.Descriptor{}, err @@ -64,33 +88,9 @@ func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descrip return "", desc, nil } -func (c *Client) Fetcher(ctx context.Context, ref string) (Fetcher, error) { - c.mu.Lock() - defer c.mu.Unlock() - - c.ref = ref - return c, nil -} - -func (c *Client) Pusher(ctx context.Context, ref string) (Pusher, error) { - c.mu.Lock() - defer c.mu.Unlock() - - c.ref = ref - return c, nil -} - -func (c *Client) Lister(ctx context.Context, ref string) (Lister, error) { - c.mu.Lock() - defer c.mu.Unlock() - - c.ref = ref - return c, nil -} - func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) error { - c.mu.Lock() - defer c.mu.Unlock() + c.mu.RLock() + defer c.mu.RUnlock() reader, err := src.Reader() if err != nil { @@ -124,8 +124,8 @@ func (c *Client) Push(ctx context.Context, d ociv1.Descriptor, src Source) error } func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.ReadCloser, error) { - c.mu.Lock() - defer c.mu.Unlock() + c.mu.RLock() + defer c.mu.RUnlock() src, err := c.createRepository(c.ref) if err != nil { @@ -167,8 +167,8 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.ReadClose } func (c *Client) List(ctx context.Context) ([]string, error) { - c.mu.Lock() - defer c.mu.Unlock() + c.mu.RLock() + defer c.mu.RUnlock() src, err := c.createRepository(c.ref) if err != nil {