Skip to content

feat: 支持修改启动器数据目录位置(issue #43) - #44

Open
yukitakasama wants to merge 8 commits into
dsh-plugins:mainfrom
yukitakasama:feat/relocatable-data-dir
Open

feat: 支持修改启动器数据目录位置(issue #43)#44
yukitakasama wants to merge 8 commits into
dsh-plugins:mainfrom
yukitakasama:feat/relocatable-data-dir

Conversation

@yukitakasama

Copy link
Copy Markdown
Contributor

概述

支持修改启动器数据目录位置(issue #43)。设置页「数据目录」卡片新增「更改位置」入口,重启后自动把现有数据(配置、版本、HOME 目录、日志、npm 缓存、托管 node 等)迁移到新位置;支持 DSH_LAUNCHER_DATA_HOME 环境变量覆盖;任一步失败自动回滚,不损坏原数据。

变更内容

自举解析链(migrate.rs)

优先级:DSH_LAUNCHER_DATA_HOME 环境变量 > 指针文件 <默认app_data_dir>\data-home.txt > 默认目录。

迁移状态机

迁移在重启后的启动阶段执行(日志文件句柄打开之前),流程:

  1. 目标为空目录才允许迁移;写入 MIGRATION_IN_PROGRESS 标记(power-failure/杀进程安全,中断后下次启动清理半成品重来)
  2. 复制 config.json / versions/ / homes/ / logs/ / .pnpm-store/ / tools/ / icons/ / bin/(纯 std::fs 递归,不新增依赖)
  3. 校验:文件数 + 总大小 + 新 config.json 可解析
  4. 切换并删除标记;旧目录快照为 <dir>.old-<ts>,不直接删除(30 天恢复窗口)
  5. 任一步失败 → 删除目标半成品 + 移除指针 → 回退默认目录正常启动

新命令

  • pick_data_dir — 打开目录选择器(tauri-plugin-dialog)
  • commit_data_dir — 校验新目录(非空 / 是否已存在 / 可写)并写入指针文件,不移动文件
  • get_data_dir_source — 返回当前路径 + 来源(env / pointer / default)+ 兜底提示 notice

UI(i18n 双语)

设置页数据目录卡片:来源标识、迁移失败 toast、更改位置按钮 + 重启确认 Modal。

验证

  • cargo check 零告警
  • 新增 7 个迁移单元测试(路径比较 / 递归复制 / 统计 / 迁移成功 / 拒绝非空目标 / 失败清理)
  • 全量测试 119 passed / 0 failed
  • npx tsc --noEmit 零错误
  • pnpm build 通过
  • tauri build 产出 exe / msi / nsis 三产物
  • 冒烟:DSH_LAUNCHER_DATA_HOME 指向临时目录启动,日志确认数据目录解析到该位置

附加

  • docs/ISSUE43_TASK_TREE.md:任务执行记录(6 阶段逐轮回填)。

yukitakasama and others added 8 commits September 12, 2026 14:59
…sue dsh-plugins#43)

- migrate.rs: bootstrap resolution chain (env DSH_LAUNCHER_DATA_HOME >
  pointer file data-home.txt > default app data dir), one-shot migration
  before the log handle opens: copy config/versions/homes/logs/.pnpm-store/
  tools/icons/bin -> verify -> switch -> snapshot old dir as .old-<ts>.
  Failure rolls back to the default dir and drops the pointer.
- AppState gains data_dir_source + data_dir_notice; commands pick_data_dir
  (blocking folder dialog), commit_data_dir (validate + write pointer),
  get_data_dir_source (path + source + fallback notice).
- lib.rs setup calls migrate::bootstrap before applog::init and
  ensure_local_node_on_path, so logs/ and tools/ move cleanly.
- 4 unit tests for paths_equal/dir_is_empty/copy_tree/tree_stats.
…sh-plugins#43)

- Settings.vue: data-dir card gains a 'Change location' button that opens
  the folder dialog (pick_data_dir), validates + writes the pending pointer
  file (commit_data_dir), then shows a restart hint modal; the card also
  displays the current source ('env' / 'pointer' / 'default') and surfaces
  the startup fallback notice as a toast.
- api/index.ts: pickDataDir / commitDataDir / getDataDirSource wired with
  browser-preview mock branches; types.ts adds DataDirInfo.
- i18n: zh-CN + en-US keys for moveTo/restartHint/migrating/migratedToast/
  source*/rollback/confirmMove.
…cords (issue dsh-plugins#43)

- copy_tree handles file sources (no create_dir_all on files) — fixes
  os error 267 when migrating config.json.
- New tests: migrate_data_dir_copies_and_clears_flag,
  migrate_data_dir_rejects_non_empty_target,
  migrate_data_dir_failure_removes_partial_target.
- Full suite: 119 passed; tauri build produced exe/msi/nsis bundles.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant