func (b *localDirBackend) WriteMetadata(ctx context.Context, meta *v1alpha1.Metadata, path string) error {
	return b.WriteObject(ctx, path, meta)
}
WriteMetadata writes the provided metadata to disk.
package storage
import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"github.com/sirupsen/logrus"
	"github.com/spf13/afero"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"sigs.k8s.io/yaml"
	"github.com/RedHatGov/bundle/pkg/config/v1alpha1"
)
var _ Backend = &localDirBackend{}
type localDirBackend struct {
	fs  afero.Fs
	dir string
}
func NewLocalBackend(dir string) (Backend, error) {
	b := localDirBackend{
		dir: dir,
	}
	return &b, b.init()
}
func (b *localDirBackend) init() error {
	if b.fs == nil {
		b.fs = afero.NewOsFs()
	}
	if err := b.fs.MkdirAll(b.dir, 0755); err != nil {
		return err
	}
	b.fs = afero.NewBasePathFs(b.fs, b.dir)
	return nil
}
func (b *localDirBackend) ReadMetadata(_ context.Context, meta *v1alpha1.Metadata, path string) error {
	logrus.Debugf("looking for metadata file at %q", path)
	data, err := afero.ReadFile(b.fs, path)
	if err != nil {
		if errors.Is(err, os.ErrNotExist) {
			return ErrMetadataNotExist
		}
		return err
	}
	typeMeta, err := getTypeMeta(data)
	if err != nil {
		return err
	}
	switch typeMeta.GroupVersionKind() {
	case v1alpha1.GroupVersion.WithKind(v1alpha1.MetadataKind):
		*meta, err = v1alpha1.LoadMetadata(data)
	default:
		return fmt.Errorf("config GVK not recognized: %s", typeMeta.GroupVersionKind())
	}
	if err != nil {
		return err
	}
	return nil
}
func getTypeMeta(data []byte) (typeMeta metav1.TypeMeta, err error) {
	if err := yaml.Unmarshal(data, &typeMeta); err != nil {
		return typeMeta, fmt.Errorf("get type meta: %v", err)
	}
	return typeMeta, nil
}