simpleupdater

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeSystem

func AnalyzeSystem(file SetupReader) (string, error)

func ExecuteUpdate

func ExecuteUpdate(updaterPath, updateRoot string) error

ExecuteUpdate starts a complete self-update handoff using only the updater helper path and the prepared temporary update directory.

The update directory must contain manifest.json plus the update payload files at the same relative paths described by the manifest. ExecuteUpdate:

  1. resolves the current application's install root and restart target;
  2. reads and validates <updateRoot>/manifest.json;
  3. generates the current platform's update script entirely in memory;
  4. copies updater to an isolated system temporary directory and streams the complete script to that helper over stdin;
  5. terminates the current application after updater has received the script.

On Windows, the current executable's directory is treated as InstallRoot and the executable itself is restarted. On macOS, ExecuteUpdate locates the enclosing .app bundle and uses the bundle root as both InstallRoot and the restart target.

ExecuteUpdate returns only when preparation or updater handoff fails. On a successful handoff it terminates the current process with exit code 0 so the updater can safely replace files that were in use by this application.

func ExtractDMGApp

func ExtractDMGApp(setup SetupReader) (fs.FS, func(), error)

func GenerateSHA256

func GenerateSHA256(file SetupReader) (string, error)

func GenerateSetupFileName added in v0.1.3

func GenerateSetupFileName(product *Product) (string, error)

func GenerateSize

func GenerateSize(file io.Seeker) (int64, error)

func GenerateUpdateScript

func GenerateUpdateScript(system string, manifest []File) (string, error)

GenerateUpdateScript returns an update script for the requested platform.

The generated script is designed to be streamed to the updater helper over stdin; it does not need to be written to disk. The updater helper provides runtime context through these environment variables:

SIMPLE_UPDATER_PID          process id of the application being updated
SIMPLE_UPDATER_INSTALL_ROOT installation root to modify
SIMPLE_UPDATER_PATCH_ROOT   temporary update directory containing patch files
SIMPLE_UPDATER_RESTART_PATH optional executable/.app path to start on success

Lifecycle implemented by the generated script:

  1. wait for the old app to exit, forcing it down after a short grace period;
  2. preflight every target before modifying anything;
  3. back up every existing target into the update directory;
  4. apply and verify all changes;
  5. rollback and show a native error dialog on failure;
  6. on success, remove the entire temporary update directory and restart.

func GenerateUpdateScriptFromJSON

func GenerateUpdateScriptFromJSON(system string, manifest []byte) (string, error)

GenerateUpdateScriptFromJSON parses a manifest.json produced by DownloadPatch and returns a platform-specific update script.

func StartUpdater

func StartUpdater(options UpdaterLaunchOptions) (int, error)

StartUpdater starts a temporary copy of the updater helper, synchronously writes the complete generated update script to its stdin, closes stdin, and then detaches from the helper process. Running an isolated copy allows the updater binary in the application install directory to be replaced by the same update transaction.

Once this function returns successfully, the calling application may exit immediately without truncating the update script.

Types

type AppInfo

type AppInfo struct {
	AppID      string `plist:"CFBundleIdentifier"`
	AppVersion string `plist:"CFBundleVersion"`
	AppName    string `plist:"CFBundleName"`
}

func ReadInfoPlist

func ReadInfoPlist(app fs.FS) (AppInfo, error)

type Client

type Client struct {
	OSS
	DB
}

func New

func New(client *Client) *Client

func (*Client) Compare

func (c *Client) Compare(system string, appID string, files []File) ([]File, error)

func (*Client) DownloadFile

func (c *Client) DownloadFile(path string) ([]byte, error)

func (*Client) DownloadLatestSetup

func (c *Client) DownloadLatestSetup(system, appID string) (*Product, error)

func (*Client) DownloadPatch

func (c *Client) DownloadPatch(files []File) ([]byte, error)

func (*Client) GetLatestSetupInfo added in v0.1.2

func (c *Client) GetLatestSetupInfo(system, appID string) (*Product, error)

func (*Client) Push

func (c *Client) Push(setup SetupReader) (*Product, error)

type DB

