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): explain a Linux update that got no password prompt

baiyuzeaf4ab5e8cdc7
diff --git a/client-core/internal/update/apply_linux.go b/client-core/internal/update/apply_linux.go
index 0ffb064..8747f99 100644
--- a/client-core/internal/update/apply_linux.go
+++ b/client-core/internal/update/apply_linux.go
@@ -22,10 +22,16 @@ func apply(p *Plan, log *slog.Logger) error {
case KindLinuxDeb:
// /opt 要管理员权限:pkexec 会弹出系统的密码框
out, err := exec.Command("pkexec", "dpkg", "-i", p.Package).CombinedOutput()
+ // 126:用户关掉了密码框。127:没拿到授权,常见的是系统根本没弹密码框——
+ // 后台服务不在桌面会话里(比如从 SSH 启动),找不到桌面的认证代理
var exit *exec.ExitError
- if errors.As(err, &exit) && (exit.ExitCode() == 126 || exit.ExitCode() == 127) {
+ if errors.As(err, &exit) && exit.ExitCode() == 126 {
return errors.New("没有获得管理员授权,已取消安装")
}
+ if errors.As(err, &exit) && exit.ExitCode() == 127 {
+ log.Warn("pkexec 没有获得授权", "out", strings.TrimSpace(string(out)))
+ return errors.New("系统没有弹出密码框:后台服务不是在桌面里启动的(比如从 SSH 启动)。请退出 PasteFerry,从应用菜单重新打开,在「设置 › 后台服务」里重新启动后再试,或者下载 .deb 手动安装")
+ }
if err != nil {
return fmt.Errorf("安装 .deb 失败: %v %s", err, strings.TrimSpace(string(out)))
}
diff --git a/design/auto-update.md b/design/auto-update.md
index 8cd7384..7d9809f 100644
--- a/design/auto-update.md
+++ b/design/auto-update.md
@@ -135,6 +135,14 @@ Problems found and fixed during the validation:
restarting it with the window open left the old process holding the
single-instance lock (seen on Linux). It now waits at most two seconds.
+- 2.6.3: on the Ubuntu VM, an update from 2.5.4 failed within a second each
+ time with "not authorized". The background service had been started over
+ SSH during an earlier test, so it and the windows it opened ran in that
+ SSH session; GNOME's polkit agent only serves the desktop session, and
+ `pkexec` exited 127 without a prompt. The updater now tells 126 (dialog
+ dismissed) from 127 and says to restart the service from the desktop, and
+ the reason reaches the toast, the service log and the diagnostics report.
+
Notes for repeating the test: `pkexec` only shows a password prompt for a
process in the graphical session, so on Linux start the service with
`systemd-run --user --scope`, not from an SSH shell. On Windows, start test
diff --git a/ui/lib/widgets/common.dart b/ui/lib/widgets/common.dart
index c71af80..9ae38fe 100644
--- a/ui/lib/widgets/common.dart
+++ b/ui/lib/widgets/common.dart
@@ -637,7 +637,8 @@ void showToast(
onAction();
}
: null,
- duration: Duration(seconds: hasAction ? 5 : 3),
+ // 出错的提示常带着原因,要多看一会儿
+ duration: Duration(seconds: hasAction || error ? 6 : 3),
onDone: dismiss,
),
);