Skip to content

Commit

Permalink
fix(file.Store): fix race condition on restoring the same named content
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <shizh@microsoft.com>
  • Loading branch information
shizhMSFT committed Mar 20, 2024
1 parent d3ff5dc commit 4c41fa2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions content/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func (s *Store) push(ctx context.Context, expected ocispec.Descriptor, content i
return nil
}

// restoreDuplicates restores successor files with same content but different names.
// restoreDuplicates restores successor files with same content but different
// names.
// See Store.ForceCAS for more info.
func (s *Store) restoreDuplicates(ctx context.Context, desc ocispec.Descriptor) error {
successors, err := content.Successors(ctx, s, desc)
Expand All @@ -310,8 +311,16 @@ func (s *Store) restoreDuplicates(ctx context.Context, desc ocispec.Descriptor)
return fmt.Errorf("%q: %s: %w", name, desc.MediaType, err)
}
return nil
}(); err != nil && !errors.Is(err, errdef.ErrNotFound) {
return err
}(); err != nil {
switch {
case errors.Is(err, errdef.ErrNotFound):
// allow pushing manifests before blobs
case errors.Is(err, ErrDuplicateName):

Check warning on line 318 in content/file/file.go

View check run for this annotation

Codecov / codecov/patch

content/file/file.go#L318

Added line #L318 was not covered by tests
// in case multiple goroutines are pushing or restoring the same
// named content, the error is ignored
default:
return err

Check warning on line 322 in content/file/file.go

View check run for this annotation

Codecov / codecov/patch

content/file/file.go#L321-L322

Added lines #L321 - L322 were not covered by tests
}
}
}
return nil
Expand Down

0 comments on commit 4c41fa2

Please sign in to comment.