Commit cd2fbfd
authored
fix: replace node-persist with minimal in-repo file storage (#1125)
* fix: replace node-persist with minimal in-repo file storage
Implements the scope agreed in #1107: HAPFileStorage keeps node-persist
0.0.12's on-disk layout byte-for-byte and its four synchronous operations
(initSync, getItem, setItemSync, removeItemSync); everything else from the
removed node-persist API throws with a clear error. Drops the deprecated
q dependency along with node-persist, mkdirp@0.5 and the node-persist
build/type workarounds.
Claude-Session: https://claude.ai/code/session_01DpHuagGzRQVzatVmNiWa7p
* fix: clearer error for non-string storage path values
Claude-Session: https://claude.ai/code/session_01DpHuagGzRQVzatVmNiWa7p
* fix: address review feedback on HAPFileStorage
Use an optional catch binding for the unused error variable and clarify
the dir option documentation (absolute if provided, relative default).
Claude-Session: https://claude.ai/code/session_01DpHuagGzRQVzatVmNiWa7p
* fix: make storage writes atomic and ignore directories on load
Writes go to a temporary file which is renamed over the target, so an
interrupted write can no longer truncate a file holding pairing data.
Directories inside the storage directory are skipped when loading
instead of aborting startup with EISDIR.
Claude-Session: https://claude.ai/code/session_01DpHuagGzRQVzatVmNiWa7p
* test: cover parent directory creation for nested keys
Asserts the temporary file is written beside its target, which is what
keeps the replacing rename atomic.
* test: cover the default storage directory branch of HAPStorage
Every existing HAPStorage test sets a custom storage path, and jest.setup.ts
sets one on the singleton, so the branch which initialises into the default
"persist" directory was no longer executed by any test.
* fix: require storage keys to be a plain filename
A key was read as a path, so "nested/key.json" created a subdirectory and
"../escaped.json" wrote outside the storage directory. Since initSync now skips
directories, a nested key wrote successfully and then read back as undefined
after a restart, where node-persist 0.0.12 at least failed loudly with EISDIR.
Rejecting such keys makes the documented one-file-per-key layout an invariant.
Nothing in HAP-NodeJS uses a key containing a separator.
* fix: close three more ways a stored value could be lost silently
Keys starting with a dot are now rejected. initSync skips dotfiles, so
`.hidden` was written, served from memory while the process ran, and gone
after a restart: the same silent loss as a key naming a subdirectory,
reached from a different direction.
initSync now skips anything which is not a regular file, resolving
symlinks. A symlink pointing at a directory does not report as one to
readdir, so it reached readFileSync and aborted startup with the EISDIR
that check exists to prevent. A link to a file still loads.
The in-memory value is only replaced once the write reached the disk. A
failed write left memory holding a value which was not saved, and since
everything is served from memory that reads as an accessory which is
paired now and unpaired after a restart.1 parent 44f277e commit cd2fbfd
16 files changed
Lines changed: 619 additions & 134 deletions
File tree
- .github
- __mocks__
- src
- lib/model
- types
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| |||
0 commit comments