database

package
v0.0.0-...-e258396 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package database contains the DistroDB object and its methods. It manages a database of Windows Subsystem for Linux distribution instances (aka distros).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistroDB

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

DistroDB is a thread-safe single-table database of WSL distribution instances. This database is held in memory and backed in disk. Any write on the database will be instanly followed up by a write-to-disk.

func New

func New(ctx context.Context, storageDir string) (db *DistroDB, err error)

New creates a database and populates it with data in the file located at "storagePath". Changes to the database will be written on this file.

You must call Close to deallocate resources.

Creating multiple databases with the same disk backing will result in undefined behaviour.

Every certain amount of times, the database wil purge all distros that are no longer registered or that have been marked as unreachable. This cleanup can be triggered on demmand with TriggerCleanup.

func (*DistroDB) Close

func (db *DistroDB) Close(ctx context.Context)

Close frees up resources allocated to database maintenance and ensures the database contents are written to file.

func (*DistroDB) Dump

func (db *DistroDB) Dump() error

Dump stores the current database state to disk, overriding old dumps. Next time we start the agent, the database will be loaded from this dump.

func (*DistroDB) Get

func (db *DistroDB) Get(name string) (distro *distro.Distro, ok bool)

Get searches for the target distro. It returns the distro object and a flag indicating if it was found. TODO: check if useful as public.

func (*DistroDB) GetAll

func (db *DistroDB) GetAll() (all []*distro.Distro)

GetAll returns a slice with all the distros in the database.

func (*DistroDB) GetDistroAndUpdateProperties

func (db *DistroDB) GetDistroAndUpdateProperties(ctx context.Context, name string, props distro.Properties) (*distro.Distro, error)

GetDistroAndUpdateProperties fetches a distro from the database, guranteeing that the returned distro is valid, is in the database, and matches the given properties. If needed: * A pre-existing distro with the same name may be removed from the database. * An existing distro in the database may have their properties updated. * A new distro may be added to the database.

func (*DistroDB) TriggerCleanup

func (db *DistroDB) TriggerCleanup()

TriggerCleanup forces the database cleanup loop to skip its current delay and call autoCleanup immediately. It is blocking until the cleanup starts.

Jump to

Keyboard shortcuts

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