[Feature] processledger 与 loginenv 仍手写固定 .tmp 文件改名写入,迁移到 atomicfile.Write
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read desktop/internal/atomicfile first to confirm the Write signature and its fsync/cleanup behaviour, then replace the hand-rolled temp-and-rename blocks in (*Ledger).write (desktop/internal/processledger/processledger.go, ~lines 228-241) and writeCache (desktop/internal/loginenv/loginenv_unix.go, ~lines 97-111). Decide how writeCache should report failures instead of swallowing them, then add tests showing no .tmp residue, preserved old contents on failure, and concurrent writers. Run go test ./desktop/internal/processledger/... ./desktop/internal/loginenv/... to verify; done means neither file calls os.Rename or builds a .tmp path itself.
Written by the indexing model from the issue text.
Description
Problem to solve / 要解决的问题
在完成 #2257 调查的 10 处 CreateTemp 原子替换迁移后,通过全仓库搜索 os.Rename( 与 .tmp 发现,桌面端还有两处预存的整文件原子写入未使用 desktop/internal/atomicfile,而是各自手写固定 .tmp 后缀文件再 os.Rename:
desktop/internal/processledger/processledger.go的(*Ledger).write(第 228–241 行):使用固定文件名l.path + ".tmp"调用os.WriteFile(temporary, data, 0o600)后直接os.Rename(temporary, l.path)。调用方为同文件第 130、153、197 行。desktop/internal/loginenv/loginenv_unix.go的writeCache(第 97–111 行):使用固定文件名path + ".tmp"调用os.WriteFile(temp, []byte(value+"\n"), 0o600)后os.Rename(temp, path)。调用方为同文件第 46、56 行。
判定依据:在 desktop/internal/ 下检索 os.Rename( 与 \.tmp(排除 *_test.go),核对全部单文件原子替换实现。保留现状的代价:
- 两处都使用固定
.tmp路径而非os.CreateTemp独占临时文件;多个 Lithe 实例并发启动或刷新登录环境/进程账本时可能互相覆盖同一临时文件。 - 两处都不在改名前
fsync;崩溃或断电后目标文件可能为空或半截(processledger.json损坏会导致孤儿进程无法识别与清理)。 (*Ledger).write在os.Rename失败时不清理l.path + ".tmp";writeCache静默丢弃MkdirAll/WriteFile/Rename的错误且无日志或豁免说明。
Proposed solution / 建议方案
将上述两处(均属于 Unix / !windows 启动辅助文件,目标为单文件原子替换)统一迁移到 desktop/internal/atomicfile.Write:
(*Ledger).write改为调用atomicfile.Write(l.path, data, 0o600),删除手写os.MkdirAll、l.path + ".tmp"与os.Rename。writeCache改为调用atomicfile.Write(path, []byte(value+"\n"), 0o600),并按统一日志规范决定失败时记录诊断或显式声明可丢弃原因,不再静默忽略错误。- 为两处补充并发/失败不留
.tmp及保留旧文件内容的单元测试。
Target platform / 目标平台
Cross-platform / 跨平台
Area / 模块
Other / 其他
Priority / 优先级
P2 / 后续考虑:目前不着急,可安排到后续版本
Alternatives considered / 已考虑的替代方案
各自原地把 path + ".tmp" 改成 os.CreateTemp 并补 Sync() 与清理逻辑。这样会再次复制 desktop/internal/atomicfile 已提供的能力,后续维护仍需分别修复。
Additional context / 补充信息
在审核 PR #2351(#2257)时通过全仓库检索 os.Rename( 与 \.tmp 发现,属于改动前既有代码,按开发规范第九节独立建单跟踪。涉及路径仅在 Unix(macOS 与 Linux)执行写入,processledger 在 Windows 为只读空实现,loginenv_unix.go 为 //go:build !windows。
Checklist / 提交前检查
- I searched existing issues for duplicates. / 我已搜索现有 Issue,确认没有重复建议。
- Dominant language
- TypeScript
- Stars
- 1.8k
- Forks
- 151
- Avg merge
- 4h 4m
- Merged PRs (30d)
- 558
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 1lck/Lithe-IDEA
-
bug issue-form:bug review: no-score
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
1lck/Lithe-IDEA#2373 · 1 comment ·
Maintainers usually reply within 1 day
-
area:ui enhancement P2 platform:cross-platform refactor review: high
Difficulty 1/5 Under an hour Newbie friendliness 84/100
1lck/Lithe-IDEA#2365 ·
Maintainers usually reply within 1 day
-
review: high
Difficulty 4/5 3-5 days Newbie friendliness 28/100
1lck/Lithe-IDEA#2381 ·
Maintainers usually reply within 1 day
-
review: high
Difficulty 3/5 1-2 days Newbie friendliness 35/100
1lck/Lithe-IDEA#2380 ·
Maintainers usually reply within 1 day
-
review: high
Difficulty 3/5 1-2 days Newbie friendliness 50/100
1lck/Lithe-IDEA#2379 ·
Maintainers usually reply within 1 day
Similar issues
-
chore
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
drydocs/meridian#1503 · 1 comment ·
Maintainers usually reply within 2 days
-
bug extension mcp
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
primer/primitives#1426 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
danielmiessler/LifeOS#2941 ·
Maintainers usually reply within 4 days
-
Sign-in-only setup dialog describes API-key verificationPossibly taken @roboclaw-bot claimed this today. Openclawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 1/5 Under an hour Newbie friendliness 78/100
openclaw/openclaw#204323 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day