fs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGitInstalled

func IsGitInstalled() bool

IsGitInstalled checks if git is available in the system path. This allows consumers to check prerequisite without importing pkg/git directly.

Types

type Config

type Config struct {
	Path      string
	AutoInit  bool
	Gitless   bool
	MustExist bool
	Logger    *slog.Logger
}

Config holds the configuration for the filesystem repository.

type Repository

type Repository struct {
	Path string
	// contains filtered or unexported fields
}

Repository implements core.Repository using the filesystem and Git.

func NewRepository

func NewRepository(config Config) *Repository

NewRepository creates a new filesystem-backed repository.

func (*Repository) Begin

func (r *Repository) Begin(ctx context.Context) (core.Transaction, error)

Begin starts a new transaction.

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, id string) error

Delete removes a note.

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, id string) (core.Note, error)

Get retrieves a note from the filesystem.

func (*Repository) Initialize

func (r *Repository) Initialize(ctx context.Context) error

Initialize performs the necessary setup for the repository (mkdir, git init).

func (*Repository) List

func (r *Repository) List(ctx context.Context) ([]core.Note, error)

List scans the directory for all notes.

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, n core.Note) error

Save persists a note to the filesystem and commits it to Git.

func (*Repository) Sync

func (r *Repository) Sync(ctx context.Context) error

Sync synchronizes the repository with its remote.

type Transaction

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

Transaction implements core.Transaction for the filesystem repository. It uses a buffered approach: changes are staged in memory and only written to disk/git on Commit.

func NewTransaction

func NewTransaction(repo *Repository) *Transaction

NewTransaction creates a new transaction for the repository.

func (*Transaction) Commit

func (t *Transaction) Commit(ctx context.Context, changeReason string) error

Commit applies all staged changes atomically.

func (*Transaction) Delete

func (t *Transaction) Delete(ctx context.Context, id string) error

Delete stages a note for removal.

func (*Transaction) Get

func (t *Transaction) Get(ctx context.Context, id string) (core.Note, error)

Get retrieves a note, preferring the staged version if it exists.

func (*Transaction) List

func (t *Transaction) List(ctx context.Context) ([]core.Note, error)

List returns all available notes, including staged ones. Changes in the transaction overlay the repository state.

func (*Transaction) Rollback

func (t *Transaction) Rollback(ctx context.Context) error

Rollback discards all staged changes.

func (*Transaction) Save

func (t *Transaction) Save(ctx context.Context, n core.Note) error

Save stages a note for persistence.

Jump to

Keyboard shortcuts

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