selfupdate

package module
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLocalVersion  = errors.New("invalid local version")
	ErrInvalidRemoteVersion = errors.New("invalid remote version")
	ErrInvalidRemoteFile    = errors.New("invalid remote file")
)

Functions

func Apply

func Apply(update io.Reader, options ...Option) error

Apply performs an update of the current executable (or opts.TargetFile, if set) with the contents of the given io.Reader.

Apply performs the following actions to ensure a safe cross-platform update:

1. If configured, applies the contents of the update io.Reader as a binary patch.

2. If configured, computes the checksum of the new executable and verifies it matches.

3. If configured, verifies the signature with a public key.

4. Creates a new file, /path/to/.target.new with the TargetMode with the contents of the updated file

5. Renames /path/to/target to /path/to/.target.old

6. Renames /path/to/.target.new to /path/to/target

7. If the final rename is successful, deletes /path/to/.target.old, returns no error. On Windows, the removal of /path/to/target.old always fails, so instead Apply hides the old file instead.

8. If the final rename fails, attempts to roll back by renaming /path/to/.target.old back to /path/to/target.

If the rollback operation fails, the file system is left in an inconsistent state (between steps 5 and 6) where there is no new executable file and the old executable file could not be moved to its original location. In this case you should notify the user of the bad news and ask them to recover manually. Applications can determine whether the rollback failed by calling RollbackError, see the documentation on that function for additional detail.

func RollbackError

func RollbackError(err error) (error, bool)

RollbackError takes an error value returned by Apply and returns the error, if any, that occurred when attempting to roll back from a failed update. Applications should always call this function on any non-nil errors returned by Apply.

If no rollback was needed or if the rollback was successful, RollbackError returns nil, otherwise it returns the error encountered when trying to roll back.

func Update

func Update(source Source, confirm func() bool) error

Types

type GithubProxy

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

func (*GithubProxy) Add

func (t *GithubProxy) Add(proxies ...string) *GithubProxy

func (*GithubProxy) Check

func (t *GithubProxy) Check() *GithubProxy

func (*GithubProxy) Fast

func (t *GithubProxy) Fast() string

func (*GithubProxy) Items

func (t *GithubProxy) Items() []string

func (*GithubProxy) SetTimeout

func (t *GithubProxy) SetTimeout(timeout time.Duration) *GithubProxy

type GoReleaser

type GoReleaser struct {
	Proxy string

	Owner string
	Repo  string
	Name  string
}

GoReleaser

{{ .Proxy }}{{ .Owner }}/{{ .Repo }}/releases/download/{{ .Version }}/{{ .Name or .Repo }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}

func (*GoReleaser) Binary

func (t *GoReleaser) Binary(version string) ([]byte, error)

func (*GoReleaser) Latest

func (t *GoReleaser) Latest() (string, error)

type Option

type Option = optionutil.I[Options]

func WithChecksum

func WithChecksum(hash crypto.Hash, checksum []byte) Option

func WithTargetMode

func WithTargetMode(targetMode os.FileMode) Option

func WithTargetPath

func WithTargetPath(targetPath string) Option

type Options

type Options struct {
	// TargetPath defines the path to the file to update.
	// The empty string means 'the executable file of the running program'.
	TargetPath string

	// Create TargetPath replacement with this file mode. If zero, defaults to 0755.
	TargetMode os.FileMode

	// Checksum of the new binary to verify against. If nil, no checksum or signature verification is done.
	Checksum []byte

	// Use this hash function to generate the checksum. If not set, crypto.SHA256 is used.
	Hash crypto.Hash
}

func (*Options) CheckPermissions

func (o *Options) CheckPermissions() error

CheckPermissions determines whether the process has the correct permissions to perform the requested update. If the update can proceed, it returns nil, otherwise it returns the error that would occur if an update were attempted.

type Source

type Source interface {
	Latest() (string, error)
	Binary(version string) ([]byte, error)
}

type Version

type Version = semver.Version

func CurrentVersion

func CurrentVersion() *Version

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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