@openclaw/fs-safe 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +86 -0
- package/README.md +36 -7
- package/dist/absolute-path.d.ts.map +1 -1
- package/dist/absolute-path.js +2 -8
- package/dist/advanced.d.ts +3 -0
- package/dist/advanced.d.ts.map +1 -1
- package/dist/advanced.js +3 -0
- package/dist/archive-deadline.d.ts.map +1 -1
- package/dist/archive-deadline.js +22 -23
- package/dist/archive-kind.d.ts +0 -1
- package/dist/archive-kind.d.ts.map +1 -1
- package/dist/archive-kind.js +5 -17
- package/dist/archive-merge.d.ts +1 -0
- package/dist/archive-merge.d.ts.map +1 -1
- package/dist/archive-merge.js +4 -4
- package/dist/archive-native.d.ts +1 -0
- package/dist/archive-native.d.ts.map +1 -1
- package/dist/archive-native.js +1 -0
- package/dist/archive-options.d.ts +2 -0
- package/dist/archive-options.d.ts.map +1 -1
- package/dist/archive-parser.wasm +0 -0
- package/dist/archive-read.d.ts.map +1 -1
- package/dist/archive-read.js +6 -7
- package/dist/archive-tar-stream.d.ts +3 -0
- package/dist/archive-tar-stream.d.ts.map +1 -1
- package/dist/archive-tar-stream.js +56 -37
- package/dist/archive-tar-wasm.d.ts +16 -4
- package/dist/archive-tar-wasm.d.ts.map +1 -1
- package/dist/archive-tar-wasm.js +134 -34
- package/dist/archive-zip-count.d.ts.map +1 -1
- package/dist/archive-zip-count.js +21 -1
- package/dist/archive-zip-directory.d.ts.map +1 -1
- package/dist/archive-zip-directory.js +23 -1
- package/dist/archive-zip-loader.d.ts +2 -0
- package/dist/archive-zip-loader.d.ts.map +1 -1
- package/dist/archive-zip-loader.js +7 -0
- package/dist/archive-zip-names.d.ts.map +1 -1
- package/dist/archive-zip-names.js +7 -2
- package/dist/archive.d.ts.map +1 -1
- package/dist/archive.js +14 -9
- package/dist/byte-view.d.ts +3 -0
- package/dist/byte-view.d.ts.map +1 -0
- package/dist/byte-view.js +13 -0
- package/dist/clone-metadata.d.ts +1 -0
- package/dist/clone-metadata.d.ts.map +1 -1
- package/dist/clone-metadata.js +6 -2
- package/dist/create-directory.d.ts +20 -0
- package/dist/create-directory.d.ts.map +1 -0
- package/dist/create-directory.js +130 -0
- package/dist/create-file-async.d.ts +7 -0
- package/dist/create-file-async.d.ts.map +1 -0
- package/dist/create-file-async.js +121 -0
- package/dist/create-file.d.ts +8 -0
- package/dist/create-file.d.ts.map +1 -0
- package/dist/create-file.js +190 -0
- package/dist/create-owned-file.d.ts +8 -0
- package/dist/create-owned-file.d.ts.map +1 -0
- package/dist/create-owned-file.js +16 -0
- package/dist/create.d.ts +4 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +2 -0
- package/dist/creation-darwin.d.ts +6 -0
- package/dist/creation-darwin.d.ts.map +1 -0
- package/dist/creation-darwin.js +70 -0
- package/dist/creation-file-state.d.ts +19 -0
- package/dist/creation-file-state.d.ts.map +1 -0
- package/dist/creation-file-state.js +118 -0
- package/dist/creation-path.d.ts +21 -0
- package/dist/creation-path.d.ts.map +1 -0
- package/dist/creation-path.js +71 -0
- package/dist/creation-permissions.d.ts +19 -0
- package/dist/creation-permissions.d.ts.map +1 -0
- package/dist/creation-permissions.js +125 -0
- package/dist/directory-durability.d.ts +7 -7
- package/dist/directory-durability.d.ts.map +1 -1
- package/dist/directory-durability.js +22 -80
- package/dist/directory-guard.d.ts +3 -0
- package/dist/directory-guard.d.ts.map +1 -1
- package/dist/directory-mode-node.d.ts +2 -0
- package/dist/directory-mode-node.d.ts.map +1 -1
- package/dist/directory-mode-node.js +8 -0
- package/dist/directory-receipt.d.ts +24 -0
- package/dist/directory-receipt.d.ts.map +1 -0
- package/dist/directory-receipt.js +123 -0
- package/dist/file-cleanup.d.ts +20 -0
- package/dist/file-cleanup.d.ts.map +1 -0
- package/dist/file-cleanup.js +81 -0
- package/dist/file-contents.d.ts +6 -0
- package/dist/file-contents.d.ts.map +1 -0
- package/dist/file-contents.js +40 -0
- package/dist/file-hash.d.ts.map +1 -1
- package/dist/file-hash.js +16 -4
- package/dist/file-lock-sync-root-acquire.d.ts.map +1 -1
- package/dist/file-lock-sync-root-acquire.js +3 -0
- package/dist/file-lock-sync-root-held.d.ts +1 -2
- package/dist/file-lock-sync-root-held.d.ts.map +1 -1
- package/dist/file-lock-sync-root-held.js +7 -5
- package/dist/file-lock-sync-stale-admission.d.ts.map +1 -1
- package/dist/file-lock-sync-stale-admission.js +3 -0
- package/dist/file-lock-sync.d.ts.map +1 -1
- package/dist/file-lock-sync.js +8 -11
- package/dist/file-observation.d.ts +1 -1
- package/dist/file-observation.d.ts.map +1 -1
- package/dist/file-store-boundary.d.ts +2 -6
- package/dist/file-store-boundary.d.ts.map +1 -1
- package/dist/file-store-boundary.js +3 -9
- package/dist/file-store-sync-write.d.ts.map +1 -1
- package/dist/file-store-sync-write.js +2 -5
- package/dist/file-store.js +3 -3
- package/dist/guarded-mkdir.d.ts +1 -0
- package/dist/guarded-mkdir.d.ts.map +1 -1
- package/dist/guarded-mkdir.js +27 -19
- package/dist/install-path.d.ts.map +1 -1
- package/dist/install-path.js +2 -5
- package/dist/json-durable-queue-ownership.d.ts.map +1 -1
- package/dist/json-durable-queue-ownership.js +2 -6
- package/dist/json-durable-queue-paths.d.ts.map +1 -1
- package/dist/json-durable-queue-paths.js +2 -24
- package/dist/json-durable-queue.d.ts.map +1 -1
- package/dist/json-durable-queue.js +10 -9
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +32 -75
- package/dist/local-roots.d.ts.map +1 -1
- package/dist/local-roots.js +19 -21
- package/dist/move-path-cleanup.d.ts +5 -19
- package/dist/move-path-cleanup.d.ts.map +1 -1
- package/dist/move-path-cleanup.js +57 -21
- package/dist/move-path.d.ts.map +1 -1
- package/dist/move-path.js +63 -40
- package/dist/native-binding.d.ts +11 -1
- package/dist/native-binding.d.ts.map +1 -1
- package/dist/native-fallback-warning.d.ts +4 -0
- package/dist/native-fallback-warning.d.ts.map +1 -0
- package/dist/native-fallback-warning.js +11 -0
- package/dist/native-operations.d.ts +0 -2
- package/dist/native-operations.d.ts.map +1 -1
- package/dist/native-operations.js +0 -24
- package/dist/native-parent-admission.d.ts +2 -0
- package/dist/native-parent-admission.d.ts.map +1 -1
- package/dist/native-parent-admission.js +3 -2
- package/dist/native-pinned-write-windows.d.ts +1 -1
- package/dist/native-pinned-write-windows.d.ts.map +1 -1
- package/dist/native-pinned-write-windows.js +173 -28
- package/dist/native-pinned-write.d.ts.map +1 -1
- package/dist/native-pinned-write.js +19 -3
- package/dist/native-policy-parent-windows.d.ts.map +1 -1
- package/dist/native-policy-parent-windows.js +15 -6
- package/dist/native-staged-file.d.ts +5 -3
- package/dist/native-staged-file.d.ts.map +1 -1
- package/dist/native-staged-file.js +90 -40
- package/dist/native.js +2 -2
- package/dist/opened-realpath.d.ts.map +1 -1
- package/dist/opened-realpath.js +11 -2
- package/dist/owner-dacl.d.ts.map +1 -1
- package/dist/owner-dacl.js +10 -4
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +2 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +3 -17
- package/dist/pinned-write-input.d.ts +4 -0
- package/dist/pinned-write-input.d.ts.map +1 -0
- package/dist/pinned-write-input.js +35 -0
- package/dist/pinned-write-mode.d.ts +5 -0
- package/dist/pinned-write-mode.d.ts.map +1 -0
- package/dist/pinned-write-mode.js +31 -0
- package/dist/pinned-write-staged.d.ts +6 -0
- package/dist/pinned-write-staged.d.ts.map +1 -0
- package/dist/pinned-write-staged.js +186 -0
- package/dist/pinned-write-types.d.ts +3 -0
- package/dist/pinned-write-types.d.ts.map +1 -1
- package/dist/pinned-write.d.ts.map +1 -1
- package/dist/pinned-write.js +41 -147
- package/dist/private-directory.d.ts.map +1 -1
- package/dist/private-directory.js +18 -4
- package/dist/private-producer-handoff-sync.d.ts +14 -0
- package/dist/private-producer-handoff-sync.d.ts.map +1 -0
- package/dist/private-producer-handoff-sync.js +114 -0
- package/dist/private-producer-handoff.d.ts +22 -4
- package/dist/private-producer-handoff.d.ts.map +1 -1
- package/dist/private-producer-handoff.js +140 -77
- package/dist/publish-copy-stage.d.ts +2 -1
- package/dist/publish-copy-stage.d.ts.map +1 -1
- package/dist/publish-copy-stage.js +16 -7
- package/dist/publish-file.d.ts +2 -2
- package/dist/publish-file.d.ts.map +1 -1
- package/dist/publish-file.js +58 -98
- package/dist/regular-file.d.ts.map +1 -1
- package/dist/regular-file.js +35 -44
- package/dist/replace-file-copy-fallback.d.ts.map +1 -1
- package/dist/replace-file-copy-fallback.js +28 -26
- package/dist/replace-file-copy-source.d.ts.map +1 -1
- package/dist/replace-file-copy-source.js +13 -22
- package/dist/replace-file-descriptor.d.ts.map +1 -1
- package/dist/replace-file-descriptor.js +10 -16
- package/dist/replace-file-temp-owner.d.ts +0 -7
- package/dist/replace-file-temp-owner.d.ts.map +1 -1
- package/dist/replace-file-temp-owner.js +9 -60
- package/dist/replace-file.d.ts.map +1 -1
- package/dist/replace-file.js +9 -13
- package/dist/root-create-input.d.ts +2 -1
- package/dist/root-create-input.d.ts.map +1 -1
- package/dist/root-create-input.js +13 -4
- package/dist/root-directory-creation.d.ts +3 -3
- package/dist/root-directory-creation.d.ts.map +1 -1
- package/dist/root-directory-creation.js +15 -3
- package/dist/root-directory-list.d.ts.map +1 -1
- package/dist/root-directory-list.js +20 -3
- package/dist/root-file-final-admission.d.ts +1 -1
- package/dist/root-file-final-admission.d.ts.map +1 -1
- package/dist/root-file-final-admission.js +5 -2
- package/dist/root-file.d.ts.map +1 -1
- package/dist/root-file.js +3 -2
- package/dist/root-impl.d.ts.map +1 -1
- package/dist/root-impl.js +78 -27
- package/dist/root-move-noreplace.d.ts +2 -0
- package/dist/root-move-noreplace.d.ts.map +1 -1
- package/dist/root-move-noreplace.js +22 -13
- package/dist/root-options.d.ts +12 -4
- package/dist/root-options.d.ts.map +1 -1
- package/dist/root-path-stat.d.ts.map +1 -1
- package/dist/root-path-stat.js +59 -7
- package/dist/root-read-admission.d.ts.map +1 -1
- package/dist/root-read-admission.js +7 -2
- package/dist/root-remove.d.ts.map +1 -1
- package/dist/root-remove.js +15 -1
- package/dist/root-write-publication.js +1 -1
- package/dist/secret-file.d.ts.map +1 -1
- package/dist/secret-file.js +1 -0
- package/dist/secure-file-windows.d.ts +6 -0
- package/dist/secure-file-windows.d.ts.map +1 -1
- package/dist/secure-file-windows.js +34 -117
- package/dist/secure-file.js +2 -2
- package/dist/sidecar-lock-acquire.d.ts.map +1 -1
- package/dist/sidecar-lock-acquire.js +4 -6
- package/dist/sidecar-lock-handle.d.ts +3 -0
- package/dist/sidecar-lock-handle.d.ts.map +1 -1
- package/dist/sidecar-lock-handle.js +6 -0
- package/dist/sidecar-lock-reclaim.d.ts +1 -1
- package/dist/sidecar-lock-reclaim.d.ts.map +1 -1
- package/dist/sidecar-lock-reclaim.js +11 -8
- package/dist/sidecar-lock-root.d.ts.map +1 -1
- package/dist/sidecar-lock-root.js +2 -1
- package/dist/sidecar-lock.d.ts.map +1 -1
- package/dist/sidecar-lock.js +3 -5
- package/dist/staged-directory.d.ts +2 -2
- package/dist/staged-directory.d.ts.map +1 -1
- package/dist/staged-directory.js +6 -6
- package/dist/staged-file-settlement.d.ts +17 -0
- package/dist/staged-file-settlement.d.ts.map +1 -0
- package/dist/staged-file-settlement.js +57 -0
- package/dist/strict-file-identity.d.ts +1 -1
- package/dist/strict-file-identity.d.ts.map +1 -1
- package/dist/strict-file-identity.js +9 -9
- package/dist/symlink-parents.d.ts.map +1 -1
- package/dist/symlink-parents.js +2 -27
- package/dist/temp-workspace-owner.js +4 -4
- package/dist/unicode-path.d.ts.map +1 -1
- package/dist/unicode-path.js +3 -0
- package/dist/walk.d.ts.map +1 -1
- package/dist/walk.js +4 -2
- package/dist/windows-owner.d.ts.map +1 -1
- package/dist/windows-owner.js +2 -1
- package/dist/windows-security-bridge.cs +336 -0
- package/dist/windows-security-bridge.ps1 +15 -0
- package/dist/windows-security-command.d.ts +26 -0
- package/dist/windows-security-command.d.ts.map +1 -0
- package/dist/windows-security-command.js +363 -0
- package/dist/windows-security-facts.d.ts +6 -0
- package/dist/windows-security-facts.d.ts.map +1 -0
- package/dist/windows-security-facts.js +108 -0
- package/dist/write-file-handle.d.ts +7 -0
- package/dist/write-file-handle.d.ts.map +1 -1
- package/dist/write-file-handle.js +23 -0
- package/dist/write-open-flags.d.ts.map +1 -1
- package/dist/write-open-flags.js +1 -8
- package/dist/write-queue.d.ts.map +1 -1
- package/dist/write-queue.js +1 -4
- package/docs/advanced.md +71 -2
- package/docs/archive.md +102 -39
- package/docs/atomic.md +29 -5
- package/docs/config.md +6 -2
- package/docs/contributing.md +48 -4
- package/docs/copy.md +2 -0
- package/docs/creation.md +132 -0
- package/docs/durability.md +59 -0
- package/docs/file-contents.md +68 -0
- package/docs/install.md +31 -7
- package/docs/json.md +5 -4
- package/docs/local-roots.md +2 -0
- package/docs/migrating-to-0.5.md +15 -6
- package/docs/migrating-to-0.6.md +9 -4
- package/docs/mutation-policy-proof.md +5 -3
- package/docs/native-helper.md +22 -9
- package/docs/native.md +47 -15
- package/docs/path.md +4 -4
- package/docs/permissions.md +37 -14
- package/docs/public-api.md +5 -0
- package/docs/quickstart.md +1 -1
- package/docs/reading.md +2 -2
- package/docs/regular-file.md +3 -0
- package/docs/root.md +43 -0
- package/docs/secret-file.md +11 -2
- package/docs/secure-file.md +9 -4
- package/docs/sidecar-lock.md +14 -5
- package/docs/staged-file.md +9 -3
- package/docs/store.md +3 -1
- package/docs/temp.md +4 -1
- package/docs/types.md +18 -2
- package/docs/walk.md +7 -0
- package/docs/writing.md +80 -7
- package/package.json +18 -15
package/docs/creation.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Exclusive leaf creation
|
|
2
|
+
|
|
3
|
+
The creation-policy work is tracked in [#482](https://github.com/openclaw/fs-safe/issues/482).
|
|
4
|
+
|
|
5
|
+
Use `createDirectory()`, `createDirectorySync()`, and `createFileSync()` from
|
|
6
|
+
`@openclaw/fs-safe/advanced` when an existing, trusted parent should receive
|
|
7
|
+
one new entry. These operations are exclusive and nonrecursive: an existing
|
|
8
|
+
entry throws `FsSafeError("already-exists")`, and missing parents are not
|
|
9
|
+
created. They do not repair or adopt an existing destination. `Root.mkdir()`
|
|
10
|
+
continues to own recursive, idempotent directory creation within a Root.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import {
|
|
14
|
+
createDirectorySync,
|
|
15
|
+
createFileSync,
|
|
16
|
+
} from "@openclaw/fs-safe/advanced";
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
|
|
19
|
+
createDirectorySync("/trusted/application/new-state", { private: true });
|
|
20
|
+
using file = createFileSync("/trusted/application/new-state/initial.db", {
|
|
21
|
+
private: true,
|
|
22
|
+
});
|
|
23
|
+
fs.fsyncSync(file.fd);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Both directory variants return `void`; `createFileSync()` returns an empty,
|
|
27
|
+
read/write descriptor owned by `OwnedFileDescriptorSync`, with
|
|
28
|
+
`{ fd, close(), [Symbol.dispose]() }`. Use the
|
|
29
|
+
owner to close it, rather than calling `fs.closeSync()` yourself. Closing and
|
|
30
|
+
disposal are idempotent; a failed close is not retried through a descriptor
|
|
31
|
+
number that might already have been reused. File creation does not write
|
|
32
|
+
payload data or request file or parent-directory synchronization.
|
|
33
|
+
|
|
34
|
+
## Permission options
|
|
35
|
+
|
|
36
|
+
`CreateDirectoryOptions` and `CreateFileOptions` both support `private?: boolean`
|
|
37
|
+
for private creation. `mode?: number` selects permission
|
|
38
|
+
bits; invalid values and private requests with group/world or special bits
|
|
39
|
+
reject before mutation. Restrictive owner-only modes remain restrictive.
|
|
40
|
+
Without `private`, ordinary Node defaults and the process umask apply. Private
|
|
41
|
+
POSIX creation requests `0700` for directories and `0600` for files by default;
|
|
42
|
+
the umask may restrict those permissions further. Existing directory privacy
|
|
43
|
+
checks never broaden permissions.
|
|
44
|
+
|
|
45
|
+
Private POSIX `Root.create()` and `createJson()` writes check the retained descriptor's actual owner and
|
|
46
|
+
permissions before writing payload bytes, after producer and authority callbacks,
|
|
47
|
+
and at publication, including JavaScript fallback writes. Payload writes require
|
|
48
|
+
the temporary `0600` mode even when the requested final mode differs.
|
|
49
|
+
Private ownership, permissions and ACLs are checked before preparing that mode,
|
|
50
|
+
including after authority callbacks; valid restrictive initial modes remain supported.
|
|
51
|
+
A successful `chmod` is insufficient: filesystems that do not
|
|
52
|
+
enforce owner-only permissions reject before payload writes. The requested final
|
|
53
|
+
mode is verified too; a failure after publication preserves the completed file
|
|
54
|
+
and staged creation reports its published outcome.
|
|
55
|
+
|
|
56
|
+
On macOS (Darwin), private creation also requires an ACL-free result. The native
|
|
57
|
+
helper must provide `inspectDarwinAcl`; native `off`, a missing helper, or an
|
|
58
|
+
older helper without that capability rejects with `helper-unavailable` before
|
|
59
|
+
creating parents or staging entries. There is no system-command fallback for
|
|
60
|
+
Darwin private creation. Operations without `private: true` keep their existing
|
|
61
|
+
native-mode behavior.
|
|
62
|
+
|
|
63
|
+
Private Darwin directories must retain owner-read or owner-search permission
|
|
64
|
+
after applying the umask so their ACL can be inspected. Modes `0000` and `0200`
|
|
65
|
+
reject with `helper-unavailable` before directory creation. Existing private
|
|
66
|
+
directories with neither permission also reject with `helper-unavailable`;
|
|
67
|
+
permissions are never broadened to inspect them. Modes `0100`, `0300`, and `0400`
|
|
68
|
+
remain supported, as does the default `0700`. Private files with mode `0000`
|
|
69
|
+
remain supported because inspection uses the owned creation descriptor.
|
|
70
|
+
|
|
71
|
+
Before creation, the parent ACL is inspected for entries that could be inherited
|
|
72
|
+
by the new directory or file, as applicable. Relevant inheritable entries reject
|
|
73
|
+
creation. Noninheriting parent ACLs, such as the usual macOS home-directory
|
|
74
|
+
deny-delete entry, do not reject child creation. Created directories and files
|
|
75
|
+
are checked for owner-only permissions and no ACL before admitting the directory
|
|
76
|
+
or allowing payload writes. An existing directory requested with `private: true`
|
|
77
|
+
must also be owned by the current user, have owner-only permissions, and have no
|
|
78
|
+
ACL. These checks never clear an ACL after creation or repair an existing entry.
|
|
79
|
+
|
|
80
|
+
On Windows, mode bits alone do not establish privacy. Private creation uses a
|
|
81
|
+
protected current-user, LocalSystem and Administrators DACL. A private staging
|
|
82
|
+
directory supplies trusted-only inheritable permissions before Node creates
|
|
83
|
+
the file. The original Node descriptor stays pinned while its full Windows
|
|
84
|
+
identity is compared with a security handle before the file DACL is protected.
|
|
85
|
+
An already broadly accessible file is rejected, not repaired. Keep the trusted
|
|
86
|
+
parent ancestry and staging directory ACL protected from untrusted changes;
|
|
87
|
+
post-operation checks do not make pathname-based fallback operations atomic
|
|
88
|
+
against an adversary who can change that namespace.
|
|
89
|
+
|
|
90
|
+
The internal async writer awaits system commands, file opens and closes, and
|
|
91
|
+
security verification. It does not wrap the synchronous creator in a promise.
|
|
92
|
+
Short identity checks and the existing guarded link/unlink critical sections
|
|
93
|
+
remain synchronous.
|
|
94
|
+
|
|
95
|
+
Private Windows file publication retains the same inode and never overwrites
|
|
96
|
+
an existing destination. The current implementation requires hardlinks on the same
|
|
97
|
+
local filesystem. Unsupported filesystems reject with `helper-unavailable`;
|
|
98
|
+
there is no copy-to-destination fallback. On Windows the owner overlaps a
|
|
99
|
+
verified destination descriptor with the creation descriptor before removing
|
|
100
|
+
the temporary name. Requested read-only attributes are finalized through the
|
|
101
|
+
retained destination descriptor after that handoff.
|
|
102
|
+
|
|
103
|
+
On Windows, native `auto` uses available capabilities; native `off` and
|
|
104
|
+
missing-capability `auto` use the packaged system-command security bridge. Native `require`
|
|
105
|
+
rejects unavailable required capabilities instead of starting a command. The
|
|
106
|
+
private-file capability check runs before creating parents or staging entries;
|
|
107
|
+
directory-only operations require only their directory capabilities. The
|
|
108
|
+
[Windows security fallback prerequisites](install.md#windows-security-fallback)
|
|
109
|
+
apply. All command mutations report unconfirmed outcomes when their reply or
|
|
110
|
+
termination cannot establish completion.
|
|
111
|
+
|
|
112
|
+
## Authority and failure outcomes
|
|
113
|
+
|
|
114
|
+
`assertBeforeMutation?: () => void` is a synchronous current-authority check.
|
|
115
|
+
It runs after preparation and immediately before creation or publication;
|
|
116
|
+
thenables reject before mutation. Parent and file identity checks are repeated
|
|
117
|
+
after the callback. Final permission checks, descriptor settlement and cleanup
|
|
118
|
+
retain the operation's cleanup ownership after publication.
|
|
119
|
+
|
|
120
|
+
Failure does not always mean the final path is absent. Staged private-file errors
|
|
121
|
+
after publication or ambiguous publication preserve the destination and carry
|
|
122
|
+
`details.publication.status` (`published` or `indeterminate`), the target path and
|
|
123
|
+
staging cleanup outcome. Cleanup and close failures retain the original error
|
|
124
|
+
in the cause chain. When `stageDirectory` is present, `cleanup` describes that
|
|
125
|
+
stage's settlement; it does not mean the published destination was removed.
|
|
126
|
+
If a directory is created but its subsequent admission fails, the error records
|
|
127
|
+
its published path and preserves it. A private file whose staging directory
|
|
128
|
+
cannot be admitted reports `not-published` and identifies the preserved stage.
|
|
129
|
+
Observed replacement paths are preserved. Existing
|
|
130
|
+
`createPrivateDirectory()` retains its Windows-only compatibility contract;
|
|
131
|
+
new portable callers should use the ordinary creation operations with
|
|
132
|
+
`private: true`.
|
package/docs/durability.md
CHANGED
|
@@ -69,6 +69,49 @@ descriptor, pathname identity, and canonical path. `assertCurrent()` repeats
|
|
|
69
69
|
those checks. This prevents a pathname replacement from turning a later sync
|
|
70
70
|
into proof for a different directory.
|
|
71
71
|
|
|
72
|
+
Pathname and descriptor checks compare exact bigint device and inode values.
|
|
73
|
+
Each inspection allows one retry for unknown Windows identity components,
|
|
74
|
+
retaining known components and rejecting definite mismatches immediately.
|
|
75
|
+
Persistent unknown identity fails closed with `path-mismatch`, including on an
|
|
76
|
+
otherwise usable directory. A failed preflight identity check never syncs the
|
|
77
|
+
descriptor; a replacement discovered after sync still rejects the operation.
|
|
78
|
+
|
|
79
|
+
`DirectoryReceipt.identity` remains a numeric Node `Stats` object for metadata
|
|
80
|
+
compatibility, projected from the same exact observation as the private
|
|
81
|
+
identity. Library-created receipts and their identity objects retain a
|
|
82
|
+
private exact snapshot; mutating their public fields cannot change the
|
|
83
|
+
directory authorized by that snapshot. Each returned receipt owns a mutable
|
|
84
|
+
numeric metadata copy. Later admissions retain the original metadata snapshot
|
|
85
|
+
even if advisory fields such as mode or timestamps were edited; changed paths
|
|
86
|
+
or identity components reject. Pass the receipt or its original
|
|
87
|
+
identity object through to later operations to retain this evidence. A copied
|
|
88
|
+
or reconstructed numeric identity is accepted only when both components are
|
|
89
|
+
safe integers and, on Windows, nonzero. Rounded or unknown caller identities
|
|
90
|
+
fail with `path-mismatch` rather than authorizing a different directory.
|
|
91
|
+
|
|
92
|
+
Caller-supplied receipts may use `DirectoryReceipt<BigIntStats>` with the result
|
|
93
|
+
of `lstat(path, { bigint: true })`. `pinDirectory()`, `syncDirectory()`,
|
|
94
|
+
`syncDirectorySync()`, `publishFileExclusive()`'s `parentReceipt`, and
|
|
95
|
+
`stageFileInDirectory()` accept both numeric and bigint receipt inputs.
|
|
96
|
+
`DirectoryReceipt` without a type argument and all returned durability receipts
|
|
97
|
+
still expose numeric `Stats`, including working type predicates and Date
|
|
98
|
+
properties. Bigint metadata is projected from the supplied observation, retaining
|
|
99
|
+
fractional timestamps and the private exact device/inode identity.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { lstatSync, realpathSync, type BigIntStats } from "node:fs";
|
|
103
|
+
import { syncDirectorySync, type DirectoryReceipt } from "@openclaw/fs-safe/durability";
|
|
104
|
+
|
|
105
|
+
const directoryPath = "/srv/backups/sqlite";
|
|
106
|
+
const receipt: DirectoryReceipt<BigIntStats> = {
|
|
107
|
+
path: directoryPath,
|
|
108
|
+
realPath: realpathSync(directoryPath),
|
|
109
|
+
identity: lstatSync(directoryPath, { bigint: true }),
|
|
110
|
+
};
|
|
111
|
+
// Keep this receipt across the application's publication operation.
|
|
112
|
+
const outcome = syncDirectorySync(receipt);
|
|
113
|
+
```
|
|
114
|
+
|
|
72
115
|
Call `close()` in `finally`. Closing is idempotent; using a closed pin fails.
|
|
73
116
|
|
|
74
117
|
These checks intentionally reject a moved or replaced pathname. For one file's
|
|
@@ -94,6 +137,10 @@ accepted.
|
|
|
94
137
|
`expectedExistingIdentity` binds an existing target to an identity observed by
|
|
95
138
|
the caller before a separate permission or policy check. A missing or replaced
|
|
96
139
|
target fails with `FsSafeError("path-mismatch")`.
|
|
140
|
+
Use bigint `dev` and `ino` from `lstat(path, { bigint: true })` or
|
|
141
|
+
[`readDirectoryIdentity()`](directory-identity.md) for caller-owned observations
|
|
142
|
+
that may exceed the numeric safe-integer range. An original library receipt's
|
|
143
|
+
`identity` object also retains its private exact identity for this option.
|
|
97
144
|
|
|
98
145
|
## Exclusive file publication
|
|
99
146
|
|
|
@@ -252,6 +299,11 @@ pathname without reopening the file and repeat the symlink and file-type checks.
|
|
|
252
299
|
POSIX opens are nonblocking, so a raced FIFO or device is rejected after
|
|
253
300
|
descriptor inspection rather than waiting for a writer.
|
|
254
301
|
|
|
302
|
+
A pathname hash reports failure to close its owned descriptor after successful
|
|
303
|
+
hashing. If hashing, admission, or cancellation already failed, that original
|
|
304
|
+
failure remains primary even when close also fails. This also applies to
|
|
305
|
+
`sha256FileSync()`; borrowed handles and descriptors remain caller-owned.
|
|
306
|
+
|
|
255
307
|
When the optional binding is active, hashing runs as an async native task and
|
|
256
308
|
does not occupy the JavaScript event loop with digest updates. With native mode
|
|
257
309
|
`off`, or in `auto` when no binding loads, the fallback performs asynchronous
|
|
@@ -323,6 +375,13 @@ this receipt instead of inferring ownership from path existence. The original
|
|
|
323
375
|
failure remains available as `cause`. Failures before target creation retain
|
|
324
376
|
their existing error shape and do not claim a cleanup result.
|
|
325
377
|
|
|
378
|
+
Source and target identities are checked again after successful or unsupported
|
|
379
|
+
directory synchronization, while their descriptors remain owned. A late
|
|
380
|
+
verification failure retains its strategy's verification phase and is not a
|
|
381
|
+
directory-sync failure. Completed copied targets stay pinned during conditional
|
|
382
|
+
cleanup; substituted entries remain untouched. Returned numeric metadata comes
|
|
383
|
+
from the retained target descriptor and grants no continuing pathname authority.
|
|
384
|
+
|
|
326
385
|
### Directory-sync failure policy
|
|
327
386
|
|
|
328
387
|
`onSyncFailure` applies only after target creation and content/identity fencing
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Exact file comparison
|
|
2
|
+
|
|
3
|
+
`sameFileContentsSync()` compares the bytes of two already-open regular files,
|
|
4
|
+
starting at offset zero. It uses bounded buffers and completes positive short
|
|
5
|
+
reads independently on each descriptor. A `true` result requires matching bytes
|
|
6
|
+
and observed EOF on both inputs; a difference can return `false` immediately.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import { sameFileContentsSync } from "@openclaw/fs-safe/advanced";
|
|
11
|
+
|
|
12
|
+
const source = fs.openSync("/trusted/source.sqlite", "r");
|
|
13
|
+
try {
|
|
14
|
+
const copy = fs.openSync("/trusted/copy.sqlite", "r");
|
|
15
|
+
try {
|
|
16
|
+
console.log(sameFileContentsSync(source, copy, { maxBytes: 256 * 1024 * 1024 }));
|
|
17
|
+
} finally {
|
|
18
|
+
fs.closeSync(copy);
|
|
19
|
+
}
|
|
20
|
+
} finally {
|
|
21
|
+
fs.closeSync(source);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Signature
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
type SameFileContentsOptions = { maxBytes?: number };
|
|
29
|
+
|
|
30
|
+
function sameFileContentsSync(
|
|
31
|
+
leftFd: number,
|
|
32
|
+
rightFd: number,
|
|
33
|
+
options?: SameFileContentsOptions,
|
|
34
|
+
): boolean;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Both descriptors must be open regular files. Nonregular inputs throw
|
|
38
|
+
`FsSafeError("not-file")`; underlying filesystem errors propagate unchanged.
|
|
39
|
+
Passing the same descriptor twice is allowed, but does not bypass validation,
|
|
40
|
+
the byte limit, or reads. File sizes are checked against the limit, but are not
|
|
41
|
+
used as proof that contents match or that EOF has been reached.
|
|
42
|
+
|
|
43
|
+
## Bounds and ownership
|
|
44
|
+
|
|
45
|
+
`maxBytes` is a limit for each file, not their combined size. It accepts a
|
|
46
|
+
non-negative safe integer or `Infinity`; omission imposes no caller-selected
|
|
47
|
+
limit. Invalid limits throw `RangeError` before filesystem work. Comparisons
|
|
48
|
+
cannot exceed `Number.MAX_SAFE_INTEGER` bytes because positions must remain
|
|
49
|
+
exactly representable.
|
|
50
|
+
|
|
51
|
+
A reported file size above the limit throws `FsSafeError("too-large")` before
|
|
52
|
+
reading. At the limit, the comparison reads at most one additional byte from
|
|
53
|
+
each input to prove EOF; any observed overflow throws the same error. A
|
|
54
|
+
matching prefix is never reported as complete equality. An early mismatch
|
|
55
|
+
does not scan the remaining bytes or promise to detect later errors or growth.
|
|
56
|
+
A zero-byte limit admits two empty files. Memory use is at most two 1 MiB
|
|
57
|
+
payload buffers, regardless of file size.
|
|
58
|
+
|
|
59
|
+
The operation neither changes the descriptors' current offsets nor closes
|
|
60
|
+
them, including on failure. It performs no writes, hashing, pathname lookup,
|
|
61
|
+
or identity comparison. Callers retain path admission, hardlink policy,
|
|
62
|
+
descriptor lifetime, and any before/after mutation-fingerprint checks. A
|
|
63
|
+
comparison is not a snapshot of concurrently modified files; applications
|
|
64
|
+
requiring stable contents must retain their existing coordination and checks.
|
|
65
|
+
|
|
66
|
+
Use [`readFileWindowFullySync()`](positional-read.md) for a selected byte
|
|
67
|
+
window and [bounded descriptor reads](advanced.md#files-and-identity) when the
|
|
68
|
+
caller needs the file contents in memory.
|
package/docs/install.md
CHANGED
|
@@ -119,22 +119,46 @@ Use the main entry for the common surface, or the focused subpaths when you want
|
|
|
119
119
|
|
|
120
120
|
## Runtime dependencies
|
|
121
121
|
|
|
122
|
-
`@openclaw/fs-safe` bundles an import-free WASM build of its Rust TAR parser for guarded
|
|
122
|
+
`@openclaw/fs-safe` bundles an import-free WASM build of its Rust TAR parser and zstd/bzip2 codecs for guarded [archive extraction and bounded entry reads](archive.md). Plain TAR, gzip, zstd, and bzip2 work in `off` and missing-native `auto`, including installs with all optional dependencies omitted; gzip uses Node's built-in decoder. These archive fallbacks need no runtime interpreter, download, or consumer compiler. ZIP fallback uses lazily loaded optional `jszip` and reports a missing-dependency error without it. Public subpaths remain safe to import with all optional dependencies omitted, but imports do not prove native availability. Native `require` remains strict, and an available native operation's failure never triggers a WASM retry.
|
|
123
123
|
|
|
124
124
|
There are no peer dependencies. Exact-version optional packages carry the seven
|
|
125
125
|
native targets and npm-compatible OS, CPU, and Linux libc filters install only
|
|
126
|
-
the matching binary. Consumers do not run a
|
|
126
|
+
the matching binary. Consumers do not run a Rust build, download code at
|
|
127
127
|
runtime, or execute a postinstall step. Omitting optional dependencies keeps
|
|
128
|
-
|
|
128
|
+
fallback-capable operations working in `auto` or `off`. Native-only
|
|
129
129
|
features, including strict owned-tree temp cleanup, retained-directory staging,
|
|
130
|
-
atomic `rename-noreplace` (including the default no-clobber `Root.move()`),
|
|
131
|
-
|
|
132
|
-
unavailable. Operations without a safe fallback fail with `helper-unavailable`
|
|
130
|
+
and atomic `rename-noreplace` (including the default no-clobber `Root.move()`),
|
|
131
|
+
remain unavailable. Operations without a safe fallback fail with `helper-unavailable`
|
|
133
132
|
when the matching package is absent, incompatible, or disabled.
|
|
134
133
|
|
|
135
134
|
Upgrading an existing 0.5 consumer? Follow [Migrating to 0.6](migrating-to-0.6.md)
|
|
136
135
|
before deploying with native mode `require` or native-only features.
|
|
137
136
|
|
|
137
|
+
### Windows security fallback
|
|
138
|
+
|
|
139
|
+
Windows raw owner/DACL inspection, private-directory creation, and secure-file
|
|
140
|
+
reads work without the addon in `auto` or `off` mode when system Windows
|
|
141
|
+
PowerShell and its .NET `Add-Type` compilation support are available. The package
|
|
142
|
+
ships a readable, fixed `.ps1` driver and adjacent `.cs` source and invokes the
|
|
143
|
+
driver with Windows PowerShell `-File`. Paths are passed as data. The fallback
|
|
144
|
+
does not generate helper scripts at runtime or use an encoded launcher.
|
|
145
|
+
The driver addresses built-in commands by module name and limits module
|
|
146
|
+
discovery to PowerShell's bundled system modules, avoiding broad command
|
|
147
|
+
discovery scans during each helper startup.
|
|
148
|
+
|
|
149
|
+
Normal PowerShell execution policy and Microsoft Defender policy must permit
|
|
150
|
+
the packaged scripts, including their use of `Add-Type`. The package does not
|
|
151
|
+
bypass restrictions, change policies, or add exclusions. Unsupported or
|
|
152
|
+
disallowed command execution fails closed.
|
|
153
|
+
|
|
154
|
+
The fallback preserves private DACLs at creation and inspects the same open
|
|
155
|
+
handle that supplies secure-file bytes. Each capability emits a path-free
|
|
156
|
+
`FS_SAFE_NATIVE_FALLBACK` warning once per process; each call adds PowerShell
|
|
157
|
+
startup and compilation overhead. Execution or compilation failure also fails
|
|
158
|
+
closed. Native `require` still rejects a missing binding or capability, and an
|
|
159
|
+
available native operation's error never triggers a command retry. See
|
|
160
|
+
[Permissions](permissions.md) and [Secure file reads](secure-file.md).
|
|
161
|
+
|
|
138
162
|
## Native helper policy
|
|
139
163
|
|
|
140
164
|
The platform native binaries provide fd-relative open/link/mkdir primitives,
|
|
@@ -147,7 +171,7 @@ where a safe fallback exists. Native-only operations fail with
|
|
|
147
171
|
import { configureFsSafeNative } from "@openclaw/fs-safe/config";
|
|
148
172
|
|
|
149
173
|
configureFsSafeNative({ mode: "auto" }); // default
|
|
150
|
-
configureFsSafeNative({ mode: "off" }); //
|
|
174
|
+
configureFsSafeNative({ mode: "off" }); // disable the addon; reject native-only operations
|
|
151
175
|
configureFsSafeNative({ mode: "require" }); // fail closed if unavailable
|
|
152
176
|
```
|
|
153
177
|
|
package/docs/json.md
CHANGED
|
@@ -146,10 +146,11 @@ where lower latency matters more than crash-durability.
|
|
|
146
146
|
|
|
147
147
|
Synchronous variant. It pretty-prints with two spaces, appends a newline,
|
|
148
148
|
creates parents at `0o700`, writes at `0o600`, and synchronizes the parent
|
|
149
|
-
directory best-effort.
|
|
150
|
-
through rename and
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
directory best-effort. A retained staging descriptor carries the exact bigint
|
|
150
|
+
identity through rename and file-mode tightening. Publication and cleanup never
|
|
151
|
+
adopt a substituted temporary file: a changed identity, type or link count rejects
|
|
152
|
+
the write and leaves the replacement untouched. A swap detected after publication
|
|
153
|
+
also rejects without deleting or changing the replacement. It has no options bag. On `EPERM`/`EEXIST`, its legacy
|
|
153
154
|
compatibility path removes the existing destination and retries the staged-file
|
|
154
155
|
rename, so that fallback is temporarily non-atomic while retaining the staged
|
|
155
156
|
file's `0600` mode; use the async `writeJson()`/`replaceFileAtomic()` surfaces
|
package/docs/local-roots.md
CHANGED
|
@@ -83,6 +83,8 @@ An existing non-directory component cannot be traversed further, including by
|
|
|
83
83
|
The asynchronous helper opens the candidate through the matched [`Root`](root.md),
|
|
84
84
|
so no-follow, identity, hardlink, device-path, and byte-limit checks happen at
|
|
85
85
|
the read itself.
|
|
86
|
+
Link policies are captured once before root initialization and reused for every
|
|
87
|
+
candidate, so replacing options while a read is pending cannot weaken admission.
|
|
86
88
|
|
|
87
89
|
```ts
|
|
88
90
|
type ReadLocalFileFromRootsOptions = LocalRootsInputOptions & {
|
package/docs/migrating-to-0.5.md
CHANGED
|
@@ -88,8 +88,10 @@ await extractArchive({
|
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
Returning `"skip"` rejects the archive unless `onFiltered: "skip-entry"` is
|
|
91
|
-
explicit. Zstd and bzip2 TAR
|
|
92
|
-
|
|
91
|
+
explicit. Zstd and bzip2 TAR required native support in version 0.5; current
|
|
92
|
+
versions also use bundled WASM codecs in `off` or missing-native `auto`, through
|
|
93
|
+
the same guarded TAR pipeline. ZIP fallback still requires optional JSZip.
|
|
94
|
+
Catch `ArchiveLimitError` by its code, including
|
|
93
95
|
`archive-entry-path-components-exceeds-limit` for deep implicit-directory
|
|
94
96
|
attacks. See [Archive extraction](archive.md).
|
|
95
97
|
|
|
@@ -167,10 +169,17 @@ See [File locks](sidecar-lock.md), [Secret files](secret-file.md), and
|
|
|
167
169
|
|
|
168
170
|
## 7. Gate native-only features
|
|
169
171
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
Version 0.5 required native support for `createPrivateDirectory()`. Current
|
|
173
|
+
releases also support a packaged PowerShell script in native `auto` and `off`
|
|
174
|
+
modes, retaining its creation-time protected DACL. Check the
|
|
175
|
+
[Windows security fallback prerequisites](install.md#windows-security-fallback)
|
|
176
|
+
before relying on this route. The API remains Windows-only, explicit native
|
|
177
|
+
`require` rejects a missing binding or capability, and native operation failures
|
|
178
|
+
remain terminal.
|
|
179
|
+
`strategy: "rename-noreplace"` remains native-only. Current zstd/bzip2 extraction
|
|
180
|
+
and bounded reads have bundled WASM fallbacks, while explicit native `require`
|
|
181
|
+
remains strict. Test unavailable native-only operations instead of assuming
|
|
182
|
+
installation always succeeds.
|
|
174
183
|
|
|
175
184
|
## 8. Run both behavior families in CI
|
|
176
185
|
|
package/docs/migrating-to-0.6.md
CHANGED
|
@@ -24,10 +24,15 @@ uses native mode `require` or any native-only feature. Version 0.5 kept its
|
|
|
24
24
|
binding in the root tarball; version 0.6 intentionally does not.
|
|
25
25
|
|
|
26
26
|
Omitting optional dependencies remains supported for fallback-capable APIs in
|
|
27
|
-
`auto` mode. It disables native-only features such as
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
`auto` mode. It disables native-only features such as retained-directory staging
|
|
28
|
+
and atomic `rename-noreplace`. Native mode `require`
|
|
29
|
+
reports `helper-unavailable` when the matching package is absent or incompatible.
|
|
30
|
+
Zstd/bzip2 TAR extraction and bounded reads required the binding in version 0.6;
|
|
31
|
+
current versions also support bundled WASM codecs in `auto` and `off` through the
|
|
32
|
+
same guarded TAR pipeline. ZIP fallback still requires optional JSZip.
|
|
33
|
+
Windows private-directory creation required the binding in version 0.6; current
|
|
34
|
+
releases also support [packaged Windows security scripts](install.md#windows-security-fallback)
|
|
35
|
+
in `auto` and `off` mode while preserving the creation-time protected DACL.
|
|
31
36
|
|
|
32
37
|
## Deployment checklist
|
|
33
38
|
|
|
@@ -44,9 +44,11 @@ new placeholder, and before publishing to an existing symlink-selected destinati
|
|
|
44
44
|
They verify alias binding, destination preservation, observed placeholder/stage
|
|
45
45
|
states, and cleanup before fixture teardown. The default native-off and explicit
|
|
46
46
|
`verify-content-with-lock` native-require configurations both select the existing
|
|
47
|
-
Windows JS buffer writer.
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
Windows JS buffer writer. In native-require mode, the compatibility route loads
|
|
48
|
+
the addon to publish its retained sidecar lock through `Root.create`; the payload
|
|
49
|
+
writer remains JS. The receipt does not mislabel this as native payload
|
|
50
|
+
publication or evidence that content-verification fallback or lock contention
|
|
51
|
+
was exercised.
|
|
50
52
|
|
|
51
53
|
## Bounds and interpretation
|
|
52
54
|
|
package/docs/native-helper.md
CHANGED
|
@@ -15,7 +15,7 @@ consumer Rust build.
|
|
|
15
15
|
import { configureFsSafeNative } from "@openclaw/fs-safe/config";
|
|
16
16
|
|
|
17
17
|
configureFsSafeNative({ mode: "auto" }); // default
|
|
18
|
-
configureFsSafeNative({ mode: "off" }); //
|
|
18
|
+
configureFsSafeNative({ mode: "off" }); // disable the addon; reject native-only operations
|
|
19
19
|
configureFsSafeNative({ mode: "require" }); // fail closed when the binding is unavailable
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -25,14 +25,22 @@ The equivalent environment variables are `FS_SAFE_NATIVE_MODE` and `OPENCLAW_FS_
|
|
|
25
25
|
|
|
26
26
|
| Mode | Behavior |
|
|
27
27
|
|---|---|
|
|
28
|
-
| `auto` | Prefer native primitives when the current platform package loads; otherwise use
|
|
29
|
-
| `off` | Do not load a native package. Use
|
|
28
|
+
| `auto` | Prefer native primitives when the current platform package loads; otherwise use supported fallbacks and reject native-only operations. |
|
|
29
|
+
| `off` | Do not load a native package. Use supported fallbacks and reject native-only operations deterministically. |
|
|
30
30
|
| `require` | Throw `FsSafeError("helper-unavailable")` instead of falling back when an operation needs the native binding and it cannot load. |
|
|
31
31
|
|
|
32
|
-
TAR
|
|
33
|
-
of the same Rust parser
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
Plain TAR, gzip, zstd, and bzip2 extraction and bounded entry reads use a bundled,
|
|
33
|
+
import-free WASM build of the same Rust TAR parser when native support is absent
|
|
34
|
+
or disabled. Zstd/bzip2 codecs are bundled alongside the parser; gzip uses Node's
|
|
35
|
+
built-in decoder. These archive fallbacks require no runtime interpreter or
|
|
36
|
+
download. `off` disables the optional native filesystem helper, not the bundled
|
|
37
|
+
WASM. `auto` prefers native and does not retry a native operation failure through
|
|
38
|
+
WASM; `require` still rejects an unavailable native binding. ZIP fallback still
|
|
39
|
+
requires optional `jszip`. `inspectTarArchive()` remains limited to plain TAR
|
|
40
|
+
and gzip.
|
|
41
|
+
|
|
42
|
+
Windows security operations can use the package's readable PowerShell/C# scripts
|
|
43
|
+
in `auto` and `off`, subject to the [Windows security fallback prerequisites](install.md#windows-security-fallback).
|
|
36
44
|
|
|
37
45
|
On Bun macOS/Linux, the [runtime path adapter](install.md#bun-runtime) uses the
|
|
38
46
|
same Rust addon for system canonicalization in `auto` and `require`. No JIT is
|
|
@@ -109,8 +117,13 @@ there. Deeper names retain guarded parent traversal.
|
|
|
109
117
|
Native primitives back create-only and replacing pinned writes, no-clobber
|
|
110
118
|
`Root.move()`, async sidecar creation, guarded publication, archive acceleration,
|
|
111
119
|
and direct Windows ACL operations. Windows secure-file reads require
|
|
112
|
-
descriptor-bound owner/DACL facts
|
|
113
|
-
|
|
120
|
+
descriptor-bound owner/DACL facts. In native `auto` or `off` mode, a missing
|
|
121
|
+
binding or capability can use a packaged PowerShell script that inspects the
|
|
122
|
+
borrowed handle. Raw owner/DACL inspection and private-directory creation also support
|
|
123
|
+
this fallback, subject to the [Windows security fallback prerequisites](install.md#windows-security-fallback).
|
|
124
|
+
Each capability emits a path-free warning once per process and adds PowerShell
|
|
125
|
+
startup and compilation overhead per call. Native `require` rejects missing
|
|
126
|
+
capabilities, and native operation failures remain terminal. No-clobber moves fail with
|
|
114
127
|
`helper-unavailable` when descriptor-relative parent admission or the atomic
|
|
115
128
|
no-replace rename is unavailable; they never use a check followed by a replacing
|
|
116
129
|
rename. Equivalent JavaScript paths remain available for documented
|
package/docs/native.md
CHANGED
|
@@ -17,7 +17,7 @@ guarded JavaScript path. Native loading is lazy; installs do not compile Rust,
|
|
|
17
17
|
run postinstall code, or fetch binaries at runtime. Seven exact-version optional
|
|
18
18
|
packages are filtered by OS, CPU, and Linux libc, so an installation receives
|
|
19
19
|
only its matching prebuilt binding.
|
|
20
|
-
Native-only formats
|
|
20
|
+
Native-only formats fail explicitly
|
|
21
21
|
instead of substituting a weaker implementation.
|
|
22
22
|
|
|
23
23
|
## The beneath model
|
|
@@ -76,14 +76,14 @@ whether a path, archive entry, mode, owner, or cleanup policy is acceptable.
|
|
|
76
76
|
or add-on CRT descriptor namespace.
|
|
77
77
|
|
|
78
78
|
The internal macOS `inspectDarwinAcl(fd)` capability reports `absent`, `empty`,
|
|
79
|
-
or `present` for the opened object's extended ACL. It synchronously
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
or `present` for the opened object's extended ACL. It synchronously borrows the
|
|
80
|
+
caller's descriptor, preserving its file position and POSIX record locks, and
|
|
81
|
+
never reopens a pathname. Keep the descriptor open until inspection returns.
|
|
82
|
+
Darwin's `acl_get_entry` returns
|
|
82
83
|
zero for an entry; end-of-list is accepted only for the first entry of a valid,
|
|
83
84
|
privately owned empty ACL. Unsupported, malformed, and failed inspection is not
|
|
84
|
-
reported as absence. These facts do not classify individual ACE permissions
|
|
85
|
-
prove volume ownership enforcement
|
|
86
|
-
and secure readers outside the clone path.
|
|
85
|
+
reported as absence. These facts do not classify individual ACE permissions or
|
|
86
|
+
prove volume ownership enforcement; each caller applies its own security policy.
|
|
87
87
|
|
|
88
88
|
## Archives
|
|
89
89
|
|
|
@@ -115,6 +115,17 @@ the guarded Node staging/publication boundary. ZIP behavior is unchanged.
|
|
|
115
115
|
`maxMetaEntryBytes` bounds bodies before allocation; unsupported global/old
|
|
116
116
|
metadata and sparse forms fail closed. See [bounded local PAX support](archive.md#bounded-local-pax-support).
|
|
117
117
|
|
|
118
|
+
The bundled module also compiles the same zstd and bzip2 codec implementations
|
|
119
|
+
used by native. In `off` or missing-native `auto`, those decoders feed the shared
|
|
120
|
+
TAR parser through fixed 64 KiB windows in one import-free WASM session with a
|
|
121
|
+
256 MiB linear-memory ceiling. Gzip retains Node's built-in decoder. Complete
|
|
122
|
+
container and TAR admission precedes policy evaluation and guarded publication;
|
|
123
|
+
concatenated compressed members and zstd skippable frames are consumed through
|
|
124
|
+
physical EOF. No runtime command, interpreter, download, or consumer compilation
|
|
125
|
+
is needed for these archive routes. `require` stays strict, and available native
|
|
126
|
+
operation failures do not retry through WASM. Public `inspectTarArchive()` still
|
|
127
|
+
accepts only plain TAR/gzip; ZIP fallback still requires optional JSZip.
|
|
128
|
+
|
|
118
129
|
Every raw pass receives only TypeScript's resolved `maxEntries`,
|
|
119
130
|
`maxMetaEntryBytes`, and `maxDecodedBytes`. Shared resolution caps metadata and
|
|
120
131
|
decoded byte fields at JavaScript's safe-integer maximum and entry counts at
|
|
@@ -172,12 +183,26 @@ not bypass the byte limit.
|
|
|
172
183
|
does not load the binding. Use asynchronous `sha256File()` for native hashing
|
|
173
184
|
and cancellation that can respond while JavaScript callbacks run.
|
|
174
185
|
|
|
175
|
-
Features without a safe
|
|
176
|
-
`Root.move()
|
|
186
|
+
Features without a safe fallback, including no-clobber
|
|
187
|
+
`Root.move()` and
|
|
177
188
|
[retained-directory staging](staged-file.md), fail with `helper-unavailable`
|
|
178
189
|
when native support is absent or off. Staging is currently Linux/macOS only and
|
|
179
190
|
rejects Windows with `unsupported-platform`.
|
|
180
191
|
|
|
192
|
+
Windows raw owner/DACL inspection, private-directory creation, and secure-file
|
|
193
|
+
descriptor inspection can use a package-shipped, readable `.ps1` driver and
|
|
194
|
+
adjacent `.cs` source in `auto` or `off` mode when their binding or capability is
|
|
195
|
+
unavailable. System Windows PowerShell runs the fixed driver with `-File`;
|
|
196
|
+
paths remain data, with no runtime-generated helper script or encoded launcher.
|
|
197
|
+
The [Windows security fallback prerequisites](install.md#windows-security-fallback)
|
|
198
|
+
apply, and unsupported or disallowed command execution fails closed. This route
|
|
199
|
+
preserves raw ACL facts, private DACLs at creation, and descriptor-bound secure
|
|
200
|
+
reads, and emits a path-free `FS_SAFE_NATIVE_FALLBACK` warning once per capability
|
|
201
|
+
per process. Each call adds PowerShell startup and compilation overhead.
|
|
202
|
+
`require` rejects missing capabilities without a command, and an available native operation's
|
|
203
|
+
failure never triggers this fallback. See [Permissions](permissions.md) and
|
|
204
|
+
[Secure file reads](secure-file.md) for error and platform contracts.
|
|
205
|
+
|
|
181
206
|
The staged-file owner also serves POSIX native pinned writes, including streaming.
|
|
182
207
|
Unpublished files remain at `0600`; requested modes are applied through the
|
|
183
208
|
owned file descriptor only after rename and published-entry identity validation.
|
|
@@ -219,15 +244,21 @@ rejection, archive filters/limits/modes, exclusive target creation, source and
|
|
|
219
244
|
target identity fencing, publication cleanup receipts, and secret/lock policy
|
|
220
245
|
remain TypeScript-owned. What changes is the syscall strength or availability:
|
|
221
246
|
|
|
247
|
+
The table compares underlying mechanisms. On Node, public `Root.open()`,
|
|
248
|
+
`Root.read()`, and `Root.openWritable()` use guarded Node file opens and report
|
|
249
|
+
`containment: "best-effort"` in every native mode. `require` checks availability
|
|
250
|
+
when an operation requests native support; it does not upgrade those results.
|
|
251
|
+
See [Root containment guarantees](security-model.md#containment-guarantees-by-platform).
|
|
252
|
+
|
|
222
253
|
| Capability | Native path | Guarded JavaScript path |
|
|
223
254
|
|---|---|---|
|
|
224
|
-
| Root
|
|
255
|
+
| Native beneath opens and Root mutations | Descriptor-relative beneath operations. Pinned writes create parents and publish both replacement and no-replace targets relative to open directory descriptors. No-clobber `Root.move()` admits both parents and uses the native no-replace rename. Native `openBeneath()` reports `kernel-atomic` on Linux and `best-effort` on macOS and Windows. macOS uses `O_RESOLVE_BENEATH` when available plus an `F_GETPATH` detector, while Windows rejects reparse traversal in the object-manager call. | Reports `best-effort`: component-wise alias checks, no-follow opens where Node exposes them, private temp/rename, and post-operation identity verification. No-clobber `Root.move()` is unsupported because a check followed by a replacing rename is unsafe. A same-privilege peer can replace a writable parent after a guard assertion but before Node resolves another pathname mutation; the mutation may land outside the intended root before the post-check detects it. |
|
|
225
256
|
| ZIP/TAR/gzip | Rust streaming decode and fd-relative output creation. | Optional JSZip or bundled WASM TAR into guarded private staging, then the same guarded merge policy. |
|
|
226
|
-
| Zstd/bzip2 TAR |
|
|
257
|
+
| Zstd/bzip2 TAR | Rust streaming decode and fd-relative output creation. | Bundled WASM codecs feed the shared Rust TAR parser, then guarded private staging and the same merge policy; no optional codec dependency. |
|
|
227
258
|
| Publication copy | Clone, Linux `copy_file_range`, async native SHA-256. | Exclusive `wx` byte loop and Node SHA-256 with the same content/identity fences. |
|
|
228
259
|
| `rename-noreplace` | Atomic platform no-replace rename. | Unsupported; no emulation by check-then-rename. |
|
|
229
|
-
| Windows DACL read | Direct `GetSecurityInfo`; the public facts API exposes ordered basic allow/deny ACE SIDs, masks, and decoded flags without trust policy. Secure-file reads query the borrowed open descriptor and compare its 32-bit volume serial and 64-bit file-index projection with Node's bigint receipt. |
|
|
230
|
-
| Windows private directory | Creation-time protected DACL. |
|
|
260
|
+
| Windows DACL read | Direct `GetSecurityInfo`; the public facts API exposes ordered basic allow/deny ACE SIDs, masks, and decoded flags without trust policy. Secure-file reads query the borrowed open descriptor and compare its 32-bit volume serial and 64-bit file-index projection with Node's bigint receipt. | The packaged PowerShell/C# bridge preserves raw facts and inspects the borrowed descriptor for secure reads, with the same Node identity comparison; its command failures reject. Structured .NET pathname reporting retains its separate compatibility query. |
|
|
261
|
+
| Windows private directory | Creation-time protected DACL. | The packaged PowerShell/C# bridge applies the protected DACL at creation and retains exact handles through identity validation and failure cleanup. Command failures reject. |
|
|
231
262
|
|
|
232
263
|
Use `off` in CI to keep the fallback contract exercised. Use `require` when a
|
|
233
264
|
deployment depends on the stronger mechanism or a native-only feature; do not
|
|
@@ -236,8 +267,9 @@ infer native loading from timing.
|
|
|
236
267
|
## Loader security
|
|
237
268
|
|
|
238
269
|
Importing fs-safe never executes a child process. Linux libc selection uses
|
|
239
|
-
the Node process report,
|
|
240
|
-
|
|
270
|
+
the Node process report, then the ELF `PT_INTERP` field of `process.execPath`,
|
|
271
|
+
then conventional musl library filenames. An installed compatibility loader
|
|
272
|
+
does not override the running executable's interpreter. If all probes are inconclusive, the
|
|
241
273
|
loader conservatively attempts the glibc package and lets normal module loading
|
|
242
274
|
fail into `auto` fallback. The loader requires only the package selected from
|
|
243
275
|
the detected target; it never probes unrelated packages, downloads code, or
|