type DB struct {
	Host     string //
	Port     string //
	Username string //
	Password string //
	Database string //
	Schema   string //
	Engine   *gorm.DB
}

type File

type File struct {
	Path       string   `json:"path"`
	Type       FileType `json:"type,omitempty"`
	Size       uint64   `json:"size"`
	SHA256     string   `json:"sha256"`
	Mode       uint32   `json:"mode,omitempty"`
	LinkTarget string   `json:"link_target,omitempty"`
	URL        string   `json:"url"`
	Data       []byte   `json:"-"`
}

func ReadProductManifest

func ReadProductManifest(root string) ([]File, error)

func ScanRoot

func ScanRoot(root fs.FS) ([]File, error)

type FileType

type FileType string
const (
	FileTypeRegular FileType = "file"
	FileTypeSymlink FileType = "symlink"
)

type OSS

type OSS struct {
	ID       string //
	Key      string //
	Endpoint string //
	Bucket   string //
	Folder   string //
	Client   *oss.Client
}

type PackageType added in v0.1.3

type PackageType string
const (
	PackageTypeInno PackageType = "inno"
	PackageTypeDMG  PackageType = "dmg"
)

func AnalyzePackage added in v0.1.3

func AnalyzePackage(file SetupReader) (string, PackageType, error)

func (PackageType) Extension added in v0.1.3

func (p PackageType) Extension() string

func (PackageType) System added in v0.1.3

func (p PackageType) System() string

type Product

type Product struct {
	ID          int         `json:"id" gorm:"primaryKey;column:id;type:serial4"`
	CreatedTime time.Time   `json:"created_time" gorm:"column:created_time;type:timestamp;default:CURRENT_TIMESTAMP(0)"` //创建时间
	Product     string      `json:"product" gorm:"column:product;type:varchar(255)"`
	System      string      `json:"system" gorm:"column:system;type:varchar(255)"`
	PackageType PackageType `json:"package_type" gorm:"column:package_type;type:varchar(32);default:''"`
	Version     string      `json:"version" gorm:"column:version;type:varchar(255)"`
	SHA256      string      `json:"sha256" gorm:"column:sha256;type:varchar(64);default:''"`
	URL         string      `json:"url" gorm:"column:url;type:varchar(255)"`
	Size        int64       `json:"size" gorm:"column:size;type:int4"`
	Files       []File      `json:"files" gorm:"column:files;type:jsonb;serializer:json"`
	FileName    string      `json:"file_name" gorm:"column:file_name;type:varchar(255)"`
	AppID       string      `json:"app_id" gorm:"column:app_id;type:varchar(255)"`
	UUID        string      `json:"uuid" gorm:"column:uuid;type:varchar(255)"`
	Data        SetupReader `json:"-" gorm:"-"`
	Bytes       []byte      `json:"-" gorm:"-"`
	RemovedTime *time.Time  `json:"removed_time" gorm:"column:removed_time;type:timestamp;default:null"`
}

func AnalyzeInnoSetupEXE

func AnalyzeInnoSetupEXE(setup SetupReader) (*Product, error)

func AnalyzeSetupDMG

func AnalyzeSetupDMG(setup SetupReader) (*Product, error)

type SetupReader added in v0.1.3

type SetupReader interface {
	io.Reader
	io.ReaderAt
	io.Seeker
}

SetupReader is the minimum capability required to inspect an installer without tying the updater to a concrete filesystem-backed file type.

type UpdaterLaunchOptions

type UpdaterLaunchOptions struct {
	UpdaterPath string
	PID         int
	InstallRoot string
	PatchRoot   string
	RestartPath string
	Script      []byte
	// Archive is an optional gzip-compressed tar stream. When set, StartUpdater
	// extracts it into a temporary patch root and generates the update script.
	// PatchRoot and Script must be empty in archive mode.
	Archive io.Reader
}

UpdaterLaunchOptions describes one handoff from the running application to the tiny updater helper. Script stays in memory and is delivered over stdin.

Directories

Path Synopsis
cmd
build-updaters command
cmd/updater command

Jump to

Keyboard shortcuts

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