Documentation
¶
Index ¶
- func AnalyzeSystem(file SetupReader) (string, error)
- func ExecuteUpdate(updaterPath, updateRoot string) error
- func ExtractDMGApp(setup SetupReader) (fs.FS, func(), error)
- func GenerateSHA256(file SetupReader) (string, error)
- func GenerateSetupFileName(product *Product) (string, error)
- func GenerateSize(file io.Seeker) (int64, error)
- func GenerateUpdateScript(system string, manifest []File) (string, error)
- func GenerateUpdateScriptFromJSON(system string, manifest []byte) (string, error)
- func StartUpdater(options UpdaterLaunchOptions) (int, error)
- type AppInfo
- type Client
- func (c *Client) Compare(system string, appID string, files []File) ([]File, error)
- func (c *Client) DownloadFile(path string) ([]byte, error)
- func (c *Client) DownloadLatestSetup(system, appID string) (*Product, error)
- func (c *Client) DownloadPatch(files []File) ([]byte, error)
- func (c *Client) GetLatestSetupInfo(system, appID string) (*Product, error)
- func (c *Client) Push(setup SetupReader) (*Product, error)
- type DB
- type File
- type FileType
- type OSS
- type PackageType
- type Product
- type SetupReader
- type UpdaterLaunchOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnalyzeSystem ¶
func AnalyzeSystem(file SetupReader) (string, error)
func ExecuteUpdate ¶
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:
- resolves the current application's install root and restart target;
- reads and validates <updateRoot>/manifest.json;
- generates the current platform's update script entirely in memory;
- copies updater to an isolated system temporary directory and streams the complete script to that helper over stdin;
- 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 GenerateUpdateScript ¶
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:
- wait for the old app to exit, forcing it down after a short grace period;
- preflight every target before modifying anything;
- back up every existing target into the update directory;
- apply and verify all changes;
- rollback and show a native error dialog on failure;
- on success, remove the entire temporary update directory and restart.
func GenerateUpdateScriptFromJSON ¶
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 Client ¶
func (*Client) DownloadLatestSetup ¶
func (*Client) GetLatestSetupInfo ¶ added in v0.1.2
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 ¶
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
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.