Skip to content

[bug] First-run crash: migrate_config_if_needed copies a non-existent config file #20

Description

@MagicSnake0503

环境

  • 平台:Windows 11 x64(Linux/macOS 同样可复现)
  • 版本:v0.1.15 与 edge(78c6f9eb453d,main 最新)均受影响
  • 场景:全新环境首次启动(无任何已有配置)

现象

全新环境首次运行程序,进程直接退出(exit code 1),无任何错误输出。Windows 下双击 GUI 版表现为"双击没反应";CLI 模式(init-config)同样 exit 1 且无输出(windows_subsystem = "windows" 下错误信息不可见)。

实测:配置目录 %APPDATA%\linuxdo\linuxdo-accelerator\config\ 被创建但为空,linuxdo-accelerator.toml 未被生成。

复现步骤

  1. 确保 %APPDATA%\linuxdo\linuxdo-accelerator 不存在
  2. 运行 linuxdo-accelerator.exe init-configexit 1,config 目录创建但为空
  3. 手动创建空的 linuxdo-accelerator.toml 后再运行同命令 → exit 0,默认配置正常写入

根因

src/config.rsmigrate_config_if_needed 在配置不存在时(首次运行)无条件执行 fs::copy

let marker_path = version_marker_path(path);
if path.exists() && marker_matches_current_version(&marker_path) {
    return Ok(false);        // 仅当配置已存在且版本匹配时才早退
}

let backup_path = backup_config_path(path);
fs::copy(path, &backup_path).with_context(...)?;   // ← 首跑时 path 不存在,这里必然失败

调用链:service::init_config / service::helper_startmigrate_config_if_needed(...)? → Err 直接传播 → main 返回 Err → 进程退出。GUI subsystem 下 stderr 不可见,所以表现为静默退出。

建议修复

copy 前先判断源文件存在:

if path.exists() {
    fs::copy(path, &backup_path).with_context(...)?;
}

证据

$ ./linuxdo-accelerator.exe init-config; echo "exit=$?"
exit=1
# config 目录为空
$ touch %APPDATA%\linuxdo\linuxdo-accelerator\config\linuxdo-accelerator.toml
$ ./linuxdo-accelerator.exe init-config; echo "exit=$?"
exit=0   # 默认配置 1778 字节正常写入

感谢这个项目,Windows 上排查首跑问题花了不少时间,希望这个 issue 能帮到其他新用户。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions