@@ -260,13 +260,21 @@ func getHTTPClient() *http.Client {
260260// transformDownloadURL 根据配置转换下载 URL(使用镜像加速)
261261func transformDownloadURL (originalURL string ) string {
262262 cfg := config .GetConfig ()
263- if cfg == nil || cfg .Update .Mirror == "" || cfg .Update .Mirror == mirrorGitHub {
264- // 未配置使用 mirrorGHProxy
265- if cfg .Update .Mirror == "" {
266- mirrorURL := mirrorMap [mirrorGHProxy ]
267263
268- return strings .Replace (originalURL , "https://github.com" , mirrorURL , 1 )
269- }
264+ // 如果配置为空或未配置镜像,使用默认镜像 ghproxy
265+ if cfg == nil {
266+ mirrorURL := mirrorMap [mirrorGHProxy ]
267+ return strings .Replace (originalURL , "https://github.com" , mirrorURL , 1 )
268+ }
269+
270+ // 如果未配置镜像或镜像为空,使用默认镜像 ghproxy
271+ if cfg .Update .Mirror == "" {
272+ mirrorURL := mirrorMap [mirrorGHProxy ]
273+ return strings .Replace (originalURL , "https://github.com" , mirrorURL , 1 )
274+ }
275+
276+ // 如果明确配置使用 GitHub 原始地址,直接返回
277+ if cfg .Update .Mirror == mirrorGitHub {
270278 return originalURL
271279 }
272280
@@ -429,8 +437,27 @@ func replaceExecutable(newPath, oldPath string) error {
429437 return nil
430438 }
431439
432- // Unix 系统可以直接替换
433- return copyFile (newPath , oldPath )
440+ // Unix 系统:先删除旧文件,再移动新文件
441+ // 注意:即使进程正在运行,删除文件也不会影响当前进程(inode 仍然存在)
442+ // 但是需要保留权限,所以先获取权限
443+ oldInfo , err := os .Stat (oldPath )
444+ if err != nil {
445+ return err
446+ }
447+ oldMode := oldInfo .Mode ()
448+
449+ // 删除旧文件(进程仍在运行,inode 保留)
450+ if err := os .Remove (oldPath ); err != nil {
451+ return err
452+ }
453+
454+ // 移动新文件到目标位置(原子操作)
455+ if err := os .Rename (newPath , oldPath ); err != nil {
456+ return err
457+ }
458+
459+ // 设置正确的权限
460+ return os .Chmod (oldPath , oldMode )
434461}
435462
436463// copyFile 复制文件
0 commit comments