func (u *Update) getPath() (string, error) { if u.TargetPath == "" { return osext.Executable() } else { return u.TargetPath, nil } }
func (u *Updater) update() error { path, err := osext.Executable() if err != nil { return err } old, err := os.Open(path) if err != nil { return err } defer old.Close() err = u.fetchInfo() if err != nil { return err } if u.Info.Version == u.CurrentVersion { return nil } bin, err := u.fetchAndVerifyPatch(old) if err != nil { if err == ErrHashMismatch { log.Println("update: hash mismatch from patched binary") } else { if u.DiffURL != "" { log.Println("update: patching binary,", err) } } bin, err = u.fetchAndVerifyFullBin() if err != nil { if err == ErrHashMismatch { log.Println("update: hash mismatch from full binary") } else { log.Println("update: fetching full binary,", err) } return err } } // close the old binary before installing because on windows // it can't be renamed if a handle to the file is still open old.Close() err, errRecover := up.FromStream(bytes.NewBuffer(bin)) if errRecover != nil { return fmt.Errorf("update and recovery errors: %q %q", err, errRecover) } if err != nil { return err } return nil }
func defaultChecksum() string { path, err := osext.Executable() if err != nil { return "" } checksum, err := update.ChecksumForFile(path) if err != nil { return "" } return hex.EncodeToString(checksum) }
func (u *Updater) getExecRelativeDir(dir string) string { filename, _ := osext.Executable() path := filepath.Join(filepath.Dir(filename), dir) return path }