toolcraft 0.0.749 → 0.0.750
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/composition.json +23 -3
- package/dist/composition.json +23 -3
- package/dist/human-in-loop/approvals-commands.d.ts +1 -1
- package/dist/index.d.ts +1 -262
- package/dist/index.js +1 -573
- package/dist/runtime-platform.d.ts +2 -0
- package/dist/runtime-platform.js +2 -0
- package/dist/runtime-platform.workerd.d.ts +3 -0
- package/dist/runtime-platform.workerd.js +10 -0
- package/dist/runtime.d.ts +262 -0
- package/dist/runtime.js +576 -0
- package/node_modules/@noble/hashes/LICENSE +21 -0
- package/node_modules/@noble/hashes/README.md +478 -0
- package/node_modules/@noble/hashes/_blake.d.ts +20 -0
- package/node_modules/@noble/hashes/_blake.js +59 -0
- package/node_modules/@noble/hashes/_md.d.ts +95 -0
- package/node_modules/@noble/hashes/_md.js +209 -0
- package/node_modules/@noble/hashes/_u64.d.ts +36 -0
- package/node_modules/@noble/hashes/_u64.js +77 -0
- package/node_modules/@noble/hashes/argon2.d.ts +148 -0
- package/node_modules/@noble/hashes/argon2.js +577 -0
- package/node_modules/@noble/hashes/blake1.d.ts +162 -0
- package/node_modules/@noble/hashes/blake1.js +630 -0
- package/node_modules/@noble/hashes/blake2.d.ts +203 -0
- package/node_modules/@noble/hashes/blake2.js +573 -0
- package/node_modules/@noble/hashes/blake3.d.ts +68 -0
- package/node_modules/@noble/hashes/blake3.js +310 -0
- package/node_modules/@noble/hashes/eskdf.d.ts +91 -0
- package/node_modules/@noble/hashes/eskdf.js +225 -0
- package/node_modules/@noble/hashes/hkdf.d.ts +70 -0
- package/node_modules/@noble/hashes/hkdf.js +152 -0
- package/node_modules/@noble/hashes/hmac.d.ts +50 -0
- package/node_modules/@noble/hashes/hmac.js +93 -0
- package/node_modules/@noble/hashes/index.d.ts +1 -0
- package/node_modules/@noble/hashes/index.js +34 -0
- package/node_modules/@noble/hashes/legacy.d.ts +107 -0
- package/node_modules/@noble/hashes/legacy.js +348 -0
- package/node_modules/@noble/hashes/package.json +91 -0
- package/node_modules/@noble/hashes/pbkdf2.d.ts +66 -0
- package/node_modules/@noble/hashes/pbkdf2.js +176 -0
- package/node_modules/@noble/hashes/scrypt.d.ts +98 -0
- package/node_modules/@noble/hashes/scrypt.js +304 -0
- package/node_modules/@noble/hashes/sha2.d.ts +176 -0
- package/node_modules/@noble/hashes/sha2.js +446 -0
- package/node_modules/@noble/hashes/sha3-addons.d.ts +533 -0
- package/node_modules/@noble/hashes/sha3-addons.js +973 -0
- package/node_modules/@noble/hashes/sha3.d.ts +208 -0
- package/node_modules/@noble/hashes/sha3.js +475 -0
- package/node_modules/@noble/hashes/src/_blake.ts +67 -0
- package/node_modules/@noble/hashes/src/_md.ts +227 -0
- package/node_modules/@noble/hashes/src/_u64.ts +111 -0
- package/node_modules/@noble/hashes/src/argon2.ts +693 -0
- package/node_modules/@noble/hashes/src/blake1.ts +677 -0
- package/node_modules/@noble/hashes/src/blake2.ts +648 -0
- package/node_modules/@noble/hashes/src/blake3.ts +344 -0
- package/node_modules/@noble/hashes/src/eskdf.ts +265 -0
- package/node_modules/@noble/hashes/src/hkdf.ts +161 -0
- package/node_modules/@noble/hashes/src/hmac.ts +130 -0
- package/node_modules/@noble/hashes/src/index.ts +33 -0
- package/node_modules/@noble/hashes/src/legacy.ts +361 -0
- package/node_modules/@noble/hashes/src/pbkdf2.ts +219 -0
- package/node_modules/@noble/hashes/src/scrypt.ts +375 -0
- package/node_modules/@noble/hashes/src/sha2.ts +486 -0
- package/node_modules/@noble/hashes/src/sha3-addons.ts +1157 -0
- package/node_modules/@noble/hashes/src/sha3.ts +525 -0
- package/node_modules/@noble/hashes/src/utils.ts +978 -0
- package/node_modules/@noble/hashes/src/webcrypto.ts +283 -0
- package/node_modules/@noble/hashes/utils.d.ts +560 -0
- package/node_modules/@noble/hashes/utils.js +687 -0
- package/node_modules/@noble/hashes/webcrypto.d.ts +121 -0
- package/node_modules/@noble/hashes/webcrypto.js +228 -0
- package/node_modules/@poe-code/agent-mcp-config/dist/apply.js +23 -9
- package/node_modules/@poe-code/config-mutations/README.md +2 -0
- package/node_modules/@poe-code/config-mutations/dist/execution/apply-mutation.js +4 -5
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.d.ts +3 -4
- package/node_modules/@poe-code/config-mutations/dist/execution/path-utils.js +3 -3
- package/node_modules/@poe-code/config-mutations/dist/template/render.js +1 -1
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.d.ts +2 -2
- package/node_modules/@poe-code/config-mutations/dist/testing/mock-fs.js +3 -6
- package/node_modules/@poe-code/config-mutations/dist/types.d.ts +4 -2
- package/node_modules/@poe-code/process-runner/README.md +2 -1
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.d.ts +1 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.js +1 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.d.ts +2 -0
- package/node_modules/@poe-code/process-runner/dist/transfer-filesystem.workerd.js +1 -0
- package/node_modules/@poe-code/process-runner/dist/types.d.ts +1 -1
- package/node_modules/@poe-code/process-runner/dist/workspace-transfer.d.ts +6 -5
- package/node_modules/@poe-code/process-runner/dist/workspace-transfer.js +67 -29
- package/node_modules/@poe-code/process-runner/package.json +13 -0
- package/node_modules/@poe-code/safe-fs/LICENSE +21 -0
- package/node_modules/@poe-code/safe-fs/PROVENANCE.json +428 -0
- package/node_modules/@poe-code/safe-fs/README.md +411 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/confinement.js +171 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.d.ts +93 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/filesystem.js +453 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/index.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/index.js +19 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/stats.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/stats.js +37 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/types.d.ts +81 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/types.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/values.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/bridge/values.js +65 -0
- package/node_modules/@poe-code/safe-fs/dist/config/memory.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/config/memory.js +7 -0
- package/node_modules/@poe-code/safe-fs/dist/config/real.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/config/real.js +16 -0
- package/node_modules/@poe-code/safe-fs/dist/config/registry.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/config/registry.js +15 -0
- package/node_modules/@poe-code/safe-fs/dist/config.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/config.js +46 -0
- package/node_modules/@poe-code/safe-fs/dist/config.node.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/config.node.js +11 -0
- package/node_modules/@poe-code/safe-fs/dist/config.portable.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/config.portable.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/abort.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/abort.js +34 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/cleanup.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.d.ts +38 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/descriptor.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/errors.d.ts +53 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/errors.js +99 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.d.ts +379 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/filesystem.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/index.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/index.js +6 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/io.d.ts +12 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/io.js +321 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/object.d.ts +134 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/object.js +97 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/path.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/path.js +2 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.d.ts +21 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/portable-path.js +78 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/contracts/virtual-path.js +162 -0
- package/node_modules/@poe-code/safe-fs/dist/core.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/core.js +17 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.d.ts +10 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/capabilities.js +216 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/conditional-chmod.js +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.d.ts +21 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/descriptor.js +279 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.d.ts +59 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/index.js +875 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/path.js +250 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/devices/stream.js +136 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/directory-admission.js +14 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.d.ts +11 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/atomic-view.js +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.d.ts +186 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/index.js +3771 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/ledger.js +96 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.d.ts +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/limits.js +26 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/memory/missing-target.js +144 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/comparison.js +118 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.d.ts +6 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/identity.js +29 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.d.ts +74 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/mount/index.js +1291 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.d.ts +27 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-authority.js +287 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.d.ts +45 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/object-publication/index.js +531 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.d.ts +87 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/index.js +1185 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.d.ts +42 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/overlay/memory-publication.js +558 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/path-namespace.js +63 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.d.ts +12 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/quota/index.js +520 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.d.ts +37 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/readonly/index.js +208 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/allocation.js +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/index.d.ts +105 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/real/index.js +1259 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.d.ts +7 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/authority.js +38 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.d.ts +130 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/filesystem.js +1137 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/bytes.js +9 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/index.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-fetch.js +74 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.d.ts +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request-node.js +111 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.d.ts +17 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/request.js +89 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.d.ts +20 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/signature.js +76 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/transport.js +478 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.d.ts +30 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/types.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.d.ts +14 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/http/xml.js +192 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/index.js +4 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/key-order.js +11 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/manifest-admission.js +167 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.d.ts +48 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/mock.js +249 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.d.ts +13 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/namespace.js +400 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.d.ts +10 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/registry.js +73 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.d.ts +103 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/s3/transport.js +28 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/scoped.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/scoped.js +663 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-ancestry.js +115 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/staging-cleanup.js +63 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/index.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.d.ts +18 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/resource-id.js +109 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.d.ts +141 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/webdav.js +1377 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/fs/webdav/xml.js +59 -0
- package/node_modules/@poe-code/safe-fs/dist/index.d.ts +25 -0
- package/node_modules/@poe-code/safe-fs/dist/index.js +21 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/linux-x64-glibc.node +0 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.d.ts +5 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/loader.mjs +120 -0
- package/node_modules/@poe-code/safe-fs/dist/native/fs-seek/manifest.json +46 -0
- package/node_modules/@poe-code/safe-fs/dist/node/filesystem.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/node/filesystem.js +30 -0
- package/node_modules/@poe-code/safe-fs/dist/node/host.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/host.js +78 -0
- package/node_modules/@poe-code/safe-fs/dist/node/index.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/index.js +2 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek-unavailable.js +5 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/node/native-seek.js +54 -0
- package/node_modules/@poe-code/safe-fs/dist/node/stats.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/stats.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/values.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node/values.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-host.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-host.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-unavailable.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/node-unavailable.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/package.json +29 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser-path.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/browser.js +58 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node-path.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node-path.js +1 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node.d.ts +26 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/node.js +64 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.d.ts +9 -0
- package/node_modules/@poe-code/safe-fs/dist/platform/transport-budget.js +17 -0
- package/node_modules/@poe-code/safe-fs/dist/python/emscripten.d.ts +15 -0
- package/node_modules/@poe-code/safe-fs/dist/python/emscripten.js +357 -0
- package/node_modules/@poe-code/safe-fs/dist/python/filesystem.d.ts +51 -0
- package/node_modules/@poe-code/safe-fs/dist/python/filesystem.js +243 -0
- package/node_modules/@poe-code/safe-fs/dist/python/flags.d.ts +3 -0
- package/node_modules/@poe-code/safe-fs/dist/python/flags.js +14 -0
- package/node_modules/@poe-code/safe-fs/dist/python/index.d.ts +9 -0
- package/node_modules/@poe-code/safe-fs/dist/python/index.js +5 -0
- package/node_modules/@poe-code/safe-fs/dist/python/native.d.ts +18 -0
- package/node_modules/@poe-code/safe-fs/dist/python/native.js +446 -0
- package/node_modules/@poe-code/safe-fs/dist/python/request.d.ts +2 -0
- package/node_modules/@poe-code/safe-fs/dist/python/request.js +61 -0
- package/node_modules/@poe-code/safe-fs/dist/python/stat.d.ts +8 -0
- package/node_modules/@poe-code/safe-fs/dist/python/stat.js +34 -0
- package/node_modules/@poe-code/safe-fs/dist/runtime-core.d.ts +27 -0
- package/node_modules/@poe-code/safe-fs/dist/runtime-core.js +57 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.d.ts +16 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/atomic-filesystem.js +496 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.d.ts +23 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-control.js +39 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.d.ts +31 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-io-metrics.js +143 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.d.ts +19 -0
- package/node_modules/@poe-code/safe-fs/dist/testing/object-publication.js +209 -0
- package/node_modules/@poe-code/safe-fs/dist/xml.d.ts +1 -0
- package/node_modules/@poe-code/safe-fs/dist/xml.js +1 -0
- package/node_modules/@poe-code/safe-fs/package.json +189 -0
- package/node_modules/@poe-code/task-list/README.md +2 -0
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.d.ts +1 -1
- package/node_modules/@poe-code/task-list/dist/backends/gh-issues-client.js +11 -4
- package/node_modules/@poe-code/task-list/dist/backends/markdown-dir.js +2 -2
- package/node_modules/@poe-code/task-list/dist/backends/utils.js +5 -7
- package/node_modules/@poe-code/task-list/dist/backends/yaml-file.js +1 -1
- package/node_modules/@poe-code/task-list/dist/default-host.d.ts +2 -0
- package/node_modules/@poe-code/task-list/dist/default-host.js +2 -0
- package/node_modules/@poe-code/task-list/dist/default-host.workerd.d.ts +4 -0
- package/node_modules/@poe-code/task-list/dist/default-host.workerd.js +6 -0
- package/node_modules/@poe-code/task-list/dist/filesystem.d.ts +3 -0
- package/node_modules/@poe-code/task-list/dist/filesystem.js +32 -0
- package/node_modules/@poe-code/task-list/dist/move.js +3 -3
- package/node_modules/@poe-code/task-list/dist/open.js +2 -5
- package/node_modules/@poe-code/task-list/dist/paths.d.ts +12 -0
- package/node_modules/@poe-code/task-list/dist/paths.js +7 -0
- package/node_modules/@poe-code/task-list/dist/types.d.ts +6 -5
- package/node_modules/@poe-code/task-list/package.json +9 -0
- package/node_modules/@poe-code/terminal-text/LICENSE +21 -0
- package/node_modules/@poe-code/terminal-text/README.md +12 -0
- package/node_modules/@poe-code/terminal-text/dist/index.d.ts +2 -0
- package/node_modules/@poe-code/terminal-text/dist/index.js +20 -0
- package/node_modules/@poe-code/terminal-text/package.json +22 -0
- package/node_modules/@poe-code/xml-ast/LICENSE +21 -0
- package/node_modules/@poe-code/xml-ast/README.md +28 -0
- package/node_modules/@poe-code/xml-ast/dist/index.d.ts +47 -0
- package/node_modules/@poe-code/xml-ast/dist/index.js +635 -0
- package/node_modules/@poe-code/xml-ast/package.json +25 -0
- package/node_modules/auth-store/README.md +35 -0
- package/node_modules/auth-store/dist/index.browser.d.ts +4 -0
- package/node_modules/auth-store/dist/index.browser.js +2 -0
- package/node_modules/auth-store/dist/provider-store.d.ts +1 -1
- package/node_modules/auth-store/dist/safe-fs-secret-store.d.ts +21 -0
- package/node_modules/auth-store/dist/safe-fs-secret-store.js +119 -0
- package/node_modules/auth-store/dist/secret-store.d.ts +12 -0
- package/node_modules/auth-store/dist/secret-store.js +1 -0
- package/node_modules/auth-store/dist/transaction-lock.d.ts +2 -4
- package/node_modules/auth-store/dist/types.d.ts +2 -9
- package/node_modules/auth-store/package.json +16 -2
- package/node_modules/tiny-http-mcp-server/dist/composition.json +16 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/README.md +25 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/authorization-state.js +4 -4
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/default-oauth-client-provider.js +6 -40
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.d.ts +10 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/oauth-form.js +20 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/pkce.js +4 -3
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.d.ts +14 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/register-client.js +53 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.d.ts +16 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/resumable.js +29 -9
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.d.ts +12 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/revoke-token.js +23 -0
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/client/token-endpoint.js +6 -19
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/http-fetch.js +1 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.d.ts +6 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.browser.js +5 -1
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.d.ts +5 -2
- package/node_modules/tiny-http-mcp-server/node_modules/mcp-oauth/dist/index.js +4 -1
- package/node_modules/tiny-http-mcp-server/package.json +4 -4
- package/node_modules/tiny-mcp-client/README.md +2 -0
- package/node_modules/tiny-mcp-client/dist/index.browser.d.ts +25 -23
- package/node_modules/tiny-mcp-client/dist/index.browser.js +116 -1
- package/node_modules/tiny-mcp-client/dist/index.d.ts +25 -23
- package/node_modules/tiny-mcp-client/dist/index.js +1034 -561
- package/node_modules/tiny-mcp-client/package.json +15 -0
- package/node_modules/tiny-stdio-mcp-server/dist/composition.json +1 -1
- package/node_modules/toolcraft-design/dist/components/table.js +6 -0
- package/node_modules/toolcraft-design/dist/escape-terminal-text.d.ts +1 -2
- package/node_modules/toolcraft-design/dist/escape-terminal-text.js +1 -20
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser/frontmatter.js +2 -1
- package/node_modules/toolcraft-design/dist/terminal-markdown/parser.js +2 -1
- package/node_modules/toolcraft-schema/dist/json-schema/utils.js +3 -0
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +32 -7
|
@@ -0,0 +1,1291 @@
|
|
|
1
|
+
import { FsError, isFsError, toFsError } from "../../contracts/errors.js";
|
|
2
|
+
import { readBytes } from "../../contracts/io.js";
|
|
3
|
+
import { finishCleanup } from "../../contracts/cleanup.js";
|
|
4
|
+
import { requireOwnedMutation, ownedMutationCapabilities, openRetainedReadFile, openRetainedResizeFile, readOnlyCapabilities, retainedReadCapabilities, retainedResizeCapabilities } from "../capabilities.js";
|
|
5
|
+
import { admitDirectoryEntries, directoryEntryLimit } from "../directory-admission.js";
|
|
6
|
+
import { normalizePath, validatePath } from "../../contracts/virtual-path.js";
|
|
7
|
+
import { forwardFileDescriptor, openFileDescriptor } from "../descriptor.js";
|
|
8
|
+
import { pathNamespace } from "../path-namespace.js";
|
|
9
|
+
import { createStagingCleanup, snapshotStagingCreation } from "../staging-cleanup.js";
|
|
10
|
+
import { directoryAncestryPaths, inspectStagingBindings, runStagingGuard, snapshotDirectoryAncestry, snapshotStagingResolution } from "../staging-ancestry.js";
|
|
11
|
+
import { compareIdentity } from "./identity.js";
|
|
12
|
+
import { createReadOnlyFileSystem } from "../readonly/index.js";
|
|
13
|
+
import { snapshotConditionalChmod } from "../conditional-chmod.js";
|
|
14
|
+
import { compareEntries, registerEntryAuthority, registerEntryView } from "./comparison.js";
|
|
15
|
+
const syntheticStat = Object.freeze({
|
|
16
|
+
type: "directory", size: 0, mode: 0o40555,
|
|
17
|
+
mtimeMs: 0, atimeMs: 0, ctimeMs: 0,
|
|
18
|
+
});
|
|
19
|
+
function within(parent, path) {
|
|
20
|
+
return parent === "/" || path === parent || path.startsWith(`${parent}/`);
|
|
21
|
+
}
|
|
22
|
+
function globalPath(path) {
|
|
23
|
+
return typeof path === "string" && path.startsWith("/") ? path : `/${String(path)}`;
|
|
24
|
+
}
|
|
25
|
+
function fail(code) {
|
|
26
|
+
throw new FsError(code);
|
|
27
|
+
}
|
|
28
|
+
function snapshotStat(stat) {
|
|
29
|
+
const { type, filesystemType, size, allocatedBytes, ioBlockSize, preferredIoBlockSize, mode, mtimeMs, atimeMs, ctimeMs, birthtimeMs, revision, identityScope, opaqueIdentity, opaqueVersion, ino, dev, rdevMajor, rdevMinor, nlink, uid, gid } = stat;
|
|
30
|
+
return {
|
|
31
|
+
type, size, mode, mtimeMs, atimeMs, ctimeMs,
|
|
32
|
+
...(filesystemType === undefined ? {} : { filesystemType }),
|
|
33
|
+
...(revision === undefined ? {} : { revision }),
|
|
34
|
+
...(allocatedBytes === undefined ? {} : { allocatedBytes }),
|
|
35
|
+
...(ioBlockSize === undefined ? {} : { ioBlockSize }),
|
|
36
|
+
...(preferredIoBlockSize === undefined ? {} : { preferredIoBlockSize }),
|
|
37
|
+
...(birthtimeMs === undefined ? {} : { birthtimeMs }),
|
|
38
|
+
...(identityScope === undefined ? {} : { identityScope }),
|
|
39
|
+
...(opaqueIdentity === undefined ? {} : { opaqueIdentity }),
|
|
40
|
+
...(opaqueVersion === undefined ? {} : { opaqueVersion }),
|
|
41
|
+
...(ino === undefined ? {} : { ino }),
|
|
42
|
+
...(dev === undefined ? {} : { dev }),
|
|
43
|
+
...(rdevMajor === undefined ? {} : { rdevMajor }),
|
|
44
|
+
...(rdevMinor === undefined ? {} : { rdevMinor }),
|
|
45
|
+
...(nlink === undefined ? {} : { nlink }),
|
|
46
|
+
...(uid === undefined ? {} : { uid }),
|
|
47
|
+
...(gid === undefined ? {} : { gid }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export class MountFileSystem {
|
|
51
|
+
capabilities;
|
|
52
|
+
mounts;
|
|
53
|
+
activeNamespaceOperations = 0;
|
|
54
|
+
namespaceMutation = false;
|
|
55
|
+
namespaceWaiters = new Set();
|
|
56
|
+
constructor(options) {
|
|
57
|
+
const mounts = [];
|
|
58
|
+
const paths = new Set();
|
|
59
|
+
const add = (path, backend) => {
|
|
60
|
+
if (backend instanceof MountFileSystem) {
|
|
61
|
+
for (const child of backend.mounts) {
|
|
62
|
+
add(path === "/" ? child.path : child.path === "/" ? path : `${path}${child.path}`, child.backend);
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (paths.has(path)) {
|
|
67
|
+
throw new FsError("EINVAL", { syscall: "mount", path });
|
|
68
|
+
}
|
|
69
|
+
paths.add(path);
|
|
70
|
+
mounts.push({ path, backend });
|
|
71
|
+
};
|
|
72
|
+
add("/", options.root);
|
|
73
|
+
for (const [input, backend] of Object.entries(options.mounts ?? {})) {
|
|
74
|
+
try {
|
|
75
|
+
validatePath(input);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new FsError("EINVAL", { syscall: "mount", path: globalPath(input), cause: error });
|
|
79
|
+
}
|
|
80
|
+
const path = normalizePath(input);
|
|
81
|
+
if (!input.startsWith("/") || path === "/") {
|
|
82
|
+
throw new FsError("EINVAL", { syscall: "mount", path: globalPath(input) });
|
|
83
|
+
}
|
|
84
|
+
add(path, backend);
|
|
85
|
+
}
|
|
86
|
+
this.mounts = mounts.sort((left, right) => right.path.length - left.path.length);
|
|
87
|
+
const selectNamespace = this.select.bind(this);
|
|
88
|
+
Object.defineProperty(this, pathNamespace, {
|
|
89
|
+
value: Object.freeze({ select: (path) => selectNamespace(path).path }),
|
|
90
|
+
});
|
|
91
|
+
registerEntryView(this, (path, options) => this.operation("compareEntry", path, options, async () => {
|
|
92
|
+
const location = await this.resolve(path, options);
|
|
93
|
+
if (location.synthetic)
|
|
94
|
+
return { filesystem: this, path, stat: syntheticStat, readOnly: true };
|
|
95
|
+
return { filesystem: location.mount.backend, path: location.local };
|
|
96
|
+
}));
|
|
97
|
+
registerEntryAuthority(this, async () => "unknown");
|
|
98
|
+
const all = (capability, methods = []) => mounts.every(({ backend }) => backend.capabilities[capability] === true
|
|
99
|
+
&& methods.every((method) => typeof backend[method] === "function"));
|
|
100
|
+
const streaming = (capability, method) => all(capability, [method]) ? true : mounts.some(({ backend }) => backend.capabilities[capability] !== false && typeof backend[method] === "function") ? undefined : false;
|
|
101
|
+
const streamingRead = streaming("streamingRead", "readStream");
|
|
102
|
+
const streamingWrite = streaming("streamingWrite", "writeStream");
|
|
103
|
+
const retainedRead = streaming("retainedRead", "openReadFile");
|
|
104
|
+
const append = all("append") ? true
|
|
105
|
+
: mounts.every(({ backend }) => backend.capabilities.append === false) ? false : undefined;
|
|
106
|
+
const common = (capability) => {
|
|
107
|
+
const optional = {
|
|
108
|
+
open: ["open"],
|
|
109
|
+
retainedStagingCleanup: ["createStagedFile", "publishStagedFile", "removeStagedFile"],
|
|
110
|
+
synchronousDirectoryValidation: ["prepareDirectoryAncestry"], guardedStagingPublication: ["createStagedFile", "publishStagedFile", "removeStagedFile"],
|
|
111
|
+
trustedOwnedStaging: ["createStagedFile", "publishStagedFile", "removeStagedFile", "writeFileConditional", "removeFileConditional", "prepareDirectory"],
|
|
112
|
+
atomicFilePublication: ["publishFileConditional"], atomicEntryRemoval: ["removeEntryConditional"], atomicEntryRemovalReceipt: ["removeEntryConditional"], atomicTreeRemoval: ["removeTreeConditional"], atomicFileMutation: ["writeFileConditional", "removeFileConditional"], atomicFileStaging: ["createStagedFile", "publishStagedFile", "removeStagedFile"], atomicDirectoryMetadata: ["prepareDirectory"],
|
|
113
|
+
symlinks: ["symlink", "readlink"], hardlinks: ["link"], permissions: ["chmod"], timestamps: ["utimes"], readlink: ["readlink"],
|
|
114
|
+
descriptorWriteStream: ["writeStream"], retainedResize: ["openResizeFile"], atomicResize: ["resizeFile"],
|
|
115
|
+
};
|
|
116
|
+
const values = mounts.map(({ backend }) => {
|
|
117
|
+
if (backend.capabilities.readOnly === true
|
|
118
|
+
&& !["open", "versionedDescriptors", "read", "stat", "readdir", "realpath", "access", "readlink", "explicitDirectories", "implicitDirectories"].includes(capability))
|
|
119
|
+
return false;
|
|
120
|
+
const declared = capability === "retainedStagingCleanup" || capability === "atomicEntryRemovalReceipt"
|
|
121
|
+
? ownedMutationCapabilities(backend)[capability] : backend.capabilities[capability];
|
|
122
|
+
if (capability === "descriptorWriteStream" && backend.capabilities.streamingWrite === false)
|
|
123
|
+
return false;
|
|
124
|
+
return declared === true && optional[capability]?.some(method => typeof backend[method] !== "function") ? false : declared;
|
|
125
|
+
});
|
|
126
|
+
if (["rename", "atomicRenameNoReplace", "copy", "exclusiveCopy"].includes(capability) && mounts.length > 1)
|
|
127
|
+
return undefined;
|
|
128
|
+
return values.every(value => value === true) ? true : values.every(value => value === false) ? false : undefined;
|
|
129
|
+
};
|
|
130
|
+
const semantics = Object.fromEntries([
|
|
131
|
+
"guardedStagingPublication", "retainedStagingCleanup", "atomicEntryRemovalReceipt",
|
|
132
|
+
"trustedOwnedStaging", "atomicFilePublication", "atomicEntryRemoval", "atomicTreeRemoval", "atomicFileMutation", "atomicFileStaging", "atomicDirectoryMetadata", "read", "stat", "readdir", "realpath", "access", "open", "versionedDescriptors",
|
|
133
|
+
"write", "append", "exclusiveCreate", "explicitDirectories", "implicitDirectories", "mkdir", "recursiveMkdir",
|
|
134
|
+
"remove", "removeDirectory", "recursiveRemove", "rename", "atomicRenameNoReplace", "copy", "exclusiveCopy", "readlink", "truncate",
|
|
135
|
+
"streamingAppend", "randomAccessWrite", "descriptorWriteStream", "retainedResize", "atomicResize", "symlinks", "hardlinks", "permissions", "timestamps",
|
|
136
|
+
].map(capability => [capability, common(capability)]).filter(([, value]) => value !== undefined));
|
|
137
|
+
this.capabilities = Object.freeze({
|
|
138
|
+
get snapshotRmdir() { return mounts.some(({ backend }) => backend.capabilities.snapshotRmdir === true); },
|
|
139
|
+
readOnly: all("readOnly"),
|
|
140
|
+
...(append === undefined ? {} : { append }),
|
|
141
|
+
...semantics,
|
|
142
|
+
// Real ancestry (including synthetic mount parents) is path-dependent.
|
|
143
|
+
synchronousStagingResolution: mounts.some(({ backend }) => typeof backend.prepareStagingResolution === "function") ? undefined : false,
|
|
144
|
+
atomicStagingAncestry: mounts.some(({ backend }) => typeof backend.prepareDirectoryAncestry === "function"
|
|
145
|
+
&& typeof backend.publishStagedFile === "function" && (typeof backend.capabilitiesFor === "function"
|
|
146
|
+
|| backend.capabilities.guardedStagingPublication !== false && backend.capabilities.synchronousDirectoryValidation !== false)) ? undefined : false,
|
|
147
|
+
atomicRename: mounts.length === 1 && all("atomicRename"),
|
|
148
|
+
conditionalChmod: all("conditionalChmod", ["chmod", "prepareDirectoryAncestry"]),
|
|
149
|
+
...(streamingRead === undefined ? {} : { streamingRead }),
|
|
150
|
+
...(streamingWrite === undefined ? {} : { streamingWrite }),
|
|
151
|
+
...(retainedRead === undefined ? {} : { retainedRead }),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async confineExtraction(roots, options = {}) {
|
|
155
|
+
options.signal?.throwIfAborted();
|
|
156
|
+
const root = this.select("/").backend;
|
|
157
|
+
const captured = [...roots];
|
|
158
|
+
for (const path of captured) {
|
|
159
|
+
validatePath(path);
|
|
160
|
+
if (normalizePath(globalPath(path)) !== path)
|
|
161
|
+
fail("EINVAL");
|
|
162
|
+
// A backing confinement retains its own root-to-destination ancestry.
|
|
163
|
+
// It cannot retain directories belonging to another mounted backend.
|
|
164
|
+
if (this.select(path).path !== "/")
|
|
165
|
+
fail("ENOTSUP");
|
|
166
|
+
}
|
|
167
|
+
if (!root.confineExtraction)
|
|
168
|
+
fail("ENOTSUP");
|
|
169
|
+
const confined = await root.confineExtraction(captured, options);
|
|
170
|
+
options.signal?.throwIfAborted();
|
|
171
|
+
const observations = new Set(["prepareDirectoryAncestry", "prepareStagingResolution"]);
|
|
172
|
+
const backing = new Proxy(confined, {
|
|
173
|
+
get(target, key) {
|
|
174
|
+
// These only capture/validate bindings. Mutations must always use the
|
|
175
|
+
// backend's confined view, including creation, metadata and hardlinks.
|
|
176
|
+
const owner = observations.has(key) ? root : target;
|
|
177
|
+
const value = Reflect.get(owner, key);
|
|
178
|
+
return typeof value === "function" ? value.bind(owner) : value;
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
return new MountFileSystem({ root: backing, mounts: Object.fromEntries(this.mounts.filter(mount => mount.path !== "/").map(mount => [mount.path,
|
|
182
|
+
mount.backend.capabilities.readOnly === true ? mount.backend : createReadOnlyFileSystem(mount.backend)])) });
|
|
183
|
+
}
|
|
184
|
+
select(path) {
|
|
185
|
+
return this.mounts.find((mount) => within(mount.path, path));
|
|
186
|
+
}
|
|
187
|
+
async capabilitiesFor(path, options = {}) {
|
|
188
|
+
return this.operation("capabilitiesFor", path, options, async () => {
|
|
189
|
+
if (options.stagingResolution === true && normalizePath(globalPath(path)) !== path)
|
|
190
|
+
fail("EINVAL");
|
|
191
|
+
const location = await this.resolve(path, options, {
|
|
192
|
+
allowMissing: options.create ?? true,
|
|
193
|
+
followFinal: options.stagingResolution !== true && (options.create !== undefined || options.creation !== "exclusive"),
|
|
194
|
+
...(options.create === undefined ? {} : { resizeCreate: options.create }),
|
|
195
|
+
});
|
|
196
|
+
const observed = ownedMutationCapabilities(location.mount.backend, await location.mount.backend.capabilitiesFor?.(location.local, options)
|
|
197
|
+
?? location.mount.backend.capabilities);
|
|
198
|
+
const declared = observed.descriptorWriteStream === true
|
|
199
|
+
&& (typeof location.mount.backend.writeStream !== "function" || observed.readOnly === true || observed.streamingWrite === false)
|
|
200
|
+
? { ...observed, descriptorWriteStream: false } : observed;
|
|
201
|
+
const resize = declared.atomicResize === true && (typeof location.mount.backend.resizeFile !== "function" || declared.readOnly === true)
|
|
202
|
+
? { ...declared, atomicResize: false } : declared;
|
|
203
|
+
const ancestry = options.stagingAncestry === true && location.path === normalizePath(globalPath(path))
|
|
204
|
+
&& await this.supportsStagingAncestry(location, resize, options);
|
|
205
|
+
const validation = options.stagingAncestry === true ? location.stat?.type === "directory"
|
|
206
|
+
&& location.path === normalizePath(globalPath(path)) && await this.supportsDirectoryValidation(location.path, options) : undefined;
|
|
207
|
+
let resolution;
|
|
208
|
+
if (options.stagingResolution === true) {
|
|
209
|
+
resolution = false;
|
|
210
|
+
if (within(location.mount.path, path) && typeof location.mount.backend.prepareStagingResolution === "function") {
|
|
211
|
+
const input = location.mount.path === "/" ? path : path.slice(location.mount.path.length) || "/";
|
|
212
|
+
const declared = input === location.local ? resize : ownedMutationCapabilities(location.mount.backend, await location.mount.backend.capabilitiesFor?.(input, options) ?? location.mount.backend.capabilities);
|
|
213
|
+
options.signal?.throwIfAborted();
|
|
214
|
+
resolution = declared.synchronousStagingResolution === true && await this.supportsStagingAncestry(location, resize, options);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const conditionalChmod = options.conditionalChmod === true
|
|
218
|
+
? resize.conditionalChmod === true && typeof location.mount.backend.chmod === "function"
|
|
219
|
+
&& await this.supportsDirectoryValidation(location.path.slice(0, location.path.lastIndexOf("/")) || "/", options, true)
|
|
220
|
+
: this.capabilities.conditionalChmod;
|
|
221
|
+
const { synchronousDirectoryValidation: ignoredValidation, synchronousStagingResolution: ignoredResolution, ...ordinary } = resize;
|
|
222
|
+
const withOpen = { ...ordinary, retainedStagingWrite: false, ...(conditionalChmod === undefined ? {} : { conditionalChmod }), ...(resolution === undefined ? {} : { synchronousStagingResolution: resolution }), ...(validation === undefined ? {} : { synchronousDirectoryValidation: validation }), atomicStagingAncestry: ancestry, ...(typeof location.mount.backend.open === "function" ? {} : { open: false }) };
|
|
223
|
+
const capabilities = location.synthetic ? { ...withOpen, open: false, retainedRead: false }
|
|
224
|
+
: retainedResizeCapabilities(location.mount.backend, retainedReadCapabilities(location.mount.backend, withOpen));
|
|
225
|
+
if (location.synthetic)
|
|
226
|
+
return readOnlyCapabilities(capabilities);
|
|
227
|
+
if (this.mounts.length === 1 || capabilities.readOnly === true)
|
|
228
|
+
return Object.freeze({ ...capabilities });
|
|
229
|
+
const { rename: ignoredRename, copy: ignoredCopy, exclusiveCopy: ignoredExclusiveCopy, ...selected } = capabilities;
|
|
230
|
+
const cannotPublish = capabilities.write === false && capabilities.streamingWrite === false && capabilities.exclusiveCreate === false;
|
|
231
|
+
return Object.freeze({
|
|
232
|
+
...selected,
|
|
233
|
+
...(capabilities.copy === false && capabilities.exclusiveCopy === false && cannotPublish ? { copy: false } : {}),
|
|
234
|
+
...(capabilities.exclusiveCopy === false && capabilities.exclusiveCreate === false && capabilities.streamingWrite === false ? { exclusiveCopy: false } : {}),
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
async supportsStagingAncestry(target, capabilities, options) {
|
|
239
|
+
options.signal?.throwIfAborted();
|
|
240
|
+
if (target.synthetic || target.stat !== undefined && (target.stat.type !== "file" || compareIdentity(target.stat, target.stat) !== "same")
|
|
241
|
+
|| capabilities.atomicFileStaging !== true || capabilities.atomicStagingAncestry !== true
|
|
242
|
+
|| capabilities.guardedStagingPublication !== true || capabilities.readOnly === true)
|
|
243
|
+
return false;
|
|
244
|
+
const parent = target.path.slice(0, target.path.lastIndexOf("/")) || "/";
|
|
245
|
+
return this.supportsDirectoryValidation(parent, options);
|
|
246
|
+
}
|
|
247
|
+
async supportsDirectoryValidation(directory, options, conditionalChmod = false) {
|
|
248
|
+
const controls = options.signal === undefined ? {} : { signal: options.signal };
|
|
249
|
+
for (const path of directoryAncestryPaths(directory)) {
|
|
250
|
+
const entry = await this.lookup(path, controls);
|
|
251
|
+
if (entry.synthetic || entry.stat?.type !== "directory" || compareIdentity(entry.stat, entry.stat) !== "same")
|
|
252
|
+
return false;
|
|
253
|
+
const backend = entry.mount.backend;
|
|
254
|
+
const declared = await backend.capabilitiesFor?.(entry.local, { ...controls, stagingAncestry: true }) ?? backend.capabilities;
|
|
255
|
+
options.signal?.throwIfAborted();
|
|
256
|
+
if (declared.synchronousDirectoryValidation !== true && !(conditionalChmod && declared.conditionalChmod === true)
|
|
257
|
+
|| typeof backend.prepareDirectoryAncestry !== "function")
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
prepareDirectoryAncestry(ancestors, options = {}) {
|
|
263
|
+
return this.operation("prepareDirectoryAncestry", ancestors.at(-1)?.path ?? "/", options, () => this.prepareAncestry(ancestors, options));
|
|
264
|
+
}
|
|
265
|
+
prepareStagingResolution(path, options = {}) {
|
|
266
|
+
const controls = options.signal === undefined ? {} : { signal: options.signal };
|
|
267
|
+
return this.operation("prepareStagingResolution", path, controls, async () => {
|
|
268
|
+
if (normalizePath(globalPath(path)) !== path)
|
|
269
|
+
fail("EINVAL");
|
|
270
|
+
const observed = [];
|
|
271
|
+
const location = await this.resolve(path, controls, { followFinal: false, allowMissing: true, resolutionSteps: observed });
|
|
272
|
+
if (location.synthetic || !within(location.mount.path, path))
|
|
273
|
+
fail("ENOTSUP");
|
|
274
|
+
const backend = location.mount.backend;
|
|
275
|
+
const input = location.mount.path === "/" ? path : path.slice(location.mount.path.length) || "/";
|
|
276
|
+
const declared = ownedMutationCapabilities(backend, await backend.capabilitiesFor?.(input, { ...controls, stagingResolution: true }) ?? backend.capabilities);
|
|
277
|
+
controls.signal?.throwIfAborted();
|
|
278
|
+
if (declared.synchronousStagingResolution !== true || !backend.prepareStagingResolution)
|
|
279
|
+
fail("ENOTSUP");
|
|
280
|
+
const prefix = directoryAncestryPaths(location.mount.path).map(ancestor => {
|
|
281
|
+
const entry = observed.find(step => step.path === ancestor);
|
|
282
|
+
if (!entry)
|
|
283
|
+
fail("ENOTSUP");
|
|
284
|
+
return entry;
|
|
285
|
+
});
|
|
286
|
+
const outerGuard = await this.prepareAncestry(prefix, controls);
|
|
287
|
+
const bound = snapshotStagingResolution(await backend.prepareStagingResolution(input, controls));
|
|
288
|
+
controls.signal?.throwIfAborted();
|
|
289
|
+
const mapPath = (local) => location.mount.path === "/" ? local : `${location.mount.path}${local === "/" ? "" : local}`;
|
|
290
|
+
const map = (entry) => ({ ...entry, path: mapPath(entry.path) });
|
|
291
|
+
const traversed = bound.traversed.map(map);
|
|
292
|
+
const localObserved = observed.filter(entry => within(location.mount.path, entry.path));
|
|
293
|
+
if (mapPath(bound.path) !== location.path || localObserved.length !== traversed.length)
|
|
294
|
+
fail("EAGAIN");
|
|
295
|
+
for (const [index, before] of localObserved.entries()) {
|
|
296
|
+
const after = traversed[index];
|
|
297
|
+
if (this.select(after.path) !== location.mount)
|
|
298
|
+
fail("EACCES");
|
|
299
|
+
if (before.path !== after.path || before.linkTarget !== after.linkTarget || before.stat.type !== after.stat.type
|
|
300
|
+
|| compareIdentity(before.stat, after.stat) !== "same"
|
|
301
|
+
|| before.stat.type !== "directory" && ["revision", "size", "mode", "nlink", "mtimeMs", "ctimeMs"].some(field => before.stat[field] !== after.stat[field]))
|
|
302
|
+
fail("EAGAIN");
|
|
303
|
+
}
|
|
304
|
+
const validate = () => {
|
|
305
|
+
controls.signal?.throwIfAborted();
|
|
306
|
+
runStagingGuard(outerGuard);
|
|
307
|
+
runStagingGuard(bound.validate);
|
|
308
|
+
return true;
|
|
309
|
+
};
|
|
310
|
+
const result = snapshotStagingResolution({ ...bound, path: mapPath(bound.path),
|
|
311
|
+
ancestors: [...prefix.slice(0, -1), ...bound.ancestors.map(map)], traversed: [...prefix.slice(0, -1), ...traversed], validate });
|
|
312
|
+
runStagingGuard(validate);
|
|
313
|
+
return result;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
async prepareAncestry(ancestors, options, conditionalChmod = false) {
|
|
317
|
+
options.signal?.throwIfAborted();
|
|
318
|
+
try {
|
|
319
|
+
const entries = snapshotDirectoryAncestry(ancestors);
|
|
320
|
+
const controls = options.signal === undefined ? {} : { signal: options.signal };
|
|
321
|
+
const groups = [];
|
|
322
|
+
for (const entry of entries) {
|
|
323
|
+
const mount = this.select(entry.path);
|
|
324
|
+
let group = groups.at(-1);
|
|
325
|
+
if (group?.mount !== mount) {
|
|
326
|
+
group = { mount, entries: [] };
|
|
327
|
+
groups.push(group);
|
|
328
|
+
}
|
|
329
|
+
group.entries.push({ path: mount.path === "/" ? entry.path : entry.path.slice(mount.path.length) || "/", stat: entry.stat });
|
|
330
|
+
}
|
|
331
|
+
const guards = [];
|
|
332
|
+
for (const group of groups) {
|
|
333
|
+
controls.signal?.throwIfAborted();
|
|
334
|
+
const backend = group.mount.backend;
|
|
335
|
+
for (const entry of group.entries) {
|
|
336
|
+
let current;
|
|
337
|
+
try {
|
|
338
|
+
current = await backend.lstat(entry.path, controls);
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
controls.signal?.throwIfAborted();
|
|
342
|
+
if (["ENOENT", "ENOTDIR", "ELOOP"].includes(toFsError(error).code))
|
|
343
|
+
fail("EAGAIN");
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
controls.signal?.throwIfAborted();
|
|
347
|
+
if (current.type !== "directory")
|
|
348
|
+
fail("EAGAIN");
|
|
349
|
+
const identity = compareIdentity(current, entry.stat);
|
|
350
|
+
if (identity === "unknown")
|
|
351
|
+
fail("ENOTSUP");
|
|
352
|
+
if (identity !== "same")
|
|
353
|
+
fail("EAGAIN");
|
|
354
|
+
const declared = await backend.capabilitiesFor?.(entry.path, { ...controls, stagingAncestry: true }) ?? backend.capabilities;
|
|
355
|
+
controls.signal?.throwIfAborted();
|
|
356
|
+
if (declared.synchronousDirectoryValidation !== true && !(conditionalChmod && declared.conditionalChmod === true))
|
|
357
|
+
fail("ENOTSUP");
|
|
358
|
+
}
|
|
359
|
+
if (typeof backend.prepareDirectoryAncestry !== "function")
|
|
360
|
+
fail("ENOTSUP");
|
|
361
|
+
const guard = await backend.prepareDirectoryAncestry(group.entries, controls);
|
|
362
|
+
controls.signal?.throwIfAborted();
|
|
363
|
+
if (typeof guard !== "function")
|
|
364
|
+
fail("ENOTSUP");
|
|
365
|
+
guards.push(guard);
|
|
366
|
+
}
|
|
367
|
+
return () => {
|
|
368
|
+
controls.signal?.throwIfAborted();
|
|
369
|
+
for (const guard of guards)
|
|
370
|
+
runStagingGuard(guard);
|
|
371
|
+
return true;
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
options.signal?.throwIfAborted();
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
protected(path) {
|
|
380
|
+
return path === "/" || this.mounts.some((mount) => within(path, mount.path));
|
|
381
|
+
}
|
|
382
|
+
async openReadFile(path, options = {}) {
|
|
383
|
+
let release;
|
|
384
|
+
try {
|
|
385
|
+
release = await this.acquireNamespace(options);
|
|
386
|
+
options.signal?.throwIfAborted();
|
|
387
|
+
const location = await this.resolve(path, options);
|
|
388
|
+
if (location.synthetic)
|
|
389
|
+
fail("EISDIR");
|
|
390
|
+
return await openRetainedReadFile(location.mount.backend, location.local, options);
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
throw error ? this.error(error, "openReadFile", path, options) : error;
|
|
394
|
+
}
|
|
395
|
+
finally {
|
|
396
|
+
release?.();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async resizeFile(path, operation, options = {}) {
|
|
400
|
+
return this.operation("resizeFile", path, options, async () => {
|
|
401
|
+
const location = await this.resolve(path, options, { allowMissing: options.create === true, resizeCreate: options.create ?? false });
|
|
402
|
+
if (location.synthetic)
|
|
403
|
+
fail("EROFS");
|
|
404
|
+
const backend = location.mount.backend;
|
|
405
|
+
const capabilities = await backend.capabilitiesFor?.(location.local, options) ?? backend.capabilities;
|
|
406
|
+
options.signal?.throwIfAborted();
|
|
407
|
+
if (capabilities.readOnly === true)
|
|
408
|
+
fail("EROFS");
|
|
409
|
+
const resize = backend.resizeFile;
|
|
410
|
+
options.signal?.throwIfAborted();
|
|
411
|
+
if (capabilities.atomicResize !== true || typeof resize !== "function")
|
|
412
|
+
fail("ENOTSUP");
|
|
413
|
+
await Reflect.apply(resize, backend, [location.local, operation, options]);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
async openResizeFile(path, options = {}) {
|
|
417
|
+
let release;
|
|
418
|
+
try {
|
|
419
|
+
release = await this.acquireNamespace(options);
|
|
420
|
+
options.signal?.throwIfAborted();
|
|
421
|
+
const resolution = this.resolve(path, options, { allowMissing: options.create === true, resizeCreate: options.create ?? false });
|
|
422
|
+
const signal = options.signal;
|
|
423
|
+
const location = await (signal ? new Promise((resolve, reject) => {
|
|
424
|
+
const abort = () => { signal.removeEventListener("abort", abort); reject(signal.reason); };
|
|
425
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
426
|
+
resolution.then(value => { signal.removeEventListener("abort", abort); resolve(value); }, error => { signal.removeEventListener("abort", abort); reject(error); });
|
|
427
|
+
if (signal.aborted)
|
|
428
|
+
abort();
|
|
429
|
+
}) : resolution);
|
|
430
|
+
options.signal?.throwIfAborted();
|
|
431
|
+
if (location.synthetic)
|
|
432
|
+
fail("EROFS");
|
|
433
|
+
return await openRetainedResizeFile(location.mount.backend, location.local, options);
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
throw error ? this.error(error, "openResizeFile", path, options) : error;
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
release?.();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
error(error, syscall, path, options, dest) {
|
|
443
|
+
if (options.signal?.aborted && Object.is(error, options.signal.reason))
|
|
444
|
+
return error;
|
|
445
|
+
return new FsError(toFsError(error).code, {
|
|
446
|
+
cause: error, syscall, path: globalPath(path), ...(dest === undefined ? {} : { dest: globalPath(dest) }),
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
// Keep guest namespace changes outside every path admission/action interval.
|
|
450
|
+
// Backend references held outside this view still require backend confinement.
|
|
451
|
+
async acquireNamespace(options, mutation = false) {
|
|
452
|
+
const signal = options.signal;
|
|
453
|
+
signal?.throwIfAborted();
|
|
454
|
+
while (this.namespaceMutation || mutation && this.activeNamespaceOperations > 0) {
|
|
455
|
+
await new Promise((resolve, reject) => {
|
|
456
|
+
const wake = () => { cleanup(); resolve(); };
|
|
457
|
+
const abort = () => { cleanup(); reject(signal.reason); };
|
|
458
|
+
const cleanup = () => {
|
|
459
|
+
this.namespaceWaiters.delete(wake);
|
|
460
|
+
signal?.removeEventListener("abort", abort);
|
|
461
|
+
};
|
|
462
|
+
this.namespaceWaiters.add(wake);
|
|
463
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
464
|
+
if (signal?.aborted)
|
|
465
|
+
abort();
|
|
466
|
+
});
|
|
467
|
+
signal?.throwIfAborted();
|
|
468
|
+
}
|
|
469
|
+
this.activeNamespaceOperations++;
|
|
470
|
+
if (mutation)
|
|
471
|
+
this.namespaceMutation = true;
|
|
472
|
+
return () => {
|
|
473
|
+
this.activeNamespaceOperations--;
|
|
474
|
+
if (mutation)
|
|
475
|
+
this.namespaceMutation = false;
|
|
476
|
+
for (const wake of this.namespaceWaiters)
|
|
477
|
+
wake();
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
async operation(syscall, path, options, action, dest, preserveReceipt = false) {
|
|
481
|
+
let release;
|
|
482
|
+
try {
|
|
483
|
+
release = await this.acquireNamespace(options, [
|
|
484
|
+
"rename", "symlink", "link", "unlink", "rm", "rmdir",
|
|
485
|
+
"removeEntryConditional", "removeFileConditional", "removeTreeConditional",
|
|
486
|
+
"publishStagedFile", "removeStagedFile",
|
|
487
|
+
].includes(syscall));
|
|
488
|
+
const result = await action();
|
|
489
|
+
if (!preserveReceipt)
|
|
490
|
+
options.signal?.throwIfAborted();
|
|
491
|
+
return result;
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
throw this.error(error, syscall, path, options, dest);
|
|
495
|
+
}
|
|
496
|
+
finally {
|
|
497
|
+
release?.();
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
components(path) {
|
|
501
|
+
validatePath(path);
|
|
502
|
+
if (!path)
|
|
503
|
+
fail("ENOENT");
|
|
504
|
+
const parts = path.split("/").filter(Boolean).map((name) => ({ name }));
|
|
505
|
+
if (path.endsWith("/"))
|
|
506
|
+
parts.push({ name: ".", trailing: true });
|
|
507
|
+
return parts;
|
|
508
|
+
}
|
|
509
|
+
async lookup(path, options, parent, plannedParent = false) {
|
|
510
|
+
options.signal?.throwIfAborted();
|
|
511
|
+
const mount = this.select(path);
|
|
512
|
+
const local = mount.path === "/" ? path : path.slice(mount.path.length) || "/";
|
|
513
|
+
let stat;
|
|
514
|
+
if (!parent?.synthetic && !plannedParent || parent?.mount !== mount) {
|
|
515
|
+
try {
|
|
516
|
+
stat = await mount.backend.lstat(local, options);
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
if (toFsError(error).code !== "ENOENT")
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
options.signal?.throwIfAborted();
|
|
524
|
+
if (path === mount.path && stat?.type !== "directory")
|
|
525
|
+
fail(stat ? "ENOTDIR" : "ENOENT");
|
|
526
|
+
const synthetic = this.protected(path) && stat?.type !== "directory";
|
|
527
|
+
return { path, mount, local, stat: synthetic ? syntheticStat : stat, synthetic };
|
|
528
|
+
}
|
|
529
|
+
async resolve(path, options, settings = {}) {
|
|
530
|
+
let pending = this.components(path);
|
|
531
|
+
const stack = [await this.lookup("/", options)];
|
|
532
|
+
let recordedUnits = 0;
|
|
533
|
+
const observe = (entry, linkTarget) => {
|
|
534
|
+
if (!settings.resolutionSteps || !entry.stat)
|
|
535
|
+
return;
|
|
536
|
+
recordedUnits += entry.path.length + (linkTarget?.length ?? 0);
|
|
537
|
+
if (settings.resolutionSteps.length >= 4096 || recordedUnits > 1_048_576)
|
|
538
|
+
fail("EFBIG");
|
|
539
|
+
settings.resolutionSteps.push({ path: entry.path, stat: snapshotStat(entry.stat), ...(linkTarget === undefined ? {} : { linkTarget }) });
|
|
540
|
+
};
|
|
541
|
+
observe(stack[0]);
|
|
542
|
+
let boundary;
|
|
543
|
+
let verification;
|
|
544
|
+
let creationVerification;
|
|
545
|
+
let followedFinalLink = false;
|
|
546
|
+
const verified = async (location) => {
|
|
547
|
+
let inspection = !location.stat && settings.resizeCreate === true ? creationVerification : verification;
|
|
548
|
+
// A missing entry has no realpath. Verify its existing parent while
|
|
549
|
+
// leaving dangling final symlinks on the ordinary following path.
|
|
550
|
+
if (inspection && !location.stat && settings.allowMissing && !followedFinalLink && inspection.finalName === undefined) {
|
|
551
|
+
const separator = inspection.path.lastIndexOf("/");
|
|
552
|
+
const finalName = inspection.path.slice(separator + 1);
|
|
553
|
+
if (finalName && finalName !== "." && finalName !== "..") {
|
|
554
|
+
inspection = { ...inspection, path: inspection.path.slice(0, separator) || "/", finalName };
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
if (inspection) {
|
|
558
|
+
const canonical = await inspection.mount.backend.realpath(inspection.path, options);
|
|
559
|
+
options.signal?.throwIfAborted();
|
|
560
|
+
if (!location.stat && inspection.finalName === undefined)
|
|
561
|
+
fail("ENOTSUP");
|
|
562
|
+
validatePath(canonical);
|
|
563
|
+
if (!canonical.startsWith("/") || normalizePath(canonical) !== canonical)
|
|
564
|
+
fail("EIO");
|
|
565
|
+
if (inspection.finalName !== undefined) {
|
|
566
|
+
try {
|
|
567
|
+
await inspection.mount.backend.lstat(`${inspection.path}/${inspection.finalName}`, options);
|
|
568
|
+
options.signal?.throwIfAborted();
|
|
569
|
+
if (!location.stat && settings.allowMissing && settings.followFinal !== false)
|
|
570
|
+
fail("ENOTSUP");
|
|
571
|
+
}
|
|
572
|
+
catch (error) {
|
|
573
|
+
options.signal?.throwIfAborted();
|
|
574
|
+
if (location.stat || toFsError(error).code !== "ENOENT")
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const expected = inspection.finalName === undefined ? canonical
|
|
579
|
+
: `${canonical === "/" ? "" : canonical}/${inspection.finalName}`;
|
|
580
|
+
if (location.mount !== inspection.mount || location.local !== expected)
|
|
581
|
+
fail("ENOTSUP");
|
|
582
|
+
}
|
|
583
|
+
return location;
|
|
584
|
+
};
|
|
585
|
+
let links = 0;
|
|
586
|
+
while (pending.length > 0) {
|
|
587
|
+
options.signal?.throwIfAborted();
|
|
588
|
+
const component = pending.shift();
|
|
589
|
+
const current = stack[stack.length - 1];
|
|
590
|
+
if (current.stat?.type !== "directory")
|
|
591
|
+
fail("ENOTDIR");
|
|
592
|
+
if (component.trailing && pending.length === 0 && settings.resizeCreate !== undefined)
|
|
593
|
+
fail("EISDIR");
|
|
594
|
+
if (!current.synthetic && !settings.createDirectories?.has(current.path)) {
|
|
595
|
+
const mode = settings.resizeCreate === undefined && current.mount.backend.capabilities.permissions === false ? 0 : 1;
|
|
596
|
+
await current.mount.backend.access(current.local, mode, options);
|
|
597
|
+
}
|
|
598
|
+
if (component.name === ".")
|
|
599
|
+
continue;
|
|
600
|
+
if (component.name === "..") {
|
|
601
|
+
if (boundary && current.path === boundary.path)
|
|
602
|
+
fail("EACCES");
|
|
603
|
+
if (stack.length > 1)
|
|
604
|
+
stack.pop();
|
|
605
|
+
if (boundary && stack[stack.length - 1].mount !== boundary)
|
|
606
|
+
fail("EACCES");
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
const nextPath = `${current.path === "/" ? "" : current.path}/${component.name}`;
|
|
610
|
+
if (boundary && this.select(nextPath) !== boundary)
|
|
611
|
+
fail("EACCES");
|
|
612
|
+
if (settings.resizeCreate === true && pending.length === 1 && pending[0].trailing)
|
|
613
|
+
fail("EISDIR");
|
|
614
|
+
let next = settings.createDirectories?.get(nextPath)
|
|
615
|
+
?? await this.lookup(nextPath, options, current, settings.createDirectories?.has(current.path));
|
|
616
|
+
if (!next.stat) {
|
|
617
|
+
if (settings.createDirectories) {
|
|
618
|
+
if (current.synthetic)
|
|
619
|
+
fail("ENOTSUP");
|
|
620
|
+
this.mutable(next);
|
|
621
|
+
next = { ...next, stat: syntheticStat };
|
|
622
|
+
settings.createDirectories.set(nextPath, next);
|
|
623
|
+
}
|
|
624
|
+
else if (settings.allowMissing && (pending.length === 0
|
|
625
|
+
|| settings.missingDirectory && pending.length === 1 && pending[0].trailing)) {
|
|
626
|
+
if (current.synthetic)
|
|
627
|
+
fail("ENOTSUP");
|
|
628
|
+
return verified(next);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
fail("ENOENT");
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const final = pending.length === 0
|
|
635
|
+
|| settings.entry && pending.length === 1 && pending[0].trailing;
|
|
636
|
+
if (next.stat?.type === "symlink" && (settings.followFinal !== false || !final)) {
|
|
637
|
+
if (++links > 40)
|
|
638
|
+
fail("ELOOP");
|
|
639
|
+
if (final)
|
|
640
|
+
followedFinalLink = true;
|
|
641
|
+
boundary ??= next.mount;
|
|
642
|
+
if (boundary !== next.mount)
|
|
643
|
+
fail("EACCES");
|
|
644
|
+
if (!verification) {
|
|
645
|
+
const suffix = pending.map((part) => part.name);
|
|
646
|
+
const last = suffix.at(-1);
|
|
647
|
+
const finalName = settings.followFinal === false && last !== undefined && last !== "." && last !== ".."
|
|
648
|
+
? suffix.pop() : undefined;
|
|
649
|
+
verification = {
|
|
650
|
+
mount: next.mount,
|
|
651
|
+
path: `${next.local}${suffix.length === 0 ? "" : `/${suffix.join("/")}`}`,
|
|
652
|
+
finalName,
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
const readlink = this.optional(next, "readlink", "symlinks");
|
|
656
|
+
const target = await readlink.call(next.mount.backend, next.local, options);
|
|
657
|
+
observe(next, target);
|
|
658
|
+
const targetParts = this.components(target);
|
|
659
|
+
if (settings.resizeCreate !== undefined && targetParts.at(-1)?.trailing && pending[0]?.trailing)
|
|
660
|
+
targetParts.pop();
|
|
661
|
+
if (settings.resizeCreate === true) {
|
|
662
|
+
const remainder = [...targetParts, ...pending];
|
|
663
|
+
const finalName = remainder.at(-1)?.name;
|
|
664
|
+
if (finalName !== undefined && finalName !== "." && finalName !== "..") {
|
|
665
|
+
const parent = target.startsWith("/") ? "" : next.local.slice(0, next.local.lastIndexOf("/"));
|
|
666
|
+
creationVerification = {
|
|
667
|
+
mount: next.mount,
|
|
668
|
+
path: `${parent}/${remainder.slice(0, -1).map(part => part.name).join("/")}`,
|
|
669
|
+
finalName,
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (target.startsWith("/")) {
|
|
674
|
+
const rootIndex = stack.findIndex((entry) => entry.path === next.mount.path);
|
|
675
|
+
if (rootIndex < 0)
|
|
676
|
+
fail("EACCES");
|
|
677
|
+
stack.splice(rootIndex + 1);
|
|
678
|
+
}
|
|
679
|
+
pending = [...targetParts, ...pending];
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
observe(next);
|
|
683
|
+
stack.push(next);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return verified(stack[stack.length - 1]);
|
|
687
|
+
}
|
|
688
|
+
mutable(location) {
|
|
689
|
+
if (this.protected(location.path))
|
|
690
|
+
fail("EBUSY");
|
|
691
|
+
if (location.mount.backend.capabilities.readOnly)
|
|
692
|
+
fail("EROFS");
|
|
693
|
+
}
|
|
694
|
+
entryPath(path) {
|
|
695
|
+
const terminal = path.split("/").filter(Boolean).at(-1);
|
|
696
|
+
if (terminal === "." || terminal === "..")
|
|
697
|
+
fail("EINVAL");
|
|
698
|
+
}
|
|
699
|
+
optional(location, method, capability) {
|
|
700
|
+
const backend = location.mount.backend;
|
|
701
|
+
const implementation = backend[method];
|
|
702
|
+
if (!implementation || capability && backend.capabilities[capability] === false)
|
|
703
|
+
fail("ENOTSUP");
|
|
704
|
+
return implementation;
|
|
705
|
+
}
|
|
706
|
+
readFile(path, options = {}) {
|
|
707
|
+
return this.operation("readFile", path, options, async () => {
|
|
708
|
+
const location = await this.resolve(path, options);
|
|
709
|
+
if (location.synthetic)
|
|
710
|
+
fail("EISDIR");
|
|
711
|
+
return location.mount.backend.readFile(location.local, options);
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
open(path, options) {
|
|
715
|
+
return openFileDescriptor(globalPath(path), options, {
|
|
716
|
+
noFollow: true, positionedRead: true, positionedWrite: true, truncate: true, synchronization: "storage",
|
|
717
|
+
}, async (admitted) => {
|
|
718
|
+
let release;
|
|
719
|
+
try {
|
|
720
|
+
release = await this.acquireNamespace(admitted);
|
|
721
|
+
const location = await this.resolve(path, admitted, {
|
|
722
|
+
allowMissing: admitted.creation !== "never", followFinal: !admitted.noFollow && admitted.creation !== "exclusive",
|
|
723
|
+
});
|
|
724
|
+
if (location.synthetic)
|
|
725
|
+
fail("EISDIR");
|
|
726
|
+
if (admitted.access !== "read" || admitted.creation !== "never" || admitted.truncate || admitted.append)
|
|
727
|
+
this.mutable(location);
|
|
728
|
+
const backend = location.mount.backend;
|
|
729
|
+
const capabilities = admitted.noFollow ? backend.capabilities
|
|
730
|
+
: await backend.capabilitiesFor?.(location.local, admitted) ?? backend.capabilities;
|
|
731
|
+
if (!backend.open || capabilities.open === false)
|
|
732
|
+
fail("ENOTSUP");
|
|
733
|
+
admitted.signal?.throwIfAborted();
|
|
734
|
+
const descriptor = await backend.open(location.local, admitted);
|
|
735
|
+
try {
|
|
736
|
+
return forwardFileDescriptor(descriptor, (syscall, forwarded, action) => this.operation(syscall, path, forwarded, action), descriptor.capabilities, snapshotStat);
|
|
737
|
+
}
|
|
738
|
+
catch (error) {
|
|
739
|
+
await finishCleanup(() => descriptor.close(), true);
|
|
740
|
+
throw error;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
admitted.signal?.throwIfAborted();
|
|
745
|
+
throw this.error(error, "open", path, admitted);
|
|
746
|
+
}
|
|
747
|
+
finally {
|
|
748
|
+
release?.();
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
writeFile(path, data, options = {}) {
|
|
753
|
+
return this.operation("writeFile", path, options, async () => {
|
|
754
|
+
const location = await this.resolve(path, options, { allowMissing: true, followFinal: !options.flag?.endsWith("x") });
|
|
755
|
+
this.mutable(location);
|
|
756
|
+
await location.mount.backend.writeFile(location.local, data, options);
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
appendFile(path, data, options = {}) {
|
|
760
|
+
return this.operation("appendFile", path, options, async () => {
|
|
761
|
+
const location = await this.resolve(path, options, { allowMissing: true });
|
|
762
|
+
this.mutable(location);
|
|
763
|
+
await location.mount.backend.appendFile(location.local, data, options);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
stat(path, options = {}) {
|
|
767
|
+
return this.operation("stat", path, options, async () => snapshotStat((await this.resolve(path, options)).stat));
|
|
768
|
+
}
|
|
769
|
+
lstat(path, options = {}) {
|
|
770
|
+
return this.operation("lstat", path, options, async () => snapshotStat((await this.resolve(path, options, { followFinal: false })).stat));
|
|
771
|
+
}
|
|
772
|
+
readdir(path, options = {}) {
|
|
773
|
+
return this.operation("readdir", path, options, async () => {
|
|
774
|
+
const limit = directoryEntryLimit(options, path);
|
|
775
|
+
const location = await this.resolve(path, options);
|
|
776
|
+
if (location.stat?.type !== "directory")
|
|
777
|
+
fail("ENOTDIR");
|
|
778
|
+
const entries = new Map();
|
|
779
|
+
if (!location.synthetic) {
|
|
780
|
+
const children = await location.mount.backend.readdir(location.local, options);
|
|
781
|
+
options.signal?.throwIfAborted();
|
|
782
|
+
admitDirectoryEntries(children.length, limit, path);
|
|
783
|
+
for (const entry of children) {
|
|
784
|
+
options.signal?.throwIfAborted();
|
|
785
|
+
const { name, type } = entry;
|
|
786
|
+
if (!name || name === "." || name === ".." || name.includes("/") || name.includes("\0"))
|
|
787
|
+
fail("EIO");
|
|
788
|
+
if (!entries.has(name))
|
|
789
|
+
admitDirectoryEntries(entries.size + 1, limit, path);
|
|
790
|
+
entries.set(name, { name, type });
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
for (const mount of this.mounts) {
|
|
794
|
+
if (mount.path !== location.path && within(location.path, mount.path)) {
|
|
795
|
+
const suffix = mount.path.slice(location.path === "/" ? 1 : location.path.length + 1);
|
|
796
|
+
const name = suffix.split("/")[0];
|
|
797
|
+
if (!entries.has(name))
|
|
798
|
+
admitDirectoryEntries(entries.size + 1, limit, path);
|
|
799
|
+
entries.set(name, { name, type: "directory" });
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return [...entries.values()].sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
mkdir(path, options = {}) {
|
|
806
|
+
return this.operation("mkdir", path, options, async () => {
|
|
807
|
+
const directories = new Map();
|
|
808
|
+
const location = await this.resolve(path, options, options.recursive
|
|
809
|
+
? { createDirectories: directories }
|
|
810
|
+
: { followFinal: false, allowMissing: true, missingDirectory: true, entry: true });
|
|
811
|
+
if (options.recursive) {
|
|
812
|
+
if (location.stat?.type !== "directory")
|
|
813
|
+
fail("EEXIST");
|
|
814
|
+
for (const directory of directories.values()) {
|
|
815
|
+
options.signal?.throwIfAborted();
|
|
816
|
+
await directory.mount.backend.mkdir(directory.local, { ...options, recursive: false });
|
|
817
|
+
}
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
this.mutable(location);
|
|
821
|
+
await location.mount.backend.mkdir(location.local, options);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
rmdir(path, options = {}) {
|
|
825
|
+
return this.operation("rmdir", path, options, async () => {
|
|
826
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true });
|
|
827
|
+
this.mutable(location);
|
|
828
|
+
this.entryPath(path);
|
|
829
|
+
if (location.stat?.type !== "directory")
|
|
830
|
+
fail("ENOTDIR");
|
|
831
|
+
const backend = location.mount.backend;
|
|
832
|
+
if (!backend.rmdir)
|
|
833
|
+
fail("ENOTSUP");
|
|
834
|
+
options.signal?.throwIfAborted();
|
|
835
|
+
await backend.rmdir(location.local, options);
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
unlink(path, options = {}) {
|
|
839
|
+
return this.operation("unlink", path, options, async () => {
|
|
840
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true });
|
|
841
|
+
this.mutable(location);
|
|
842
|
+
this.entryPath(path);
|
|
843
|
+
const backend = location.mount.backend;
|
|
844
|
+
if (!backend.unlink)
|
|
845
|
+
fail("ENOTSUP");
|
|
846
|
+
options.signal?.throwIfAborted();
|
|
847
|
+
await backend.unlink(location.local, options);
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
rm(path, options = {}) {
|
|
851
|
+
return this.operation("rm", path, options, async () => {
|
|
852
|
+
let location;
|
|
853
|
+
try {
|
|
854
|
+
location = await this.resolve(path, options, { followFinal: false, entry: true });
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
if (options.force && isFsError(error, "ENOENT"))
|
|
858
|
+
return;
|
|
859
|
+
throw error;
|
|
860
|
+
}
|
|
861
|
+
this.mutable(location);
|
|
862
|
+
this.entryPath(path);
|
|
863
|
+
await location.mount.backend.rm(location.local, options);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
async localStaging(staging, options) {
|
|
867
|
+
const parent = await this.resolve(staging.parent.path, options, { followFinal: false, entry: true });
|
|
868
|
+
const directory = await this.resolve(staging.directory.path, options, { followFinal: false, entry: true });
|
|
869
|
+
const file = await this.resolve(staging.file.path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
870
|
+
if (parent.mount !== directory.mount || directory.mount !== file.mount)
|
|
871
|
+
fail("EXDEV");
|
|
872
|
+
if (this.protected(directory.path) || this.protected(file.path))
|
|
873
|
+
fail("EBUSY");
|
|
874
|
+
for (const location of [directory, file])
|
|
875
|
+
this.mutable(location);
|
|
876
|
+
return { mount: directory.mount, staging: {
|
|
877
|
+
parent: { path: parent.local, stat: staging.parent.stat },
|
|
878
|
+
directory: { path: directory.local, stat: staging.directory.stat },
|
|
879
|
+
file: { path: file.local, stat: staging.file.stat },
|
|
880
|
+
} };
|
|
881
|
+
}
|
|
882
|
+
publishFileConditional(path, source, options) {
|
|
883
|
+
return this.operation("publishFileConditional", path, options, async () => {
|
|
884
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
885
|
+
if (this.protected(location.path))
|
|
886
|
+
fail("EBUSY");
|
|
887
|
+
this.mutable(location);
|
|
888
|
+
const backend = location.mount.backend;
|
|
889
|
+
await requireOwnedMutation(backend, location.local, "atomicFilePublication", options, options.expected === null);
|
|
890
|
+
if (!backend.publishFileConditional)
|
|
891
|
+
fail("ENOTSUP");
|
|
892
|
+
return snapshotStat(await backend.publishFileConditional(location.local, source, options));
|
|
893
|
+
}, undefined, true);
|
|
894
|
+
}
|
|
895
|
+
writeFileConditional(path, data, options) {
|
|
896
|
+
return this.operation("writeFileConditional", path, options, async () => {
|
|
897
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
898
|
+
if (this.protected(location.path))
|
|
899
|
+
fail("EBUSY");
|
|
900
|
+
this.mutable(location);
|
|
901
|
+
const backend = location.mount.backend;
|
|
902
|
+
await requireOwnedMutation(backend, location.local, "atomicFileMutation", options, options.expected === null);
|
|
903
|
+
if (!backend.writeFileConditional)
|
|
904
|
+
fail("ENOTSUP");
|
|
905
|
+
return snapshotStat(await backend.writeFileConditional(location.local, data, options));
|
|
906
|
+
}, undefined, true);
|
|
907
|
+
}
|
|
908
|
+
removeEntryConditional(path, options) {
|
|
909
|
+
options = { ...options };
|
|
910
|
+
const requested = options.returnRemainingStat === true;
|
|
911
|
+
return this.operation("removeEntryConditional", path, options, async () => {
|
|
912
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
913
|
+
if (this.protected(location.path))
|
|
914
|
+
fail("EBUSY");
|
|
915
|
+
this.mutable(location);
|
|
916
|
+
const backend = location.mount.backend;
|
|
917
|
+
await requireOwnedMutation(backend, location.local, "atomicEntryRemoval", options);
|
|
918
|
+
if (requested)
|
|
919
|
+
await requireOwnedMutation(backend, location.local, "atomicEntryRemovalReceipt", options);
|
|
920
|
+
if (!backend.removeEntryConditional)
|
|
921
|
+
fail("ENOTSUP");
|
|
922
|
+
const receipt = await backend.removeEntryConditional(location.local, options);
|
|
923
|
+
return requested && receipt !== undefined ? Object.freeze(snapshotStat(receipt)) : undefined;
|
|
924
|
+
}, undefined, requested);
|
|
925
|
+
}
|
|
926
|
+
removeFileConditional(path, options) {
|
|
927
|
+
return this.operation("removeFileConditional", path, options, async () => {
|
|
928
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
929
|
+
if (this.protected(location.path))
|
|
930
|
+
fail("EBUSY");
|
|
931
|
+
this.mutable(location);
|
|
932
|
+
const backend = location.mount.backend;
|
|
933
|
+
await requireOwnedMutation(backend, location.local, "atomicFileMutation", options);
|
|
934
|
+
if (!backend.removeFileConditional)
|
|
935
|
+
fail("ENOTSUP");
|
|
936
|
+
await backend.removeFileConditional(location.local, options);
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
removeTreeConditional(path, options) {
|
|
940
|
+
return this.operation("removeTreeConditional", path, options, async () => {
|
|
941
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true });
|
|
942
|
+
if (this.protected(location.path))
|
|
943
|
+
fail("EBUSY");
|
|
944
|
+
this.mutable(location);
|
|
945
|
+
const backend = location.mount.backend;
|
|
946
|
+
await requireOwnedMutation(backend, location.local, "atomicTreeRemoval", options);
|
|
947
|
+
if (!backend.removeTreeConditional)
|
|
948
|
+
fail("ENOTSUP");
|
|
949
|
+
await backend.removeTreeConditional(location.local, options);
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
async createStagedFile(path, name, content, options) {
|
|
953
|
+
options = snapshotStagingCreation(options, path);
|
|
954
|
+
return this.operation("createStagedFile", path, options, async () => {
|
|
955
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true, missingDirectory: true });
|
|
956
|
+
if (this.protected(location.path))
|
|
957
|
+
fail("EBUSY");
|
|
958
|
+
this.mutable(location);
|
|
959
|
+
const backend = location.mount.backend;
|
|
960
|
+
await requireOwnedMutation(backend, location.local, "atomicFileStaging", options, true);
|
|
961
|
+
if (options.retainCleanup === true)
|
|
962
|
+
await requireOwnedMutation(backend, location.local, "retainedStagingCleanup", options, true);
|
|
963
|
+
if (!backend.createStagedFile)
|
|
964
|
+
fail("ENOTSUP");
|
|
965
|
+
const receipt = await backend.createStagedFile(location.local, name, content, options);
|
|
966
|
+
const map = (entry) => Object.freeze({
|
|
967
|
+
path: location.mount.path === "/" ? entry.path : `${location.mount.path}${entry.path === "/" ? "" : entry.path}`,
|
|
968
|
+
stat: Object.freeze(snapshotStat(entry.stat)),
|
|
969
|
+
});
|
|
970
|
+
try {
|
|
971
|
+
const staging = { parent: map(receipt.parent), directory: map(receipt.directory), file: map(receipt.file) };
|
|
972
|
+
if (!receipt.cleanup)
|
|
973
|
+
return Object.freeze(staging);
|
|
974
|
+
const backendCleanup = receipt.cleanup;
|
|
975
|
+
const cleanup = createStagingCleanup(staging.directory.path, controls => this.operation("removeStagedFile", staging.directory.path, controls, () => backendCleanup.remove(controls), undefined, true), () => backendCleanup.close());
|
|
976
|
+
return Object.freeze({ ...staging, cleanup });
|
|
977
|
+
}
|
|
978
|
+
catch (error) {
|
|
979
|
+
await finishCleanup(() => receipt.cleanup?.close(), true);
|
|
980
|
+
throw error;
|
|
981
|
+
}
|
|
982
|
+
}, undefined, true);
|
|
983
|
+
}
|
|
984
|
+
publishStagedFile(staging, destination, options) {
|
|
985
|
+
return this.operation("publishStagedFile", staging.file.path, options, async () => {
|
|
986
|
+
const ancestors = options.ancestors === undefined ? undefined : snapshotDirectoryAncestry(options.ancestors);
|
|
987
|
+
const callerGuard = options.commitGuard;
|
|
988
|
+
let guard;
|
|
989
|
+
if (ancestors) {
|
|
990
|
+
const canonical = normalizePath(globalPath(destination));
|
|
991
|
+
const parent = canonical.slice(0, canonical.lastIndexOf("/")) || "/";
|
|
992
|
+
if (canonical !== destination || ancestors.at(-1)?.path !== parent)
|
|
993
|
+
fail("EINVAL");
|
|
994
|
+
guard = await this.prepareAncestry(ancestors, options);
|
|
995
|
+
runStagingGuard(guard);
|
|
996
|
+
}
|
|
997
|
+
const local = await this.localStaging(staging, options);
|
|
998
|
+
const target = await this.resolve(destination, options, { followFinal: false, entry: true, allowMissing: true });
|
|
999
|
+
if (ancestors) {
|
|
1000
|
+
if (target.path !== destination)
|
|
1001
|
+
fail("EAGAIN");
|
|
1002
|
+
if (options.destination === null) {
|
|
1003
|
+
if (target.stat !== undefined)
|
|
1004
|
+
fail("EAGAIN");
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
if (target.stat === undefined || target.stat.type !== options.destination.type)
|
|
1008
|
+
fail("EAGAIN");
|
|
1009
|
+
const identity = compareIdentity(target.stat, options.destination);
|
|
1010
|
+
if (identity === "unknown")
|
|
1011
|
+
fail("ENOTSUP");
|
|
1012
|
+
if (identity !== "same")
|
|
1013
|
+
fail("EAGAIN");
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
if (this.protected(target.path))
|
|
1017
|
+
fail("EBUSY");
|
|
1018
|
+
if (local.mount !== target.mount)
|
|
1019
|
+
fail("EXDEV");
|
|
1020
|
+
this.mutable(target);
|
|
1021
|
+
await requireOwnedMutation(local.mount.backend, local.staging.directory.path, "atomicFileStaging", options);
|
|
1022
|
+
await requireOwnedMutation(local.mount.backend, target.local, "atomicFileStaging", options, options.destination === null);
|
|
1023
|
+
if (!local.mount.backend.publishStagedFile)
|
|
1024
|
+
fail("ENOTSUP");
|
|
1025
|
+
if (ancestors || callerGuard !== undefined)
|
|
1026
|
+
await requireOwnedMutation(local.mount.backend, target.local, "guardedStagingPublication", options, options.destination === null);
|
|
1027
|
+
if (!ancestors) {
|
|
1028
|
+
await local.mount.backend.publishStagedFile(local.staging, target.local, options);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const parent = target.path.slice(0, target.path.lastIndexOf("/")) || "/";
|
|
1032
|
+
if (target.path !== normalizePath(globalPath(destination)) || ancestors.at(-1)?.path !== parent)
|
|
1033
|
+
fail("EINVAL");
|
|
1034
|
+
try {
|
|
1035
|
+
const declared = await local.mount.backend.capabilitiesFor?.(target.local, { ...options, stagingAncestry: true, ...(options.destination === null ? { create: true } : {}) }) ?? local.mount.backend.capabilities;
|
|
1036
|
+
if (!await this.supportsStagingAncestry(target, declared, options))
|
|
1037
|
+
fail("ENOTSUP");
|
|
1038
|
+
}
|
|
1039
|
+
catch (error) {
|
|
1040
|
+
options.signal?.throwIfAborted();
|
|
1041
|
+
if (["ENOTSUP", "ENOENT", "ENOTDIR", "ELOOP"].includes(toFsError(error).code)) {
|
|
1042
|
+
await inspectStagingBindings(async (path) => {
|
|
1043
|
+
const entry = await this.lookup(path, options);
|
|
1044
|
+
if (!entry.stat)
|
|
1045
|
+
fail("ENOENT");
|
|
1046
|
+
return entry.stat;
|
|
1047
|
+
}, destination, options);
|
|
1048
|
+
}
|
|
1049
|
+
throw error;
|
|
1050
|
+
}
|
|
1051
|
+
const first = ancestors.findIndex(entry => entry.path === target.mount.path);
|
|
1052
|
+
if (first < 0)
|
|
1053
|
+
fail("EINVAL");
|
|
1054
|
+
const localAncestors = ancestors.slice(first).map(entry => ({
|
|
1055
|
+
path: target.mount.path === "/" ? entry.path : entry.path.slice(target.mount.path.length) || "/", stat: entry.stat,
|
|
1056
|
+
}));
|
|
1057
|
+
await local.mount.backend.publishStagedFile(local.staging, target.local, {
|
|
1058
|
+
...options, ancestors: localAncestors,
|
|
1059
|
+
commitGuard: () => {
|
|
1060
|
+
if (callerGuard !== undefined)
|
|
1061
|
+
runStagingGuard(callerGuard);
|
|
1062
|
+
runStagingGuard(guard);
|
|
1063
|
+
return true;
|
|
1064
|
+
},
|
|
1065
|
+
});
|
|
1066
|
+
}, destination, true);
|
|
1067
|
+
}
|
|
1068
|
+
removeStagedFile(staging, options = {}) {
|
|
1069
|
+
return this.operation("removeStagedFile", staging.directory.path, options, async () => {
|
|
1070
|
+
const local = await this.localStaging(staging, options);
|
|
1071
|
+
await requireOwnedMutation(local.mount.backend, local.staging.directory.path, "atomicFileStaging", options);
|
|
1072
|
+
if (!local.mount.backend.removeStagedFile)
|
|
1073
|
+
fail("ENOTSUP");
|
|
1074
|
+
await local.mount.backend.removeStagedFile(local.staging, options);
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1077
|
+
prepareDirectory(path, options) {
|
|
1078
|
+
return this.operation("prepareDirectory", path, options, async () => {
|
|
1079
|
+
const location = await this.resolve(path, options, { followFinal: false, entry: true, allowMissing: true, missingDirectory: true });
|
|
1080
|
+
if (this.protected(location.path))
|
|
1081
|
+
fail("EBUSY");
|
|
1082
|
+
this.mutable(location);
|
|
1083
|
+
await requireOwnedMutation(location.mount.backend, location.local, "atomicDirectoryMetadata", options, options.expected === null);
|
|
1084
|
+
if (!location.mount.backend.prepareDirectory)
|
|
1085
|
+
fail("ENOTSUP");
|
|
1086
|
+
return snapshotStat(await location.mount.backend.prepareDirectory(location.local, options));
|
|
1087
|
+
}, undefined, true);
|
|
1088
|
+
}
|
|
1089
|
+
rename(source, destination, options = {}) {
|
|
1090
|
+
return this.operation("rename", source, options, async () => {
|
|
1091
|
+
const origin = await this.resolve(source, options, { followFinal: false, entry: true });
|
|
1092
|
+
const target = await this.resolve(destination, options, {
|
|
1093
|
+
followFinal: false, allowMissing: true, entry: true, missingDirectory: origin.stat?.type === "directory",
|
|
1094
|
+
});
|
|
1095
|
+
if (this.protected(origin.path) || this.protected(target.path))
|
|
1096
|
+
fail("EBUSY");
|
|
1097
|
+
if (origin.mount !== target.mount)
|
|
1098
|
+
fail("EXDEV");
|
|
1099
|
+
this.mutable(origin);
|
|
1100
|
+
this.mutable(target);
|
|
1101
|
+
this.entryPath(source);
|
|
1102
|
+
this.entryPath(destination);
|
|
1103
|
+
if (options.noReplace) {
|
|
1104
|
+
const capabilities = await target.mount.backend.capabilitiesFor?.(target.local, options) ?? target.mount.backend.capabilities;
|
|
1105
|
+
options.signal?.throwIfAborted();
|
|
1106
|
+
if (capabilities.atomicRenameNoReplace !== true)
|
|
1107
|
+
fail("ENOTSUP");
|
|
1108
|
+
}
|
|
1109
|
+
await origin.mount.backend.rename(origin.local, target.local, options);
|
|
1110
|
+
}, destination);
|
|
1111
|
+
}
|
|
1112
|
+
copyFile(source, destination, options = {}) {
|
|
1113
|
+
return this.operation("copyFile", source, options, async () => {
|
|
1114
|
+
const origin = await this.resolve(source, options);
|
|
1115
|
+
if (origin.stat?.type === "directory")
|
|
1116
|
+
fail("EISDIR");
|
|
1117
|
+
const target = await this.resolve(destination, options, { allowMissing: true, followFinal: !options.exclusive });
|
|
1118
|
+
if (this.protected(target.path))
|
|
1119
|
+
fail("EBUSY");
|
|
1120
|
+
this.mutable(target);
|
|
1121
|
+
if (options.exclusive && target.stat)
|
|
1122
|
+
fail("EEXIST");
|
|
1123
|
+
if (origin.mount.backend === target.mount.backend && origin.local === target.local)
|
|
1124
|
+
fail("EINVAL");
|
|
1125
|
+
let identity = compareIdentity(origin.stat, target.stat);
|
|
1126
|
+
if (identity === "same")
|
|
1127
|
+
fail("EINVAL");
|
|
1128
|
+
if (target.stat?.type === "directory")
|
|
1129
|
+
fail("EISDIR");
|
|
1130
|
+
if (target.stat && identity === "unknown") {
|
|
1131
|
+
identity = await compareEntries(origin.mount.backend, origin.local, target.mount.backend, target.local, options);
|
|
1132
|
+
if (identity === "same")
|
|
1133
|
+
fail("EINVAL");
|
|
1134
|
+
}
|
|
1135
|
+
if (target.stat && identity === "unknown")
|
|
1136
|
+
fail("ENOTSUP");
|
|
1137
|
+
if (origin.mount.backend === target.mount.backend) {
|
|
1138
|
+
await origin.mount.backend.copyFile(origin.local, target.local, { ...options, exclusive: options.exclusive || !target.stat });
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
const reader = origin.mount.backend;
|
|
1142
|
+
const writer = target.mount.backend;
|
|
1143
|
+
const writeOptions = {
|
|
1144
|
+
...(options.signal ? { signal: options.signal } : {}), flag: options.exclusive || !target.stat ? "wx" : "w",
|
|
1145
|
+
...(writer.capabilities.permissions === true ? { mode: origin.stat.mode & 0o7777 } : {}),
|
|
1146
|
+
};
|
|
1147
|
+
if (reader.readStream && reader.capabilities.streamingRead !== false
|
|
1148
|
+
&& writer.writeStream && writer.capabilities.streamingWrite !== false) {
|
|
1149
|
+
const source = readBytes(reader.readStream(origin.local, options), options.signal);
|
|
1150
|
+
let failed = false;
|
|
1151
|
+
try {
|
|
1152
|
+
await writer.writeStream(target.local, source, writeOptions);
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
failed = true;
|
|
1156
|
+
throw error;
|
|
1157
|
+
}
|
|
1158
|
+
finally {
|
|
1159
|
+
await finishCleanup(() => source.return(undefined), failed);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
const data = await reader.readFile(origin.local, options);
|
|
1164
|
+
options.signal?.throwIfAborted();
|
|
1165
|
+
await writer.writeFile(target.local, data, writeOptions);
|
|
1166
|
+
}
|
|
1167
|
+
}, destination);
|
|
1168
|
+
}
|
|
1169
|
+
realpath(path, options = {}) {
|
|
1170
|
+
return this.operation("realpath", path, options, async () => (await this.resolve(path, options)).path);
|
|
1171
|
+
}
|
|
1172
|
+
compareEntry(path, peer, peerPath, options = {}) {
|
|
1173
|
+
return this.operation("compareEntry", path, options, () => compareEntries(this, path, peer, peerPath, options), peerPath);
|
|
1174
|
+
}
|
|
1175
|
+
access(path, mode = 0, options = {}) {
|
|
1176
|
+
return this.operation("access", path, options, async () => {
|
|
1177
|
+
if (!Number.isInteger(mode) || mode < 0 || mode > 7)
|
|
1178
|
+
fail("EINVAL");
|
|
1179
|
+
const location = await this.resolve(path, options);
|
|
1180
|
+
if (location.synthetic) {
|
|
1181
|
+
if (mode & 2)
|
|
1182
|
+
fail("EACCES");
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
await location.mount.backend.access(location.local, mode, options);
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
readlink(path, options = {}) {
|
|
1190
|
+
return this.operation("readlink", path, options, async () => {
|
|
1191
|
+
const location = await this.resolve(path, options, { followFinal: false });
|
|
1192
|
+
if (location.stat?.type !== "symlink")
|
|
1193
|
+
fail("EINVAL");
|
|
1194
|
+
return this.optional(location, "readlink", "symlinks").call(location.mount.backend, location.local, options);
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
symlink(target, path, options = {}) {
|
|
1198
|
+
return this.operation("symlink", path, options, async () => {
|
|
1199
|
+
this.components(target);
|
|
1200
|
+
const location = await this.resolve(path, options, { followFinal: false, allowMissing: true });
|
|
1201
|
+
this.mutable(location);
|
|
1202
|
+
await this.optional(location, "symlink", "symlinks").call(location.mount.backend, target, location.local, options);
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
link(existingPath, newPath, options = {}) {
|
|
1206
|
+
return this.operation("link", existingPath, options, async () => {
|
|
1207
|
+
const origin = await this.resolve(existingPath, options, { followFinal: false, entry: true });
|
|
1208
|
+
const target = await this.resolve(newPath, options, { followFinal: false, allowMissing: true, entry: true });
|
|
1209
|
+
if (this.protected(origin.path) || this.protected(target.path))
|
|
1210
|
+
fail("EBUSY");
|
|
1211
|
+
if (origin.mount !== target.mount)
|
|
1212
|
+
fail("EXDEV");
|
|
1213
|
+
this.mutable(origin);
|
|
1214
|
+
this.mutable(target);
|
|
1215
|
+
await this.optional(origin, "link", "hardlinks").call(origin.mount.backend, origin.local, target.local, options);
|
|
1216
|
+
}, newPath);
|
|
1217
|
+
}
|
|
1218
|
+
chmod(path, mode, options = {}) {
|
|
1219
|
+
return this.operation("chmod", path, options, async () => {
|
|
1220
|
+
const conditional = snapshotConditionalChmod(path, options);
|
|
1221
|
+
const controls = options.signal === undefined ? {} : { signal: options.signal };
|
|
1222
|
+
const location = await this.resolve(path, controls, conditional ? { followFinal: false } : {});
|
|
1223
|
+
this.mutable(location);
|
|
1224
|
+
const chmod = this.optional(location, "chmod", "permissions");
|
|
1225
|
+
if (!conditional)
|
|
1226
|
+
return chmod.call(location.mount.backend, location.local, mode, controls);
|
|
1227
|
+
if (location.path !== path)
|
|
1228
|
+
fail("EAGAIN");
|
|
1229
|
+
const backend = location.mount.backend;
|
|
1230
|
+
const capabilities = await backend.capabilitiesFor?.(location.local, { ...controls, conditionalChmod: true }) ?? backend.capabilities;
|
|
1231
|
+
if (capabilities.conditionalChmod !== true)
|
|
1232
|
+
fail("ENOTSUP");
|
|
1233
|
+
const guard = await this.prepareAncestry(conditional.ancestors, controls, true);
|
|
1234
|
+
const ancestors = conditional.ancestors.filter(entry => this.select(entry.path) === location.mount).map(entry => ({
|
|
1235
|
+
path: location.mount.path === "/" ? entry.path : entry.path.slice(location.mount.path.length) || "/", stat: entry.stat,
|
|
1236
|
+
}));
|
|
1237
|
+
await chmod.call(backend, location.local, mode, { ...conditional, ancestors, commitGuard: () => {
|
|
1238
|
+
if (conditional.commitGuard)
|
|
1239
|
+
runStagingGuard(conditional.commitGuard);
|
|
1240
|
+
runStagingGuard(guard);
|
|
1241
|
+
return true;
|
|
1242
|
+
} });
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
utimes(path, atimeMs, mtimeMs, options = {}) {
|
|
1246
|
+
return this.operation("utimes", path, options, async () => {
|
|
1247
|
+
const location = await this.resolve(path, options);
|
|
1248
|
+
this.mutable(location);
|
|
1249
|
+
await this.optional(location, "utimes", "timestamps").call(location.mount.backend, location.local, atimeMs, mtimeMs, options);
|
|
1250
|
+
});
|
|
1251
|
+
}
|
|
1252
|
+
truncate(path, length = 0, options = {}) {
|
|
1253
|
+
return this.operation("truncate", path, options, async () => {
|
|
1254
|
+
const location = await this.resolve(path, options);
|
|
1255
|
+
this.mutable(location);
|
|
1256
|
+
await this.optional(location, "truncate").call(location.mount.backend, location.local, length, options);
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
async *readStream(path, options = {}) {
|
|
1260
|
+
let release;
|
|
1261
|
+
try {
|
|
1262
|
+
release = await this.acquireNamespace(options);
|
|
1263
|
+
options.signal?.throwIfAborted();
|
|
1264
|
+
const location = await this.resolve(path, options);
|
|
1265
|
+
if (location.synthetic)
|
|
1266
|
+
fail("EISDIR");
|
|
1267
|
+
const source = this.optional(location, "readStream", "streamingRead").call(location.mount.backend, location.local, options);
|
|
1268
|
+
for await (const chunk of readBytes(source, options.signal)) {
|
|
1269
|
+
options.signal?.throwIfAborted();
|
|
1270
|
+
yield chunk;
|
|
1271
|
+
}
|
|
1272
|
+
options.signal?.throwIfAborted();
|
|
1273
|
+
}
|
|
1274
|
+
catch (error) {
|
|
1275
|
+
throw this.error(error, "readStream", path, options);
|
|
1276
|
+
}
|
|
1277
|
+
finally {
|
|
1278
|
+
release?.();
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
writeStream(path, source, options = {}) {
|
|
1282
|
+
return this.operation("writeStream", path, options, async () => {
|
|
1283
|
+
const location = await this.resolve(path, options, { allowMissing: true, followFinal: !options.flag?.endsWith("x") });
|
|
1284
|
+
this.mutable(location);
|
|
1285
|
+
await this.optional(location, "writeStream", "streamingWrite").call(location.mount.backend, location.local, source, options);
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
export function createMountFileSystem(options) {
|
|
1290
|
+
return new MountFileSystem(options);
|
|
1291
|
+
}
|