Documentation
¶
Overview ¶
Package repository contains the packaging logic of the updater.
Index ¶
- type PackageStates
- type PreRemoveHook
- type Repositories
- func (r *Repositories) AvailableDiskSpace() (uint64, error)
- func (r *Repositories) Cleanup(ctx context.Context) error
- func (r *Repositories) Create(ctx context.Context, pkg string, version string, stableSourcePath string) error
- func (r *Repositories) Delete(ctx context.Context, pkg string) error
- func (r *Repositories) Get(pkg string) *Repository
- func (r *Repositories) GetState(pkg string) (State, error)
- func (r *Repositories) GetStates() (map[string]State, error)
- func (r *Repositories) MkdirTemp() (string, error)
- func (r *Repositories) RootPath() string
- type Repository
- func (r *Repository) Cleanup(ctx context.Context) error
- func (r *Repository) Create(ctx context.Context, name string, stableSourcePath string) error
- func (r *Repository) Delete(ctx context.Context) error
- func (r *Repository) DeleteExperiment(ctx context.Context) error
- func (r *Repository) ExperimentFS() fs.FS
- func (r *Repository) ExperimentPath() string
- func (r *Repository) GetState() (State, error)
- func (r *Repository) PromoteExperiment(ctx context.Context) error
- func (r *Repository) SetExperiment(ctx context.Context, name string, sourcePath string) error
- func (r *Repository) StableFS() fs.FS
- func (r *Repository) StablePath() string
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PackageStates ¶ added in v0.65.0
type PackageStates struct {
States map[string]State `json:"states"`
ConfigStates map[string]State `json:"config_states"`
}
PackageStates contains the state all installed packages
type PreRemoveHook ¶ added in v0.65.0
PreRemoveHook are called before a package is removed. It returns a boolean indicating if the package files can be deleted safely and an error if an error happened when running the hook.
type Repositories ¶
type Repositories struct {
// contains filtered or unexported fields
}
Repositories manages multiple repositories.
func NewRepositories ¶
func NewRepositories(rootPath string, preRemoveHooks map[string]PreRemoveHook) *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(ctx context.Context) error
Cleanup cleans up the repositories.
func (*Repositories) Create ¶
func (r *Repositories) Create(ctx context.Context, pkg string, version string, stableSourcePath string) error
Create creates a new repository for the given package name.
func (*Repositories) Delete ¶
func (r *Repositories) Delete(ctx 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)
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(ctx context.Context) error
Cleanup calls the cleanup function of the repository
func (*Repository) Create ¶
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) Delete ¶ added in v0.65.0
func (r *Repository) Delete(ctx context.Context) error
Delete deletes the repository.
1. Remove the stable and experiment links. 2. Cleanup the repository to remove all package versions after running the pre-remove hooks. 3. Remove the root directory.
func (*Repository) DeleteExperiment ¶
func (r *Repository) DeleteExperiment(ctx context.Context) 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) ExperimentPath ¶ added in v0.66.0
func (r *Repository) ExperimentPath() string
ExperimentPath returns the experiment package path.
func (*Repository) GetState ¶
func (r *Repository) GetState() (State, error)
GetState returns the state of the repository.
func (*Repository) PromoteExperiment ¶
func (r *Repository) PromoteExperiment(ctx context.Context) 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 ¶
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.
func (*Repository) StablePath ¶ added in v0.66.0
func (r *Repository) StablePath() string
StablePath returns the stable package path.
type State ¶
State is the state of the repository.
func (*State) HasExperiment ¶
HasExperiment returns true if the repository has an experiment package.