uninstall

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package uninstall removes each item that the CLI made: the container, the volumes, the images, the entries in the files of the apps, the keys of the instance in the key file, the legacy keychain items of the instance, the folders of the CLI, and at the end the binary. It also removes a 2.x install on request.

The functions take an engine interface and folder paths, so that the tests use fakes.

Index

Constants

View Source
const (
	LabelManagedBy = "dev.mai.managed-by"
	ManagedByValue = "mai-cli"
	LabelInstance  = "dev.mai.instance"
	LabelCompose   = "com.docker.compose.project"
)

Labels of the objects that the CLI makes.

View Source
const (
	LegacyContainer = "mai"
	LegacyProject   = "mai"
	LegacyRepo      = "ghcr.io/monorithm/mai"
)

Names of the 2.x install.

View Source
const (
	Gone    = "gone"
	Failure = "failure"
	Kept    = "kept"
	Skipped = "skipped"
)

States of a result.

View Source
const ConfigFile = "config.json"

ConfigFile is the name of the configuration file in the configuration folder.

View Source
const DefaultInstance = "mai"

DefaultInstance is the instance of a command with no --instance and no config.json.

Variables

View Source
var IsKept func(error) bool

IsKept reports if an error of RemoveAppEntry means that the entry stays, because other content of the file needs it. nil counts each error as a failure.

View Source
var LegacyVolumes = []string{"mai_mai-data", "mai_mai-spool", "mai_mai-volume"}

LegacyVolumes are the named volumes of the 2.x compose files.

View Source
var RemoveAppEntry func(manifest.Item) error

RemoveAppEntry removes one entry that mai connect wrote in a file of an app. The part of the CLI that writes the entries sets it. When it is nil, the uninstall keeps each entry and shows a warning.

View Source
var RemoveCreatedAppFile func(manifest.Item) (bool, error)

RemoveCreatedAppFile removes a file of an app that mai connect made, only when the file holds nothing of the user after the remove of the entries. The result is false for a file that stays. The part of the CLI that writes app entries sets it; nil keeps each such file.

Functions

func Confirm

func Confirm(in io.Reader, out io.Writer, yes bool) bool

Confirm wants the typed word "uninstall", unless yes is true.

func DataVolume

func DataVolume(instance string) string

DataVolume is the name of the data volume of an instance.

func EndLeases

func EndLeases(ctx context.Context, hc *http.Client, base string, ks KeySource, instance string) string

EndLeases ends each lease of the server through the owner API. It never fails: it gives a line of text that tells what it did. The bridges stop at their next call.

func ExecOutput

func ExecOutput(ctx context.Context, e Engine, container string, cmd []string) ([]byte, []byte, int, error)

ExecOutput runs a command in the container and gives its standard output and exit code.

func Failed

func Failed(rs []Result) bool

Failed tells if one result is a failure.

func FindLegacyEntries

func FindLegacyEntries(file string) []string

FindLegacyEntries reads one configuration file of an app and gives each 2.x MCP entry in it. It never changes the file.

func HumanSize

func HumanSize(n int64) string

HumanSize gives a size in bytes as text with a binary unit.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound tells if an engine error means that the object does not exist. The client keeps the error class out of reach without a further module, thus the text of the answer of the engine is also examined.

func LegacyAppFiles

func LegacyAppFiles(home, goos string) []string

LegacyAppFiles gives the configuration files of the apps that can hold a 2.x MCP entry.

func Report

func Report(w io.Writer, rs []Result)

Report writes one line for each result.

func SelectContainer

func SelectContainer(ctx context.Context, e Engine) (string, error)

SelectContainer gives the ID of the 2.x container "mai", or "". It selects a container only when it has the compose project label "mai" and no label of the 3.0 CLI.

func SpoolVolume

func SpoolVolume(instance string) string

SpoolVolume is the name of the spool volume of an instance.

func WriteBackup

