gotcore

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const MaxNameLen = 1024

Variables

View Source
var (
	ErrNotExist = errors.New("mark does not exist")
	ErrExists   = errors.New("a mark already exists by that name")
)

Functions

func Apply added in v0.4.0

func Apply(ctx context.Context, fsmach *gotfs.Machine, ss gotfs.RW, fn gotfsvm.Function, ins []gotfs.Root) (gotfs.Root, error)

Apply applies a function to a root to create a new Root.

func CheckName

func CheckName(name string) error

func CloneMark

func CloneMark(ctx context.Context, st SpaceTx, from, to string) error

func ForEach

func ForEach(ctx context.Context, stx SpaceTx, span Span, fn func(string) error) (retErr error)

ForEach is a convenience function which uses Space.List to call fn with all the mark names contained in span.

func GotFS

func GotFS(cfg DSConfig) gotfs.Machine

func GotVC

func GotVC(cfg DSConfig) gotvc.Machine[Payload]

func History

func History(ctx context.Context, vcmach *VCMach, s stores.RO, commRef gdat.Ref, fn func(ref gdat.Ref, comm Commit) error) error

func IsExists

func IsExists(err error) bool

func IsNotExist

func IsNotExist(err error) bool

func PostCommit added in v0.4.0

func PostCommit(ctx context.Context, vcmach *VCMach, srw stores.WO, comm Commit) (gdat.Ref, error)

PostCommit write a commit to the store.

func SortAnnotations

func SortAnnotations(s []Annotation)

func Sync

func Sync(ctx context.Context, src, dst *MarkTx, force bool) error

SyncVolumes syncs the contents of src to dst.

func SyncSpaces

func SyncSpaces(ctx context.Context, task SyncSpacesTask) error

func TestSpace

func TestSpace(t *testing.T, newSpace func(t testing.TB) Space)

func TestSync

func TestSync(t *testing.T, setup func(testing.TB) Space)

func ViewCommit added in v0.4.0

func ViewCommit(ctx context.Context, stx SpaceTx, se CommitExpr, fn func(vctx *ViewCtx) error) error

ViewCommit calls fn with everything needed to read a Commitshot, its filesystem, and its ancestry.

Types

type Annotation

type Annotation struct {
	Key   string `json:"k"`
	Value string `json:"v"`
}

Annotation annotates a mark

func GetAnnotation

func GetAnnotation(as []Annotation, key string) (ret []Annotation)

type ChunkingConfig

type ChunkingConfig struct {
	CD  *Chunking_CDConfig `json:"cd,omitempty"`
	Max *Chunking_Fixed    `json:"fixed,omitempty"`
}

type Chunking_CDConfig

type Chunking_CDConfig struct {
	MeanSize int `json:"mean_size"`
	MaxSize  int `json:"max_size"`
}

type Chunking_Fixed

type Chunking_Fixed struct {
	Max uint32 `json:"max"`
	Min uint32 `json:"min"`
}

type Commit added in v0.4.0

type Commit = gotvc.Vertex[Payload]

Commit is a commitment to a filesystem commit, ancestor Commits, and additional metadata.

func CreateCommit added in v0.4.0

func CreateCommit(ctx context.Context, vcmach *VCMach, srw stores.RW, copa CommitParams) (Commit, error)

CreateCommit creates a new Commit in the store.

func GetCommit added in v0.4.0

func GetCommit(ctx context.Context, s stores.RO, ref gdat.Ref) (Commit, error)

GetCommit reads a commit from the store.

type CommitExpr added in v0.4.0

type CommitExpr interface {
	GetSpace() string
	// Resolve returns a valid Ref, which points to a Commit.
	// Resolve returns the zero valued Ref when a mark does not have a Ref set.
	Resolve(ctx context.Context, stx SpaceTx) (gdat.Ref, error)
	// contains filtered or unexported methods
}

CommitExpr is a sum type representing the different ways to refer to a Commit in Got So far, there are 2 primitive ways - Exactly by Ref - By Mark And 1 higher-order way - By an offset from the result of a previous expression

func ParseCommitExpr added in v0.4.0

func ParseCommitExpr(x string) (CommitExpr, error)

type CommitExpr_Exact added in v0.4.0

type CommitExpr_Exact struct {
	Space string
	Ref   gdat.Ref
}

func ParseCommit_Exact added in v0.4.0

func ParseCommit_Exact(x string) (*CommitExpr_Exact, error)

func (*CommitExpr_Exact) GetSpace added in v0.4.0

func (se *CommitExpr_Exact) GetSpace() string

func (*CommitExpr_Exact) Resolve added in v0.4.0

func (se *CommitExpr_Exact) Resolve(ctx context.Context, tx SpaceTx) (gdat.Ref, error)

type CommitExpr_Mark added in v0.4.0

type CommitExpr_Mark struct {
	Space string
	Name  string
}

