Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
tbphp
gpt-load
Repository navigation
Code
Issues
11
(11)
Pull requests
6
(6)
Actions
Security and quality
6
(6)
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
gpt-load
/
update_replace_nonwindows.go
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
42 lines (37 loc) · 1.3 KB
main
Breadcrumbs
gpt-load
/
update_replace_nonwindows.go
Copy path
Top
File metadata and controls
Code
Blame
42 lines (37 loc) · 1.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:build !windows
package main
import (
"fmt"
"os"
"syscall"
)
// replaceExecutable 用 rename 原子替换可执行文件。新文件是新的 inode:运行中的进程继续使用旧文件,
// 也避免 macOS 原地改写已签名文件后程序被系统终止。
func replaceExecutable(target, replacement string) error {
if err := os.Rename(replacement, target); err != nil {
return fmt.Errorf("replace %s: %w", target, err)
}
return nil
}
// preserveExecutableOwner 让新文件沿用原程序的属主和属组。更新者与原文件属主不同(例如 sudo)时,
// 新文件默认归更新者所有;在 0750 这类权限下,服务账号重启时会失去执行权限。
func preserveExecutableOwner(file *os.File, original os.FileInfo) error {
want, ok := original.Sys().(*syscall.Stat_t)
if !ok {
return fmt.Errorf("read owner of %s", original.Name())
}
info, err := file.Stat()
if err != nil {
return err
}
current, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return fmt.Errorf("read owner of %s", file.Name())
}
if current.Uid == want.Uid && current.Gid == want.Gid {
return nil
}
return file.Chown(int(want.Uid), int(want.Gid))
}
// cleanupReplacedExecutable 在非 Windows 平台无需处理:rename 已经直接替换了旧文件。
func cleanupReplacedExecutable() {}
You can’t perform that action at this time.