fix: move CAS node files into nodes/ subdirectory (#84) #87
Reference in New Issue
Block a user
Delete Branch "fix/84-nodes-subdirectory"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Restructure the on-disk layout of
@ocas/fsFsStoreso that allcontent-addressed node files (
<HASH>.bin) are stored inside anodes/subdirectory of the store root, separated from store metadata.
Why
Previously,
.binnode files were written flat in the store rootalongside metadata directories (
_index/,_store.db,_meta).For stores with many nodes this made the root directory hard to
inspect and conflated user-visible data with internal bookkeeping.
Issue #84 calls for moving node files into a dedicated subdirectory
for a cleaner, more inspectable layout.
Changes
packages/fs/src/store.tsNODES_DIR = "nodes"constant.loadDir(),put(),putSelfReferencing(),delete()and atomic.tmpwrites all usejoin(dir, NODES_DIR, ...).createFsStore(dir): any.binfiles in thestore root are renamed into
nodes/before loading. Idempotent._index/,_store.db,_meta) remain at the store root.packages/fs/src/store.test.tsnodes/, round-trip,migration from flat layout, idempotency, delete path, metadata
location, and
_indexrebuild fromnodes/..changeset/nodes-subdirectory.md—@ocas/fsminor bump.Verification
pnpm run test— 631/631 tests passing across 36 filespnpm run check— biome lint cleanpnpm run build— builds cleanlyRef
Fixes #84
LGTM ✅
存储布局重构:
.bin文件从 store root 搬到nodes/子目录,metadata(_index/、_store.db、_meta)留在 root,职责分离清晰migrateFlatLayoutToNodes()放在createFsStore入口,先迁移再加载,时序正确renameSync而非 copy+delete,同文件系统下是原子操作,安全loadDir的 try/catch 兜住nodes/不存在的情况(全新 store),没遗漏测试覆盖完善: 14 个场景覆盖了新布局写入(A)、round-trip(B)、迁移(C,含幂等性)、删除路径(D)、metadata 位置不变(E)、index 重建(F),逻辑闭环。
Changeset
minor正确 — 存储布局变更虽然有自动迁移,但属于用户可感知的结构性改动。可以合。