Skip to content

Commit 2605bf7

Browse files
xishang0128wwqgtxx
authored andcommitted
fix: add code signing for macOS executables during file copy
1 parent d2395fb commit 2605bf7

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

component/updater/update_core.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"net/http"
1010
"os"
11+
"os/exec"
1112
"path/filepath"
1213
"runtime"
1314
"strings"
@@ -159,7 +160,7 @@ func (u *CoreUpdater) Update(currentExePath string, channel string, force bool)
159160
return fmt.Errorf("backuping: %w", err)
160161
}
161162

162-
err = u.replace(updateExePath, currentExePath)
163+
err = u.copyFile(updateExePath, currentExePath)
163164
if err != nil {
164165
return fmt.Errorf("replacing: %w", err)
165166
}
@@ -284,21 +285,6 @@ func (u *CoreUpdater) backup(currentExePath, backupExePath, backupDir string) (e
284285
return nil
285286
}
286287

287-
// replace moves the current executable with the updated one
288-
func (u *CoreUpdater) replace(updateExePath, currentExePath string) error {
289-
log.Infoln("replacing: %s to %s", updateExePath, currentExePath)
290-
291-
// Use copyFile to retain the original file attributes
292-
err := u.copyFile(updateExePath, currentExePath)
293-
if err != nil {
294-
return err
295-
}
296-
297-
log.Infoln("updater: copy: %s to %s", updateExePath, currentExePath)
298-
299-
return nil
300-
}
301-
302288
// clean removes the temporary directory itself and all it's contents.
303289
func (u *CoreUpdater) clean(updateDir string) {
304290
_ = os.RemoveAll(updateDir)
@@ -474,5 +460,13 @@ func (u *CoreUpdater) copyFile(src, dst string) (err error) {
474460
return fmt.Errorf("io.Copy(): %w", err)
475461
}
476462

463+
if runtime.GOOS == "darwin" {
464+
err = exec.Command("/usr/bin/codesign", "--sign", "-", dst).Run()
465+
if err != nil {
466+
log.Warnln("codesign failed: %v", err)
467+
}
468+
}
469+
470+
log.Infoln("updater: copy: %s to %s", src, dst)
477471
return nil
478472
}

0 commit comments

Comments
 (0)