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 5, 2023
1 parent 7bece14 commit d5d3f82
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion pkg/content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func (content *Content) Info(ctx context.Context, dgst digest.Digest) (content.I
}

func (content *Content) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
if info.Labels != nil {
info.Labels = nil
}
return content.store.Update(ctx, info, fieldpaths...)
}

Expand Down Expand Up @@ -158,5 +161,37 @@ func (content *Content) Abort(ctx context.Context, ref string) error {
}

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

type LocalWriter struct {
writer content.Writer
}

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

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

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

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 {
// 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) {
return localWriter.writer.Status()
}

0 comments on commit d5d3f82

Please sign in to comment.