mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 16:30:07 +08:00
fix: add code signing for macOS executables during file copy
This commit is contained in:
parent
d2395fb43a
commit
2605bf78f9
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -159,7 +160,7 @@ func (u *CoreUpdater) Update(currentExePath string, channel string, force bool)
|
|||||||
return fmt.Errorf("backuping: %w", err)
|
return fmt.Errorf("backuping: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = u.replace(updateExePath, currentExePath)
|
err = u.copyFile(updateExePath, currentExePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("replacing: %w", err)
|
return fmt.Errorf("replacing: %w", err)
|
||||||
}
|
}
|
||||||
@ -284,21 +285,6 @@ func (u *CoreUpdater) backup(currentExePath, backupExePath, backupDir string) (e
|
|||||||
return nil
|
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.
|
// clean removes the temporary directory itself and all it's contents.
|
||||||
func (u *CoreUpdater) clean(updateDir string) {
|
func (u *CoreUpdater) clean(updateDir string) {
|
||||||
_ = os.RemoveAll(updateDir)
|
_ = os.RemoveAll(updateDir)
|
||||||
@ -474,5 +460,13 @@ func (u *CoreUpdater) copyFile(src, dst string) (err error) {
|
|||||||
return fmt.Errorf("io.Copy(): %w", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user