Skip to content

fix(storage): honor AVD paths and safely clean legacy snapshots - #118

Open
dwgx wants to merge 4 commits into
RoutineMiku:mainfrom
dwgx:fix/avd-path-and-snapshot-cleanup
Open

dwgx wants to merge 4 commits into
RoutineMiku:mainfrom
dwgx:fix/avd-path-and-snapshot-cleanup

Conversation

@dwgx

@dwgx dwgx commented Nov 21, 2026 •

Copy link
Copy Markdown

Problem

An explicit runtime.avdDir can be ignored when the runtime is inside DATA_DIR. The string-prefix containment check also treats a sibling such as DATA_DIR-old as a child.

Legacy emulator snapshots are offered by the leftovers scanner as generic directories, but the generic-directory cleaner requires an ApkStart.exe. A normal old snapshot therefore cannot be cleaned through that path. The UI also describes every skipped item as occupied and labels estimated file sizes as released disk space.

Changes

  • Give an explicit AVD directory precedence regardless of the runtime location. Use path semantics for containment; preserve the defaults when the setting is empty.
  • Introduce a dedicated snapshot item type. The main process supplies the authoritative AVD root; an item cannot supply its own cleanup root.
  • Restrict snapshot cleanup to recognized legacy names directly below apkstart.avd/snapshots. Preserve the current apkstart snapshot and unknown neighbours.
  • Validate the AVD root, intermediate directories and target using directory type and resolved-path checks. Refuse junctions, links, missing or unreadable metadata, and revalidate immediately before deletion.
  • Measure regular-file logical sizes before deletion, independently of the submitted estimate. Refuse nested links and measurement errors. Partial deletion failures and duplicate items cannot be counted as successful removals.
  • Describe cleanup candidates, logical size estimates and skipped reasons accurately in the UI. Empty results mean no automatic cleanup candidates; the confirmation now includes legacy snapshots.

For this change, a linked avdHome is intentionally skipped and preserved. This is a documented compatibility limit rather than an attempt to infer ownership through a configured link.

Validation

On Windows, the final head a74b74650e180f9b0b824b5d9592a4f96e510ebb passed:

  • node test/web-storage-test.js: 35 passed, including real TEMP junctions, normal cleanup, current/unknown snapshot preservation, ordinary-file rejection, scan-to-clean changes, measured bytes, partial deletion failure and duplicate accounting.

The preceding integration head 07f450f0dfe45f0410cb056a810df83403d09b59 passed the following acceptance checks. The final commit adds only the two failure/accounting tests; the product source is unchanged, so these earlier checks are reused:

  • node test/run-tests.js: 9 passed.
  • An unchanged independent four-case TEMP preservation probe: 4/4, with the tested failures preserved in the review evidence.
  • Two additional independent controls for partial deletion and duplicate accounting: 2/2; both were then added to the committed suite.
  • JavaScript syntax and git diff --check: exit 0.

The cleanup implementation is unchanged from the independently reviewed candidate cb1aea31be8074231dd5f072a2e2da68c719710d. The integrated branch adds the separately reviewed UI feedback and the two failure/accounting tests.

Cloud CI

The existing workflow passed on this exact head, a74b74650e180f9b0b824b5d9592a4f96e510ebb, in the contributor fork: Windows CI run 44880914393.

Both Windows / Node 20 and Node 22 jobs passed, including the full test command and the pointer-hook smoke test. The optional APK-fixture scenario self-skipped because no APK fixture was supplied; it is not counted as exercised.

The initial isolated local worktree could not finish npm test because @napi-rs/lzma was not installed there. That failure is retained in the review record; the clean cloud workflow installed dependencies and completed the chain.

Scope

This addresses explicit AVD path selection and legacy snapshot cleanup, and is related to #104. It does not establish that every disk-usage report under that issue is resolved.

The change does not add uninstall-time data wiping, migrate existing AVDs, purge the whole data/runtime directory or run a real installation. File-size totals are logical lengths, not measured physical disk space reclaimed. Revalidation before deletion does not claim atomic protection against every concurrent path replacement by another process.

dwgx added 4 commits November 21, 2026 16:23
- 显式非空 runtime.avdDir 现在无条件优先,包括运行时目录就是默认的 <DATA_DIR>/runtime 的情况。
- 空 avdDir 仍沿用原默认:运行时目录确实在 DATA_DIR 内 -> <runtime>/avd,否则 -> <DATA_DIR>/avd。
- 把 root.toLowerCase().startsWith(DATA_DIR) 换成 path.resolve + path.relative 判断,DATA_DIR-old 这种同前缀兄弟目录、跨盘路径、大小写差异都按路径语义处理。
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