repository

package
v0.0.0-...-1f3c2e8 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package repository contains the packaging logic of the updater.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Repositories

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

Repositories manages multiple repositories.

func NewRepositories

func NewRepositories(rootPath, locksPath string) *Repositories

NewRepositories returns a new Repositories.

func (*Repositories) AvailableDiskSpace

func (r *Repositories) AvailableDiskSpace() (uint64, error)

AvailableDiskSpace returns the available disk space for the repositories. This will check the underlying partition of the given path. Note that the path must be an existing dir.

On Unix, it is computed using `statfs` and is the number of free blocks available to an unprivileged used * block size See https://man7.org/linux/man-pages/man2/statfs.2.html for more details On Windows, it is computed using `GetDiskFreeSpaceExW` and is the number of bytes available See https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw for more details

func (*Repositories) Cleanup

func (r *Repositories) Cleanup() error

Cleanup cleans up the repositories.

func (*Repositories) Create

func (r *Repositories) Create(pkg string, version string, stableSourcePath string) error

Create creates a new repository for the given package name.

func (*Repositories) Delete

func (r *Repositories) Delete(_ context.Context, pkg string) error

Delete deletes the repository for the given package name.

func (*Repositories) Get

func (r *Repositories) Get(pkg string) *Repository

Get returns the repository for the given package name.

func (*Repositories) GetState

func (r *Repositories) GetState(pkg string) (State, error)

GetState returns the state of the given package.

func (*Repositories) GetStates

func (r *Repositories) GetStates() (map[string]State, error)

GetStates returns the state of all repositories.

func (*Repositories) MkdirTemp

func (r *Repositories) MkdirTemp() (string, error)

MkdirTemp creates a temporary directory in the same partition as the root path. This ensures that the temporary directory can be moved to the root path without copying. The caller is responsible for cleaning up the directory.

func (*Repositories) RootPath

func (r *Repositories) RootPath() string

RootPath returns the root path of the repositories.

type Repository

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

Repository contains the stable and experimental package of a single artifact managed by the updater.

On disk the repository is structured as follows: . ├── 7.50.0 ├── 7.51.0 ├── stable -> 7.50.0 (symlink) └── experiment -> 7.51.0 (symlink)

and the locks directory (if any) is structured as follows: . ├── 7.50.0 │ └── 1234 ├── 7.51.0 │ └── 5678

We voluntarily do not load the state of the repository in memory to avoid any bugs where what's on disk and what's in memory are not in sync. All the functions of the repository are "atomic" and ensure no invalid state can be reached even if an error happens during their execution. It is possible to end up with garbage left on disk if an error happens during some operations. This is cleaned up during the next operation.

func (*Repository) Cleanup

func (r *Repository) Cleanup() error

Cleanup calls the cleanup function of the repository

func (*Repository) Create

func (r *Repository) Create(name string, stableSourcePath string) error

Create creates a fresh new repository at the given root path and moves the given stable source path to the repository as the first stable. If a repository already exists at the given path, it is fully removed.

1. Remove the previous repository if it exists. 2. Create the root directory. 3. Move the stable source to the repository. 4. Create the stable link.

func (*Repository) DeleteExperiment

func (r *Repository) DeleteExperiment() error

DeleteExperiment deletes the experiment.

1. Cleanup the repository. 2. Sets the experiment link to the stable link. 3. Cleanup the repository to remove the previous experiment package.

func (*Repository) ExperimentFS

func (r *Repository) ExperimentFS() fs.FS

ExperimentFS returns the experiment package fs.

func (*Repository) GetState

func (r *Repository) GetState() (State, error)

GetState returns the state of the repository.

func (*Repository) PromoteExperiment

func (r *Repository) PromoteExperiment() error

PromoteExperiment promotes the experiment to stable.

1. Cleanup the repository. 2. Set the stable link to the experiment package. The experiment link stays in place. 3. Cleanup the repository to remove the previous stable package.

func (*Repository) SetExperiment

func (r *Repository) SetExperiment(name string, sourcePath string) error

SetExperiment moves package files from the given source path to the repository and sets it as the experiment.

1. Cleanup the repository. 2. Move the experiment source to the repository. 3. Set the experiment link to the experiment package.

func (*Repository) StableFS

func (r *Repository) StableFS() fs.FS

StableFS returns the stable package fs.

type State

type State struct {
	Stable     string
	Experiment string
}

State is the state of the repository.

func (*State) HasExperiment

func (s *State) HasExperiment() bool

HasExperiment returns true if the repository has an experiment package.

func (*State) HasStable

func (s *State) HasStable() bool

HasStable returns true if the repository has a stable package.

Jump to

Keyboard shortcuts

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