func ParseCommit_Mark added in v0.4.0

func ParseCommit_Mark(x string) (*CommitExpr_Mark, error)

func (CommitExpr_Mark) GetSpace added in v0.4.0

func (se CommitExpr_Mark) GetSpace() string

func (CommitExpr_Mark) Resolve added in v0.4.0

func (se CommitExpr_Mark) Resolve(ctx context.Context, tx SpaceTx) (gdat.Ref, error)

func (CommitExpr_Mark) String added in v0.4.0

func (se CommitExpr_Mark) String() string

type CommitExpr_Offset added in v0.4.0

type CommitExpr_Offset struct {
	X      CommitExpr
	Offset uint
}

type CommitNotes added in v0.4.0

type CommitNotes struct {
	AuthoredAt tai64.TAI64  `json:"authored_at"`
	Authors    []inet256.ID `json:"authors"`

	Message string `json:"message"`
}

CommitNotes holds additional information about a commit. This is stored as json in the commit.

type CommitParams added in v0.4.0

type CommitParams struct {
	Committer   inet256.ID
	CommittedAt tai64.TAI64
	Base        []Commit
	Snap        gotfs.Root
	Notes       CommitNotes
}

type DSConfig

type DSConfig struct {
	// Salt is a 32-byte salt used to derive the cryptographic keys for the mark.
	Salt Salt `json:"salt"`
	// GotFS contains all configuration for GotFS
	GotFS FSConfig `json:"fs"`
}

DSConfig holds all data structure parameters

func DefaultConfig

func DefaultConfig(public bool) DSConfig

func (DSConfig) Hash

func (cfg DSConfig) Hash() [32]byte

func (DSConfig) Marshal

func (cfg DSConfig) Marshal(out []byte) []byte

type ErrInvalidName

type ErrInvalidName struct {
	Name   string
	Reason string
}

func (ErrInvalidName) Error

func (e ErrInvalidName) Error() string

type ErrRefIntegrity

type ErrRefIntegrity struct {
	Ref   gdat.Ref
	Store string
}

func (ErrRefIntegrity) Error

func (e ErrRefIntegrity) Error() string

type FSConfig

type FSConfig struct {
	Data     ChunkingConfig    `json:"data_chunking"`
	Metadata Chunking_CDConfig `json:"metadata_chunking"`
}

Config contains all parameters.

type FSMach

type FSMach = gotfs.Machine

type Info

type Info struct {
	// Config holds the all the datastructure parameters
	Config DSConfig `json:"config"`
	// Annotations are arbitrary metadata associated with the mark.
	Annotations []Annotation `json:"annotations"`

	// CreatedAt is the time the mark was created.
	CreatedAt tai64.TAI64 `json:"created_at"`
}

Info is the metadata associated with a Mark.

func CreateIfNotExists

func CreateIfNotExists(ctx context.Context, stx SpaceTx, k string, cfg Metadata) (*Info, error)

func (Info) AsMetadata

func (i Info) AsMetadata() Metadata

func (Info) Clone

func (i Info) Clone() Info

type MarkTx

type MarkTx struct {
	// contains filtered or unexported fields
}

MarkTx scopes down a SpaceTx to a single Mark.

func NewMarkTx

func NewMarkTx(ctx context.Context, stx SpaceTx, name string) (*MarkTx, error)

func (*MarkTx) Apply

func (m *MarkTx) Apply(ctx context.Context, fn func(RW, gdat.Ref) (gdat.Ref, error)) error

Apply calls fn with the Marks target Ref If the mark does not yet have a target, then the ref will be 0.

func (*MarkTx) Config

func (m *MarkTx) Config() DSConfig

func (*MarkTx) FSRO

func (mtx *MarkTx) FSRO() gotfs.RO

func (*MarkTx) FSRW

func (mtx *MarkTx) FSRW() gotfs.RW

func (*MarkTx) GotFS

func (b *MarkTx) GotFS() *gotfs.Machine

func (*MarkTx) GotVC

func (b *MarkTx) GotVC() *VCMach

func (*MarkTx) History

func (b *MarkTx) History(ctx context.Context, fn func(ref gdat.Ref, comm Commit) error) error

func (*MarkTx) Info

func (b *MarkTx) Info() Info

func (*MarkTx) Load

func (b *MarkTx) Load(ctx context.Context, dst *gdat.Ref) (bool, error)

Load loads a commit from the Mark

func (*MarkTx) LoadCommit added in v0.4.0

func (mt *MarkTx) LoadCommit(ctx context.Context, dst *Commit) (bool, error)

func (*MarkTx) LoadFS

func (b *MarkTx) LoadFS(ctx context.Context, dst *gotfs.Root) (bool, error)

func (*MarkTx) Modify

func (m *MarkTx) Modify(ctx context.Context, fn func(mctx ModifyCtx) (*Commit, error)) error

