[中] analysis.json 使用固定 .tmp 文件名,并发保存可能互相覆盖

Open Beginner friendly
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
desktop-dev

Research direction

Start at windows/birdlock/core/analysis.py around lines 231-237 (save_analysis() and its p.with_suffix(".tmp")), then read the callers in windows/birdlock/app/state.py at :506-513 and :955-962 to see which paths hold _analysis_save_lock and which do not. The fix is to create the temp file with tempfile.mkstemp(dir=p.parent) (mirroring how project saving already does it) and keep os.replace() for the swap. Done looks like two concurrent saves of the same fingerprint both producing valid analysis.json with no leftover shared .tmp file.

Written by the indexing model from the issue text.

Description

位置:windows/birdlock/core/analysis.py:231-237;windows/birdlock/app/state.py:955-962、:506-513

现象:save_analysis() 使用 p.with_suffix(".tmp");_save_analysis_now() 在后台线程写,move_group()、select_segment()、change_subject()、_finish_analysis() 也可能在主线程或分析线程调用,并不都持有 _analysis_save_lock。同一 fingerprint 的两个保存可能同时写同一个 .tmp,其中一个 os.replace() 失败或写出交错 JSON。

复现:在分析进行中快速拖动分组,观察 analysis.json 写入异常或损坏。

建议:在 save_analysis() 内部用 tempfile.mkstemp(dir=p.parent) 生成唯一临时文件(工程保存已是这样做的),或把锁下沉到该函数。

来源:2026-11-15 全仓只读审计,PR #7 未包含此项。 未在 Windows 实机复现,复现路径由代码审计推得。

Dominant language
Swift
Stars
2
Forks
2
Avg merge
1h 11m
Merged PRs (30d)
2

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cyandee/BirdLock

All issues in cyandee/BirdLock

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.