func WriteBackup(ctx context.Context, e Engine, container, dest string) error

WriteBackup runs "mai backup" in the container and writes one tar archive at dest. The archive holds the database dump and the mail tar of the backup.

Types

type Binary

type Binary struct {
	Path string // the executable, with the symbolic links resolved
	GOOS string
	// Run runs a package manager and waits for it.
	Run func(name string, args ...string) error
	// Start starts a process that continues after the exit of mai.
	Start func(name string, args ...string) error
}

Binary removes the executable of the CLI as the last step.

func (*Binary) Method

func (b *Binary) Method() string

Method tells how the binary goes: "brew", "scoop", "after-exit", or "file".

func (*Binary) Remove

func (b *Binary) Remove() Result

Remove removes the binary and gives the result.

type Config

type Config struct {
	Instance string `json:"instance"`
	Port     int    `json:"port"`
	Image    string `json:"image"`
	DataDir  string `json:"data_dir"`
}

Config is the part of config.json that the uninstall reads. A missing file or field gives the default value.

func LoadConfig

func LoadConfig(dir string) (Config, error)

LoadConfig reads <dir>/config.json and sets the defaults.

type Engine

type Engine interface {
	ContainerList(ctx context.Context, opts client.ContainerListOptions) (client.ContainerListResult, error)
	ContainerInspect(ctx context.Context, id string, opts client.ContainerInspectOptions) (client.ContainerInspectResult, error)
	ContainerRemove(ctx context.Context, id string, opts client.ContainerRemoveOptions) (client.ContainerRemoveResult, error)
	VolumeList(ctx context.Context, opts client.VolumeListOptions) (client.VolumeListResult, error)
	VolumeInspect(ctx context.Context, id string, opts client.VolumeInspectOptions) (client.VolumeInspectResult, error)
	VolumeRemove(ctx context.Context, id string, opts client.VolumeRemoveOptions) (client.VolumeRemoveResult, error)
	ImageList(ctx context.Context, opts client.ImageListOptions) (client.ImageListResult, error)
	ImageInspect(ctx context.Context, id string, opts ...client.ImageInspectOption) (client.ImageInspectResult, error)
	ImageRemove(ctx context.Context, id string, opts client.ImageRemoveOptions) (client.ImageRemoveResult, error)
	DiskUsage(ctx context.Context, opts client.DiskUsageOptions) (client.DiskUsageResult, error)
	ExecCreate(ctx context.Context, id string, opts client.ExecCreateOptions) (client.ExecCreateResult, error)
	ExecAttach(ctx context.Context, id string, opts client.ExecAttachOptions) (client.ExecAttachResult, error)
	ExecInspect(ctx context.Context, id string, opts client.ExecInspectOptions) (client.ExecInspectResult, error)
	CopyFromContainer(ctx context.Context, id string, opts client.CopyFromContainerOptions) (client.CopyFromContainerResult, error)
}

Engine is the part of the Engine API that the uninstall uses. *client.Client satisfies it.

type KeySource added in v3.2.0

type KeySource interface {
	Get(account string) (string, error)
}

KeySource gives the key of an account. The key file of the CLI (keys.File) is one.

type Legacy

type Legacy struct {
	Engine   Engine
	Home     string   // the home folder; the 2.x folder is <Home>/.mai
	AppFiles []string // configuration files of the apps; the uninstall only reads them
	Yes      bool
	In       io.Reader
	Out      io.Writer
}

Legacy removes a 2.x install. It never changes the files of the apps.

func (*Legacy) MakePlan

func (l *Legacy) MakePlan(ctx context.Context) (*LegacyPlan, error)

MakePlan finds the 2.x items.

func (*Legacy) Remove

func (l *Legacy) Remove(ctx context.Context, p *LegacyPlan) []Result

Remove removes the items of the plan and does a check of each one.

func (*Legacy) Run

func (l *Legacy) Run(ctx context.Context) int

Run removes the 2.x install and returns the exit code.

