Repository: containerd/containerd
File: plugins/content/local/store.go (Go)

Code before:
	root               string
	ls                 LabelStore
	integritySupported bool

	locksMu              sync.Mutex
	locks                map[string]*lock
	ensureIngestRootOnce func() error
}

// NewStore returns a local content store
func NewStore(root string) (content.Store, error) {
	return NewLabeledStore(root, nil)
}

// NewLabeledStore returns a new content store using the provided label store
//
// Note: content stores which are used underneath a metadata store may not
// require labels and should use `NewStore`. `NewLabeledStore` is primarily
// useful for tests or standalone implementations.
func NewLabeledStore(root string, ls LabelStore) (content.Store, error) {
	if err := os.MkdirAll(root, 0755); err != nil {
		return nil, err
	}
	supported, err := fsverity.IsSupported(root)
	if err != nil {
		log.G(context.Background()).WithField("root", root).WithError(err).Warnf("failed to check fsverity support")
	}
	s := &store{
		root:               root,
		ls:                 ls,
		integritySupported: supported,
		locks:              map[string]*lock{},
	}
	s.ensureIngestRootOnce = sync.OnceValue(s.ensureIngestRoot)
	return s, nil
}

func (s *store) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
	p, err := s.blobPath(dgst)
	if err != nil {
		return content.Info{}, fmt.Errorf("calculating blob info path: %w", err)
	}

	fi, err := os.Stat(p)
	if err != nil {
		if os.IsNotExist(err) {
			err = fmt.Errorf("content %v: %w", dgst, errdefs.ErrNotFound)
		}

		return content.Info{}, err
	}

Review comment (bug):
```suggestion
		log.G(context.Background()).WithField("root", root).WithError(err).Warnf("failed check for fsverity support")
```

Code after:
// including resumable ingest.
type store struct {
	root               string
	ls                 LabelStore
	integritySupported bool

	locksMu              sync.Mutex
	locks                map[string]*lock
	ensureIngestRootOnce func() error
}

// NewStore returns a local content store
func NewStore(root string) (content.Store, error) {
	return NewLabeledStore(root, nil)
}

// NewLabeledStore returns a new content store using the provided label store
//
// Note: content stores which are used underneath a metadata store may not
// require labels and should use `NewStore`. `NewLabeledStore` is primarily
// useful for tests or standalone implementations.
func NewLabeledStore(root string, ls LabelStore) (content.Store, error) {
	if _, err := os.Stat(root); err != nil {
		if !errors.Is(err, fs.ErrNotExist) {
			return nil, fmt.Errorf("failed to stat %q: %w", root, err)
		}
		if err := os.MkdirAll(root, 0755); err != nil {
			return nil, fmt.Errorf("failed to mkdir %q: %w", root, err)
		}
	}
	supported, err := fsverity.IsSupported(root)
	if err != nil {
		log.L.WithError(err).WithField("path", root).Warnf("failed check for fsverity support")
	}
	s := &store{
		root:               root,
		ls:                 ls,
		integritySupported: supported,
		locks:              map[string]*lock{},
	}
	s.ensureIngestRootOnce = sync.OnceValue(s.ensureIngestRoot)
	return s, nil
}

func (s *store) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
	p, err := s.blobPath(dgst)
	if err != nil {
		return content.Info{}, fmt.Errorf("calculating blob info path: %w", err)
	}

	fi, err := os.Stat(p)