Merge pull request #2425 from sipsma/refinalize

Re-add Finalize method to ImmutableRef.
master
Tõnis Tiigi 2021-10-25 15:24:36 -07:00 committed by GitHub
commit 33fb83eb71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

2
cache/blobs.go vendored
View File

@ -39,7 +39,7 @@ func (sr *immutableRef) computeBlobChain(ctx context.Context, createIfNeeded boo
return errors.Errorf("missing lease requirement for computeBlobChain")
}
if err := sr.finalizeLocked(ctx); err != nil {
if err := sr.Finalize(ctx); err != nil {
return err
}

4
cache/manager.go vendored
View File

@ -129,7 +129,7 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispecs.Descriptor,
chainID = imagespecidentity.ChainID([]digest.Digest{p.getChainID(), chainID})
blobChainID = imagespecidentity.ChainID([]digest.Digest{p.getBlobChainID(), blobChainID})
if err := p.finalizeLocked(ctx); err != nil {
if err := p.Finalize(ctx); err != nil {
p.Release(context.TODO())
return nil, err
}
@ -467,7 +467,7 @@ func (cm *cacheManager) New(ctx context.Context, s ImmutableRef, sess session.Gr
}
parent = p.(*immutableRef)
}
if err := parent.finalizeLocked(ctx); err != nil {
if err := parent.Finalize(ctx); err != nil {
return nil, err
}
if err := parent.Extract(ctx, sess); err != nil {

View File

@ -226,7 +226,7 @@ func TestManager(t *testing.T) {
checkDiskUsage(ctx, t, cm, 1, 0)
err = snap.(*immutableRef).finalizeLocked(ctx)
err = snap.Finalize(ctx)
require.NoError(t, err)
err = snap.Release(ctx)
@ -948,7 +948,7 @@ func TestLazyCommit(t *testing.T) {
require.NoError(t, err)
// this time finalize commit
err = snap.(*immutableRef).finalizeLocked(ctx)
err = snap.Finalize(ctx)
require.NoError(t, err)
err = snap.Release(ctx)
@ -1022,7 +1022,7 @@ func TestLazyCommit(t *testing.T) {
snap2, err = cm.Get(ctx, snap.ID())
require.NoError(t, err)
err = snap2.(*immutableRef).finalizeLocked(ctx)
err = snap2.Finalize(ctx)
require.NoError(t, err)
err = snap2.Release(ctx)

5
cache/refs.go vendored
View File

@ -40,6 +40,9 @@ type ImmutableRef interface {
Ref
Parent() ImmutableRef
Clone() ImmutableRef
// Finalize commits the snapshot to the driver if it's not already.
// This means the snapshot can no longer be mounted as mutable.
Finalize(context.Context) error
Extract(ctx context.Context, s session.Group) error // +progress
GetRemote(ctx context.Context, createIfNeeded bool, compressionType compression.Type, forceCompression bool, s session.Group) (*solver.Remote, error)
@ -818,7 +821,7 @@ func (sr *immutableRef) release(ctx context.Context) error {
return nil
}
func (sr *immutableRef) finalizeLocked(ctx context.Context) error {
func (sr *immutableRef) Finalize(ctx context.Context) error {
sr.mu.Lock()
defer sr.mu.Unlock()
return sr.finalize(ctx)