Skip to content

Commit

Permalink
unexport the two fields in client and remove the mutext from delayed …
Browse files Browse the repository at this point in the history
…reader
  • Loading branch information
Skarlso committed Dec 17, 2024
1 parent 31c23e8 commit 73e1b47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
36 changes: 18 additions & 18 deletions api/tech/oras/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type ClientOptions struct {
}

type Client struct {
Client *auth.Client
PlainHTTP bool
client *auth.Client
plainHTTP bool
Ref string

rw sync.Mutex
mu sync.Mutex
}

var (
Expand All @@ -36,12 +36,12 @@ var (
)

func New(opts ClientOptions) *Client {
return &Client{Client: opts.Client, PlainHTTP: opts.PlainHTTP}
return &Client{client: opts.Client, plainHTTP: opts.PlainHTTP}
}

func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descriptor, error) {
c.rw.Lock()
defer c.rw.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

src, err := c.createRepository(ref)
if err != nil {
Expand All @@ -66,32 +66,32 @@ func (c *Client) Resolve(ctx context.Context, ref string) (string, ociv1.Descrip
}

func (c *Client) Fetcher(ctx context.Context, ref string) (Fetcher, error) {
c.rw.Lock()
defer c.rw.Unlock()
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.rw.Lock()
defer c.rw.Unlock()
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.rw.Lock()
defer c.rw.Unlock()
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.rw.Lock()
defer c.rw.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

reader, err := src.Reader()
if err != nil {
Expand Down Expand Up @@ -125,8 +125,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.rw.Lock()
defer c.rw.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

src, err := c.createRepository(c.Ref)
if err != nil {
Expand Down Expand Up @@ -168,8 +168,8 @@ func (c *Client) Fetch(ctx context.Context, desc ociv1.Descriptor) (io.ReadClose
}

func (c *Client) List(ctx context.Context) ([]string, error) {
c.rw.Lock()
defer c.rw.Unlock()
c.mu.Lock()
defer c.mu.Unlock()

src, err := c.createRepository(c.Ref)
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions api/tech/oras/delayed_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package oras

import (
"io"
"sync"
)

// delayedReader sets up a reader that only fetches a blob
Expand All @@ -12,7 +11,6 @@ type delayedReader struct {
open func() (io.ReadCloser, error)
rc io.ReadCloser
closed bool
rw sync.Mutex
}

func newDelayedReader(open func() (io.ReadCloser, error)) (*delayedReader, error) {
Expand All @@ -22,9 +20,6 @@ func newDelayedReader(open func() (io.ReadCloser, error)) (*delayedReader, error
}

func (d *delayedReader) Read(p []byte) (n int, err error) {
d.rw.Lock()
defer d.rw.Unlock()

if d.closed {
return 0, io.EOF
}
Expand All @@ -38,9 +33,6 @@ func (d *delayedReader) Read(p []byte) (n int, err error) {
}

func (d *delayedReader) reader() (io.ReadCloser, error) {
d.rw.Lock()
defer d.rw.Unlock()

if d.rc != nil {
return d.rc, nil
}
Expand All @@ -55,9 +47,6 @@ func (d *delayedReader) reader() (io.ReadCloser, error) {
}

func (d *delayedReader) Close() error {
d.rw.Lock()
defer d.rw.Unlock()

if d.closed {
return nil
}
Expand Down

0 comments on commit 73e1b47

Please sign in to comment.