Skip to content

Commit

Permalink
feat: add localWriter
Browse files Browse the repository at this point in the history
We add localWriter to wrap writer in the content store to
make sure not to write any labels in boltdb.
In that case, we can make gc work well with the lease.

Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Aug 6, 2023
1 parent d5d3f82 commit 25e90db
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,36 +162,37 @@ func (content *Content) Abort(ctx context.Context, ref string) error {

func (content *Content) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
writer, err := content.store.Writer(ctx, opts...)
return &LocalWriter{
return &localWriter{
writer: writer,
}, err
}

type LocalWriter struct {
// localWriter wrap the content.Writer
type localWriter struct {
writer content.Writer
}

func (localWriter *LocalWriter) Close() error {
func (localWriter *localWriter) Close() error {
return localWriter.writer.Close()
}

func (localWriter *LocalWriter) Write(p []byte) (int, error) {
func (localWriter *localWriter) Write(p []byte) (int, error) {
return localWriter.writer.Write(p)
}

func (localWriter *LocalWriter) Digest() digest.Digest {
func (localWriter *localWriter) Digest() digest.Digest {
return localWriter.writer.Digest()
}

func (localWriter *LocalWriter) Truncate(size int64) error {
func (localWriter *localWriter) Truncate(size int64) error {
return localWriter.writer.Truncate(size)
}

func (localWriter *LocalWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
func (localWriter *localWriter) Commit(ctx context.Context, size int64, expected digest.Digest, opts ...content.Opt) error {
// we don't write any lables, drop the opts
return localWriter.writer.Commit(ctx, size, expected)
}

func (localWriter *LocalWriter) Status() (st content.Status, err error) {
func (localWriter *localWriter) Status() (st content.Status, err error) {
return localWriter.writer.Status()
}

0 comments on commit 25e90db

Please sign in to comment.