Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

fix(core): run the updater outside the folder it replaces

baiyuzea975f85d3e76
diff --git a/client-core/internal/update/apply.go b/client-core/internal/update/apply.go
index 68d5a9a..23ec857 100644
--- a/client-core/internal/update/apply.go
+++ b/client-core/internal/update/apply.go
@@ -83,6 +83,7 @@ func Start(p *Plan, work string) error {
return err
}
cmd := exec.Command(helper, "-apply-update", planPath)
+ cmd.Dir = work
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("启动更新助手: %v %s", err, out)
}
@@ -92,6 +93,8 @@ func Start(p *Plan, work string) error {
// RunHelper 是更新助手的入口(pasteferryd -apply-update / -apply-update-run)。
// detach 为 true 时只负责启动脱离进程树的第二级,然后退出。
func RunHelper(planPath string, detach bool) int {
+ // 工作目录不能留在要替换的文件夹里:Windows 上被当作工作目录的文件夹不能改名
+ _ = os.Chdir(filepath.Dir(planPath))
if detach {
self, err := os.Executable()
if err == nil {
diff --git a/client-core/internal/update/proc_unix.go b/client-core/internal/update/proc_unix.go
index da7cca8..bbda3e9 100644
--- a/client-core/internal/update/proc_unix.go
+++ b/client-core/internal/update/proc_unix.go
@@ -56,6 +56,8 @@ func processInDir(pid int, dir string) bool {
func startDetached(path string, args ...string) error {
cmd := exec.Command(path, args...)
+ // 在程序自己的文件夹里运行,不把调用者的工作目录(可能是要替换的文件夹)带过去
+ cmd.Dir = filepath.Dir(path)
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
if err := cmd.Start(); err != nil {
return err
diff --git a/client-core/internal/update/proc_windows.go b/client-core/internal/update/proc_windows.go
index e11c886..cf47739 100644
--- a/client-core/internal/update/proc_windows.go
+++ b/client-core/internal/update/proc_windows.go
@@ -49,6 +49,8 @@ func processInDir(pid int, dir string) bool {
func startDetached(path string, args ...string) error {
cmd := exec.Command(path, args...)
+ // 在程序自己的文件夹里运行,不把调用者的工作目录(可能是要替换的文件夹)带过去
+ cmd.Dir = filepath.Dir(path)
cmd.SysProcAttr = &syscall.SysProcAttr{
CreationFlags: windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP,
HideWindow: true,