55 "fmt"
66 "os"
77 "os/exec"
8+ "path/filepath"
89 "time"
910
1011 "github.com/https-cert/deploy/internal/updater"
@@ -49,16 +50,27 @@ func CreateUpdateCmd() *cobra.Command {
4950 RunE : func (cmd * cobra.Command , args []string ) error {
5051 ctx := context .Background ()
5152
53+ // 获取当前可执行文件的真实路径
54+ execPath , err := os .Executable ()
55+ if err != nil {
56+ return fmt .Errorf ("获取可执行文件路径失败: %w" , err )
57+ }
58+ // 解析符号链接,获取真实文件系统路径
59+ execPath , err = filepath .EvalSymlinks (execPath )
60+ if err != nil {
61+ return fmt .Errorf ("解析可执行文件路径失败: %w" , err )
62+ }
63+
5264 fmt .Println ("正在检查更新..." )
5365 info , err := updater .CheckUpdate (ctx )
5466 if err != nil {
5567 return fmt .Errorf ("检查更新失败: %w" , err )
5668 }
5769
58- if ! info .HasUpdate {
59- fmt .Println ("当前已是最新版本" )
60- return nil
61- }
70+ if ! info .HasUpdate {
71+ fmt .Println ("当前已是最新版本" )
72+ return nil
73+ }
6274
6375 fmt .Printf ("发现新版本: %s -> %s\n " , info .CurrentVersion , info .LatestVersion )
6476
@@ -80,11 +92,6 @@ func CreateUpdateCmd() *cobra.Command {
8092 if wasRunning {
8193 fmt .Println ("正在重启守护进程..." )
8294
83- execPath , err := os .Executable ()
84- if err != nil {
85- return fmt .Errorf ("获取可执行文件路径失败,请手动启动: anssl daemon: %w" , err )
86- }
87-
8895 restartCmd := exec .Command (execPath , "daemon" , "-c" , ConfigFile )
8996 if err := restartCmd .Start (); err != nil {
9097 return fmt .Errorf ("守护进程启动失败,请手动启动: anssl daemon: %w" , err )
0 commit comments