func (*MarkTx) RO

func (mtx *MarkTx) RO() RO

func (*MarkTx) Save

func (m *MarkTx) Save(ctx context.Context, ref gdat.Ref) error

Save saves the commit to the Mark

func (*MarkTx) VCRO

func (mtx *MarkTx) VCRO() stores.RO

func (*MarkTx) VCRW

func (mtx *MarkTx) VCRW() stores.RW

func (*MarkTx) WO

func (mtx *MarkTx) WO() WO

type Metadata

type Metadata struct {
	Config      DSConfig     `json:"config"`
	Annotations []Annotation `json:"annotations"`
}

Metadata is non-volume, user-modifiable information associated with a mark.

func (Metadata) AsInfo

func (c Metadata) AsInfo() Info

func (Metadata) Clone

func (c Metadata) Clone() Metadata

Clone returns a deep copy of md

type ModifyCtx

type ModifyCtx struct {
	VC     *VCMach
	FS     *FSMach
	Stores RW
	Target gdat.Ref
	Root   *Commit
}

ModifyCtx is the context passed to the modify function.

func (*ModifyCtx) Sync

func (mctx *ModifyCtx) Sync(ctx context.Context, srcs RO, root Commit) error

Sync syncs a commit into the Space's store

type Payload

type Payload struct {
	// Snap is the commit of the filesystem.
	Snap  gotfs.Root
	Notes []byte
}

Payload is the thing being committed to.

func ParsePayload

func ParsePayload(data []byte) (Payload, error)

func (Payload) Marshal

func (p Payload) Marshal(out []byte) []byte

func (*Payload) Unmarshal

func (p *Payload) Unmarshal(data []byte) error

type RO added in v0.4.0

type RO struct {
	FS gotfs.RO
	VC stores.RO
}

type RW added in v0.4.0

type RW struct {
	FS gotfs.RW
	VC stores.RW
}

RW are read-write stores

func (RW) RO added in v0.4.0

func (rw RW) RO() RO

func (RW) WO added in v0.4.0

func (rw RW) WO() WO

type Salt

type Salt [32]byte

Salt is a 32-byte salt

func (Salt) MarshalText

func (s Salt) MarshalText() ([]byte, error)

func (*Salt) String

func (s *Salt) String() string

func (*Salt) UnmarshalText

func (s *Salt) UnmarshalText(data []byte) error

type Space

type Space interface {
	// Do calls fn to perform a transaction.
	Do(ctx context.Context, modify bool, fn func(SpaceTx) error) error
}

A Space holds named gotcore.

type SpaceTx

type SpaceTx interface {
	// Create creates a new Mark at name in the Space.
	// The mark will have md for initial metadata.
	// An error is returned if the name already exists.
	Create(ctx context.Context, name string, md Metadata) (*Info, error)
	// Inspect returns all the info for a Mark
	Inspect(ctx context.Context, name string) (*Info, error)
	// SetMetadata sets the metadata for the Mark at name to md
	SetMetadata(ctx context.Context, name string, md Metadata) error
	// Delete deletes a Mark and all of it's metadata, the Commit is not removed.
	Delete(ctx context.Context, name string) error
	// All iterates over all the mark names.
	All(context.Context) iter.Seq2[string, error]

	// Store returns the space's underlying stores
	// These can all be the same store, but each will be passed to different systems.
	// 0: GotFS data stream
	// 1: GotFS metadata
	// 2: GotVC
	Stores() RW
	// SetTarget changes the mark so it points to a different commit
	SetTarget(ctx context.Context, name string, ref gdat.Ref) error
	// GetTarget retrieves the Commit referenced by gdat.Ref
	GetTarget(ctx context.Context, name string, dst *gdat.Ref) (bool, error)
}

SpaceTx is a transaction on a Space

type Span

type Span struct {
	Begin string
	End   string
}

func TotalSpan

func TotalSpan() Span

func (Span) Contains

func (s Span) Contains(x string) bool

type SyncSpacesTask

type SyncSpacesTask struct {
	// Src is the space to read from.
	Src Space
	// Dst is the name ofthe space to write to.
	Dst Space

	// Filter is applied to src to determine what to copy.
	// If nil, then all marks are copied.
	Filter func(string) bool
	// MapName is applied to go from names in the Src space, to name in the Dst space.
	MapName func(string) string
}

SyncSpacesTask contains parameters needed to copy marks from one space to another.

type VCMach

type VCMach = gotvc.Machine[Payload]

type ViewCtx

type ViewCtx struct {
	VC     *VCMach
	FS     *FSMach
	Stores RO
	Target gdat.Ref
	Root   *Commit
}

func (*ViewCtx) FSRO

func (vc *ViewCtx) FSRO() gotfs.RO

type WO added in v0.4.0

type WO struct {
	FS gotfs.WO
	VC stores.WO
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL