mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-07 16:16:37 +08:00
[优化] 使用 slog 替代 fmt 进行日志输出
This commit is contained in:
@@ -4,22 +4,39 @@ package updater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func replaceAndRestart(execPath string, tmpPath string) error {
|
||||
backupPath := execPath + ".bak"
|
||||
os.Remove(backupPath)
|
||||
err := os.Remove(backupPath)
|
||||
if err != nil {
|
||||
slog.Error("remove backup binary failed", "path", backupPath, "error", err)
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(execPath, backupPath); err != nil {
|
||||
os.Remove(tmpPath)
|
||||
err := os.Remove(tmpPath)
|
||||
if err != nil {
|
||||
slog.Error("remove tmp binary failed", "path", tmpPath, "error", err)
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("backup current binary: %w", err)
|
||||
}
|
||||
if err := os.Rename(tmpPath, execPath); err != nil {
|
||||
os.Rename(backupPath, execPath)
|
||||
err := os.Rename(backupPath, execPath)
|
||||
if err != nil {
|
||||
slog.Error("restore backup binary failed", "path", backupPath, "error", err)
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("replace binary: %w", err)
|
||||
}
|
||||
os.Remove(backupPath)
|
||||
err = os.Remove(backupPath)
|
||||
if err != nil {
|
||||
slog.Error("remove backup binary failed", "path", backupPath, "error", err)
|
||||
return err
|
||||
}
|
||||
if err := syscall.Exec(execPath, os.Args, os.Environ()); err != nil {
|
||||
return fmt.Errorf("exec restart: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user