mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-09-19 20:15:59 +08:00
fix: add code signing for macOS executables during file copy
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -159,7 +160,7 @@ func (u *CoreUpdater) Update(currentExePath string, channel string, force bool)
|
||||
return fmt.Errorf("backuping: %w", err)
|
||||
}
|
||||
|
||||
err = u.replace(updateExePath, currentExePath)
|
||||
err = u.copyFile(updateExePath, currentExePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("replacing: %w", err)
|
||||
}
|
||||
@ -284,21 +285,6 @@ func (u *CoreUpdater) backup(currentExePath, backupExePath, backupDir string) (e
|
||||
return nil
|
||||
}
|
||||
|
||||
// replace moves the current executable with the updated one
|
||||
func (u *CoreUpdater) replace(updateExePath, currentExePath string) error {
|
||||
log.Infoln("replacing: %s to %s", updateExePath, currentExePath)
|
||||
|
||||
// Use copyFile to retain the original file attributes
|
||||
err := u.copyFile(updateExePath, currentExePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infoln("updater: copy: %s to %s", updateExePath, currentExePath)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// clean removes the temporary directory itself and all it's contents.
|
||||
func (u *CoreUpdater) clean(updateDir string) {
|
||||
_ = os.RemoveAll(updateDir)
|
||||
@ -474,5 +460,13 @@ func (u *CoreUpdater) copyFile(src, dst string) (err error) {
|
||||
return fmt.Errorf("io.Copy(): %w", err)
|
||||
}
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
err = exec.Command("/usr/bin/codesign", "--sign", "-", dst).Run()
|
||||
if err != nil {
|
||||
log.Warnln("codesign failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
log.Infoln("updater: copy: %s to %s", src, dst)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user