func (*Legacy) Show

func (l *Legacy) Show(p *LegacyPlan)

Show writes the 2.x items.

type LegacyPlan

type LegacyPlan struct {
	Container string // ID of the compose container; empty = none
	Volumes   []string
	Images    []string // references with a 2.x tag
	Folder    string   // empty = none
	Entries   []string // 2.x MCP entries in files of the apps
}

LegacyPlan is the list of 2.x items.

func (*LegacyPlan) Empty

func (p *LegacyPlan) Empty() bool

Empty tells if the plan has no item to remove.

type NotFoundError

type NotFoundError struct{ What string }

NotFoundError is an engine error for a missing object. The fake engine of the tests uses it.

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) NotFound

func (NotFoundError) NotFound()

NotFound marks the error as a missing object.

type Plan

type Plan struct {
	Instance   string
	Containers []string
	Volumes    []string
	Images     []manifest.Item
	AppEntries []manifest.Item
	AppFiles   []manifest.Item // files of apps that mai connect made
	// KeptEntries and KeptFiles hold the app entries and the files of apps of the instance that
	// stay, because a different instance has keys or records. An entry names no instance, thus
	// it serves the instance of config.json at each start of its bridge. Their records get the
	// instance EntryOwner, thus the uninstall of the last instance removes them.
	KeptEntries []manifest.Item
	KeptFiles   []manifest.Item
	EntryOwner  string
	Keys        []string // accounts of the instance in the key file
	Legacy      []string // accounts of the instance with a legacy keychain item
	LegacyErr   error    // the error of the examination of the legacy keychain
	Paths       []string
	DataDirs    []string // the data folders of the instance in Paths
	// Unowned holds each data folder of a record of mai 3.0 or 3.1 whose instance is not
	// known. It stays.
	Unowned []string

	Manifest *manifest.Manifest
	Config   Config
	// Others holds each different instance with a key in the key file or a record in the
	// manifest, sorted. MakePlan sets it, and Remove sets it again after the remove. While
	// it is not empty, the files of the CLI that the other instances use stay.
	Others []string
	// contains filtered or unexported fields
}

Plan is the list of items that the uninstall removes.

type Result

type Result struct {
	Item   string
	State  string
	Detail string
}

Result is the state of one item after the remove.

type Uninstaller

type Uninstaller struct {
	Engine   Engine
	Keys     *keys.File // the key file, with the legacy keychain; nil = no key is removed
	Dirs     paths.Dirs
	Instance string // empty = the instance of config.json
	Yes      bool
	Backup   string // path of a backup archive; empty = no backup
	In       io.Reader
	Out      io.Writer
	HTTP     *http.Client
	BaseURL  string  // base URL of the server; empty = the host port of the container of the instance
	Binary   *Binary // nil = keep the binary
}

Uninstaller removes one instance and the files of the CLI. The files of the CLI that the other instances of the same folders use stay: the key file, the manifest, the configuration file of a different instance, and the binary.

func (*Uninstaller) MakePlan

func (u *Uninstaller) MakePlan() (*Plan, error)

MakePlan reads config.json and the manifest and gives the items to remove. The plan holds only the items of the instance. The records of a different instance stay out of the plan.

func (*Uninstaller) Remove

func (u *Uninstaller) Remove(ctx context.Context, p *Plan) []Result

Remove removes each item of the plan, and does a check of each one after its remove.

func (*Uninstaller) Run

func (u *Uninstaller) Run(ctx context.Context) int

Run does the complete uninstall and returns the exit code.

func (*Uninstaller) Search

func (u *Uninstaller) Search(ctx context.Context, instance string) []Result

Search finds objects of the engine with the labels of the instance. Each object that it finds is a failure.

func (*Uninstaller) Show

func (u *Uninstaller) Show(ctx context.Context, p *Plan)

Show writes the list of items and the size of the mail data.

Jump to

Keyboard shortcuts

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