@openclaw/fs-safe 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +36 -7
  3. package/dist/absolute-path.d.ts.map +1 -1
  4. package/dist/absolute-path.js +2 -8
  5. package/dist/advanced.d.ts +3 -0
  6. package/dist/advanced.d.ts.map +1 -1
  7. package/dist/advanced.js +3 -0
  8. package/dist/archive-deadline.d.ts.map +1 -1
  9. package/dist/archive-deadline.js +22 -23
  10. package/dist/archive-kind.d.ts +0 -1
  11. package/dist/archive-kind.d.ts.map +1 -1
  12. package/dist/archive-kind.js +5 -17
  13. package/dist/archive-merge.d.ts +1 -0
  14. package/dist/archive-merge.d.ts.map +1 -1
  15. package/dist/archive-merge.js +4 -4
  16. package/dist/archive-native.d.ts +1 -0
  17. package/dist/archive-native.d.ts.map +1 -1
  18. package/dist/archive-native.js +1 -0
  19. package/dist/archive-options.d.ts +2 -0
  20. package/dist/archive-options.d.ts.map +1 -1
  21. package/dist/archive-parser.wasm +0 -0
  22. package/dist/archive-read.d.ts.map +1 -1
  23. package/dist/archive-read.js +6 -7
  24. package/dist/archive-tar-stream.d.ts +3 -0
  25. package/dist/archive-tar-stream.d.ts.map +1 -1
  26. package/dist/archive-tar-stream.js +56 -37
  27. package/dist/archive-tar-wasm.d.ts +16 -4
  28. package/dist/archive-tar-wasm.d.ts.map +1 -1
  29. package/dist/archive-tar-wasm.js +134 -34
  30. package/dist/archive-zip-count.d.ts.map +1 -1
  31. package/dist/archive-zip-count.js +21 -1
  32. package/dist/archive-zip-directory.d.ts.map +1 -1
  33. package/dist/archive-zip-directory.js +23 -1
  34. package/dist/archive-zip-loader.d.ts +2 -0
  35. package/dist/archive-zip-loader.d.ts.map +1 -1
  36. package/dist/archive-zip-loader.js +7 -0
  37. package/dist/archive-zip-names.d.ts.map +1 -1
  38. package/dist/archive-zip-names.js +7 -2
  39. package/dist/archive.d.ts.map +1 -1
  40. package/dist/archive.js +14 -9
  41. package/dist/byte-view.d.ts +3 -0
  42. package/dist/byte-view.d.ts.map +1 -0
  43. package/dist/byte-view.js +13 -0
  44. package/dist/clone-metadata.d.ts +1 -0
  45. package/dist/clone-metadata.d.ts.map +1 -1
  46. package/dist/clone-metadata.js +6 -2
  47. package/dist/create-directory.d.ts +20 -0
  48. package/dist/create-directory.d.ts.map +1 -0
  49. package/dist/create-directory.js +130 -0
  50. package/dist/create-file-async.d.ts +7 -0
  51. package/dist/create-file-async.d.ts.map +1 -0
  52. package/dist/create-file-async.js +121 -0
  53. package/dist/create-file.d.ts +8 -0
  54. package/dist/create-file.d.ts.map +1 -0
  55. package/dist/create-file.js +190 -0
  56. package/dist/create-owned-file.d.ts +8 -0
  57. package/dist/create-owned-file.d.ts.map +1 -0
  58. package/dist/create-owned-file.js +16 -0
  59. package/dist/create.d.ts +4 -0
  60. package/dist/create.d.ts.map +1 -0
  61. package/dist/create.js +2 -0
  62. package/dist/creation-darwin.d.ts +6 -0
  63. package/dist/creation-darwin.d.ts.map +1 -0
  64. package/dist/creation-darwin.js +70 -0
  65. package/dist/creation-file-state.d.ts +19 -0
  66. package/dist/creation-file-state.d.ts.map +1 -0
  67. package/dist/creation-file-state.js +118 -0
  68. package/dist/creation-path.d.ts +21 -0
  69. package/dist/creation-path.d.ts.map +1 -0
  70. package/dist/creation-path.js +71 -0
  71. package/dist/creation-permissions.d.ts +19 -0
  72. package/dist/creation-permissions.d.ts.map +1 -0
  73. package/dist/creation-permissions.js +125 -0
  74. package/dist/directory-durability.d.ts +7 -7
  75. package/dist/directory-durability.d.ts.map +1 -1
  76. package/dist/directory-durability.js +22 -80
  77. package/dist/directory-guard.d.ts +3 -0
  78. package/dist/directory-guard.d.ts.map +1 -1
  79. package/dist/directory-mode-node.d.ts +2 -0
  80. package/dist/directory-mode-node.d.ts.map +1 -1
  81. package/dist/directory-mode-node.js +8 -0
  82. package/dist/directory-receipt.d.ts +24 -0
  83. package/dist/directory-receipt.d.ts.map +1 -0
  84. package/dist/directory-receipt.js +123 -0
  85. package/dist/file-cleanup.d.ts +20 -0
  86. package/dist/file-cleanup.d.ts.map +1 -0
  87. package/dist/file-cleanup.js +81 -0
  88. package/dist/file-contents.d.ts +6 -0
  89. package/dist/file-contents.d.ts.map +1 -0
  90. package/dist/file-contents.js +40 -0
  91. package/dist/file-hash.d.ts.map +1 -1
  92. package/dist/file-hash.js +16 -4
  93. package/dist/file-lock-sync-root-acquire.d.ts.map +1 -1
  94. package/dist/file-lock-sync-root-acquire.js +3 -0
  95. package/dist/file-lock-sync-root-held.d.ts +1 -2
  96. package/dist/file-lock-sync-root-held.d.ts.map +1 -1
  97. package/dist/file-lock-sync-root-held.js +7 -5
  98. package/dist/file-lock-sync-stale-admission.d.ts.map +1 -1
  99. package/dist/file-lock-sync-stale-admission.js +3 -0
  100. package/dist/file-lock-sync.d.ts.map +1 -1
  101. package/dist/file-lock-sync.js +8 -11
  102. package/dist/file-observation.d.ts +1 -1
  103. package/dist/file-observation.d.ts.map +1 -1
  104. package/dist/file-store-boundary.d.ts +2 -6
  105. package/dist/file-store-boundary.d.ts.map +1 -1
  106. package/dist/file-store-boundary.js +3 -9
  107. package/dist/file-store-sync-write.d.ts.map +1 -1
  108. package/dist/file-store-sync-write.js +2 -5
  109. package/dist/file-store.js +3 -3
  110. package/dist/guarded-mkdir.d.ts +1 -0
  111. package/dist/guarded-mkdir.d.ts.map +1 -1
  112. package/dist/guarded-mkdir.js +27 -19
  113. package/dist/install-path.d.ts.map +1 -1
  114. package/dist/install-path.js +2 -5
  115. package/dist/json-durable-queue-ownership.d.ts.map +1 -1
  116. package/dist/json-durable-queue-ownership.js +2 -6
  117. package/dist/json-durable-queue-paths.d.ts.map +1 -1
  118. package/dist/json-durable-queue-paths.js +2 -24
  119. package/dist/json-durable-queue.d.ts.map +1 -1
  120. package/dist/json-durable-queue.js +10 -9
  121. package/dist/json.d.ts.map +1 -1
  122. package/dist/json.js +32 -75
  123. package/dist/local-roots.d.ts.map +1 -1
  124. package/dist/local-roots.js +19 -21
  125. package/dist/move-path-cleanup.d.ts +5 -19
  126. package/dist/move-path-cleanup.d.ts.map +1 -1
  127. package/dist/move-path-cleanup.js +57 -21
  128. package/dist/move-path.d.ts.map +1 -1
  129. package/dist/move-path.js +63 -40
  130. package/dist/native-binding.d.ts +11 -1
  131. package/dist/native-binding.d.ts.map +1 -1
  132. package/dist/native-fallback-warning.d.ts +4 -0
  133. package/dist/native-fallback-warning.d.ts.map +1 -0
  134. package/dist/native-fallback-warning.js +11 -0
  135. package/dist/native-operations.d.ts +0 -2
  136. package/dist/native-operations.d.ts.map +1 -1
  137. package/dist/native-operations.js +0 -24
  138. package/dist/native-parent-admission.d.ts +2 -0
  139. package/dist/native-parent-admission.d.ts.map +1 -1
  140. package/dist/native-parent-admission.js +3 -2
  141. package/dist/native-pinned-write-windows.d.ts +1 -1
  142. package/dist/native-pinned-write-windows.d.ts.map +1 -1
  143. package/dist/native-pinned-write-windows.js +173 -28
  144. package/dist/native-pinned-write.d.ts.map +1 -1
  145. package/dist/native-pinned-write.js +19 -3
  146. package/dist/native-policy-parent-windows.d.ts.map +1 -1
  147. package/dist/native-policy-parent-windows.js +15 -6
  148. package/dist/native-staged-file.d.ts +5 -3
  149. package/dist/native-staged-file.d.ts.map +1 -1
  150. package/dist/native-staged-file.js +90 -40
  151. package/dist/native.js +2 -2
  152. package/dist/opened-realpath.d.ts.map +1 -1
  153. package/dist/opened-realpath.js +11 -2
  154. package/dist/owner-dacl.d.ts.map +1 -1
  155. package/dist/owner-dacl.js +10 -4
  156. package/dist/path.d.ts.map +1 -1
  157. package/dist/path.js +2 -1
  158. package/dist/permissions.d.ts.map +1 -1
  159. package/dist/permissions.js +3 -17
  160. package/dist/pinned-write-input.d.ts +4 -0
  161. package/dist/pinned-write-input.d.ts.map +1 -0
  162. package/dist/pinned-write-input.js +35 -0
  163. package/dist/pinned-write-mode.d.ts +5 -0
  164. package/dist/pinned-write-mode.d.ts.map +1 -0
  165. package/dist/pinned-write-mode.js +31 -0
  166. package/dist/pinned-write-staged.d.ts +6 -0
  167. package/dist/pinned-write-staged.d.ts.map +1 -0
  168. package/dist/pinned-write-staged.js +186 -0
  169. package/dist/pinned-write-types.d.ts +3 -0
  170. package/dist/pinned-write-types.d.ts.map +1 -1
  171. package/dist/pinned-write.d.ts.map +1 -1
  172. package/dist/pinned-write.js +41 -147
  173. package/dist/private-directory.d.ts.map +1 -1
  174. package/dist/private-directory.js +18 -4
  175. package/dist/private-producer-handoff-sync.d.ts +14 -0
  176. package/dist/private-producer-handoff-sync.d.ts.map +1 -0
  177. package/dist/private-producer-handoff-sync.js +114 -0
  178. package/dist/private-producer-handoff.d.ts +22 -4
  179. package/dist/private-producer-handoff.d.ts.map +1 -1
  180. package/dist/private-producer-handoff.js +140 -77
  181. package/dist/publish-copy-stage.d.ts +2 -1
  182. package/dist/publish-copy-stage.d.ts.map +1 -1
  183. package/dist/publish-copy-stage.js +16 -7
  184. package/dist/publish-file.d.ts +2 -2
  185. package/dist/publish-file.d.ts.map +1 -1
  186. package/dist/publish-file.js +58 -98
  187. package/dist/regular-file.d.ts.map +1 -1
  188. package/dist/regular-file.js +35 -44
  189. package/dist/replace-file-copy-fallback.d.ts.map +1 -1
  190. package/dist/replace-file-copy-fallback.js +28 -26
  191. package/dist/replace-file-copy-source.d.ts.map +1 -1
  192. package/dist/replace-file-copy-source.js +13 -22
  193. package/dist/replace-file-descriptor.d.ts.map +1 -1
  194. package/dist/replace-file-descriptor.js +10 -16
  195. package/dist/replace-file-temp-owner.d.ts +0 -7
  196. package/dist/replace-file-temp-owner.d.ts.map +1 -1
  197. package/dist/replace-file-temp-owner.js +9 -60
  198. package/dist/replace-file.d.ts.map +1 -1
  199. package/dist/replace-file.js +9 -13
  200. package/dist/root-create-input.d.ts +2 -1
  201. package/dist/root-create-input.d.ts.map +1 -1
  202. package/dist/root-create-input.js +13 -4
  203. package/dist/root-directory-creation.d.ts +3 -3
  204. package/dist/root-directory-creation.d.ts.map +1 -1
  205. package/dist/root-directory-creation.js +15 -3
  206. package/dist/root-directory-list.d.ts.map +1 -1
  207. package/dist/root-directory-list.js +20 -3
  208. package/dist/root-file-final-admission.d.ts +1 -1
  209. package/dist/root-file-final-admission.d.ts.map +1 -1
  210. package/dist/root-file-final-admission.js +5 -2
  211. package/dist/root-file.d.ts.map +1 -1
  212. package/dist/root-file.js +3 -2
  213. package/dist/root-impl.d.ts.map +1 -1
  214. package/dist/root-impl.js +78 -27
  215. package/dist/root-move-noreplace.d.ts +2 -0
  216. package/dist/root-move-noreplace.d.ts.map +1 -1
  217. package/dist/root-move-noreplace.js +22 -13
  218. package/dist/root-options.d.ts +12 -4
  219. package/dist/root-options.d.ts.map +1 -1
  220. package/dist/root-path-stat.d.ts.map +1 -1
  221. package/dist/root-path-stat.js +59 -7
  222. package/dist/root-read-admission.d.ts.map +1 -1
  223. package/dist/root-read-admission.js +7 -2
  224. package/dist/root-remove.d.ts.map +1 -1
  225. package/dist/root-remove.js +15 -1
  226. package/dist/root-write-publication.js +1 -1
  227. package/dist/secret-file.d.ts.map +1 -1
  228. package/dist/secret-file.js +1 -0
  229. package/dist/secure-file-windows.d.ts +6 -0
  230. package/dist/secure-file-windows.d.ts.map +1 -1
  231. package/dist/secure-file-windows.js +34 -117
  232. package/dist/secure-file.js +2 -2
  233. package/dist/sidecar-lock-acquire.d.ts.map +1 -1
  234. package/dist/sidecar-lock-acquire.js +4 -6
  235. package/dist/sidecar-lock-handle.d.ts +3 -0
  236. package/dist/sidecar-lock-handle.d.ts.map +1 -1
  237. package/dist/sidecar-lock-handle.js +6 -0
  238. package/dist/sidecar-lock-reclaim.d.ts +1 -1
  239. package/dist/sidecar-lock-reclaim.d.ts.map +1 -1
  240. package/dist/sidecar-lock-reclaim.js +11 -8
  241. package/dist/sidecar-lock-root.d.ts.map +1 -1
  242. package/dist/sidecar-lock-root.js +2 -1
  243. package/dist/sidecar-lock.d.ts.map +1 -1
  244. package/dist/sidecar-lock.js +3 -5
  245. package/dist/staged-directory.d.ts +2 -2
  246. package/dist/staged-directory.d.ts.map +1 -1
  247. package/dist/staged-directory.js +6 -6
  248. package/dist/staged-file-settlement.d.ts +17 -0
  249. package/dist/staged-file-settlement.d.ts.map +1 -0
  250. package/dist/staged-file-settlement.js +57 -0
  251. package/dist/strict-file-identity.d.ts +1 -1
  252. package/dist/strict-file-identity.d.ts.map +1 -1
  253. package/dist/strict-file-identity.js +9 -9
  254. package/dist/symlink-parents.d.ts.map +1 -1
  255. package/dist/symlink-parents.js +2 -27
  256. package/dist/temp-workspace-owner.js +4 -4
  257. package/dist/unicode-path.d.ts.map +1 -1
  258. package/dist/unicode-path.js +3 -0
  259. package/dist/walk.d.ts.map +1 -1
  260. package/dist/walk.js +4 -2
  261. package/dist/windows-owner.d.ts.map +1 -1
  262. package/dist/windows-owner.js +2 -1
  263. package/dist/windows-security-bridge.cs +336 -0
  264. package/dist/windows-security-bridge.ps1 +15 -0
  265. package/dist/windows-security-command.d.ts +26 -0
  266. package/dist/windows-security-command.d.ts.map +1 -0
  267. package/dist/windows-security-command.js +363 -0
  268. package/dist/windows-security-facts.d.ts +6 -0
  269. package/dist/windows-security-facts.d.ts.map +1 -0
  270. package/dist/windows-security-facts.js +108 -0
  271. package/dist/write-file-handle.d.ts +7 -0
  272. package/dist/write-file-handle.d.ts.map +1 -1
  273. package/dist/write-file-handle.js +23 -0
  274. package/dist/write-open-flags.d.ts.map +1 -1
  275. package/dist/write-open-flags.js +1 -8
  276. package/dist/write-queue.d.ts.map +1 -1
  277. package/dist/write-queue.js +1 -4
  278. package/docs/advanced.md +71 -2
  279. package/docs/archive.md +102 -39
  280. package/docs/atomic.md +29 -5
  281. package/docs/config.md +6 -2
  282. package/docs/contributing.md +48 -4
  283. package/docs/copy.md +2 -0
  284. package/docs/creation.md +132 -0
  285. package/docs/durability.md +59 -0
  286. package/docs/file-contents.md +68 -0
  287. package/docs/install.md +31 -7
  288. package/docs/json.md +5 -4
  289. package/docs/local-roots.md +2 -0
  290. package/docs/migrating-to-0.5.md +15 -6
  291. package/docs/migrating-to-0.6.md +9 -4
  292. package/docs/mutation-policy-proof.md +5 -3
  293. package/docs/native-helper.md +22 -9
  294. package/docs/native.md +47 -15
  295. package/docs/path.md +4 -4
  296. package/docs/permissions.md +37 -14
  297. package/docs/public-api.md +5 -0
  298. package/docs/quickstart.md +1 -1
  299. package/docs/reading.md +2 -2
  300. package/docs/regular-file.md +3 -0
  301. package/docs/root.md +43 -0
  302. package/docs/secret-file.md +11 -2
  303. package/docs/secure-file.md +9 -4
  304. package/docs/sidecar-lock.md +14 -5
  305. package/docs/staged-file.md +9 -3
  306. package/docs/store.md +3 -1
  307. package/docs/temp.md +4 -1
  308. package/docs/types.md +18 -2
  309. package/docs/walk.md +7 -0
  310. package/docs/writing.md +80 -7
  311. package/package.json +18 -15
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-owned-file.d.ts","sourceRoot":"","sources":["../src/create-owned-file.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,KAAK,IAAI,IAAI,CAAC;IACd,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;CAC1B,CAAC;AAEF,6EAA6E;AAC7E,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,OAAO,GAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAmB,GAC3C,uBAAuB,CAYzB"}
@@ -0,0 +1,16 @@
1
+ import fs from "node:fs";
2
+ /** Capture the descriptor's creator-owned closer before it can be reused. */
3
+ export function ownFileDescriptorSync(fd, closeFd = fs.closeSync) {
4
+ let open = true;
5
+ const owner = {
6
+ fd,
7
+ close() {
8
+ if (!open)
9
+ return;
10
+ open = false;
11
+ closeFd(fd);
12
+ },
13
+ [Symbol.dispose]() { owner.close(); },
14
+ };
15
+ return Object.freeze(owner);
16
+ }
@@ -0,0 +1,4 @@
1
+ export { createDirectory, createDirectorySync, createDirectoryWithAdmission, createDirectorySyncWithAdmission, type CreateDirectoryOptions, type CreationAdmission, } from "./create-directory.js";
2
+ export { createFileSync, createFileHandle, type CreateFileOptions } from "./create-file.js";
3
+ export type { OwnedFileDescriptorSync } from "./create-owned-file.js";
4
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAAE,mBAAmB,EACpC,4BAA4B,EAAE,gCAAgC,EAC9D,KAAK,sBAAsB,EAAE,KAAK,iBAAiB,GACpD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC5F,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC"}
package/dist/create.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createDirectory, createDirectorySync, createDirectoryWithAdmission, createDirectorySyncWithAdmission, } from "./create-directory.js";
2
+ export { createFileSync, createFileHandle } from "./create-file.js";
@@ -0,0 +1,6 @@
1
+ import { type BigIntStats } from "node:fs";
2
+ export declare function assertDarwinPrivateCreationAvailable(): void;
3
+ export declare function assertDarwinPrivateDirectoryMode(mode: number): void;
4
+ export declare function assertDarwinCreationAcl(fd: number, inheritanceTarget?: "file" | "directory"): void;
5
+ export declare function assertDarwinCreationDirectoryAcl(pathname: string, expected: BigIntStats, inheritanceTarget?: "file" | "directory"): void;
6
+ //# sourceMappingURL=creation-darwin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-darwin.d.ts","sourceRoot":"","sources":["../src/creation-darwin.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAe/C,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAInE;AAED,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAYlG;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,WAAW,GAChF,IAAI,CAqBN"}
@@ -0,0 +1,70 @@
1
+ import fs, {} from "node:fs";
2
+ import { inspectDirectoryIdentitySync } from "./directory-guard.js";
3
+ import { nodeDarwinDirectoryMetadataFlags, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
4
+ import { FsSafeError } from "./errors.js";
5
+ import { getNativeBinding } from "./native.js";
6
+ import { inspectFileIdentitySync } from "./strict-file-identity.js";
7
+ function inspector() {
8
+ const native = getNativeBinding();
9
+ if (typeof native?.inspectDarwinAcl !== "function") {
10
+ throw new FsSafeError("helper-unavailable", "private Darwin creation requires native descriptor ACL inspection");
11
+ }
12
+ return native.inspectDarwinAcl.bind(native);
13
+ }
14
+ export function assertDarwinPrivateCreationAvailable() {
15
+ if (process.platform === "darwin")
16
+ inspector();
17
+ }
18
+ export function assertDarwinPrivateDirectoryMode(mode) {
19
+ if (process.platform === "darwin" && ((mode & ~process.umask()) & 0o500) === 0) {
20
+ throw new FsSafeError("helper-unavailable", "private Darwin directory ACL inspection requires owner read or search permission");
21
+ }
22
+ }
23
+ export function assertDarwinCreationAcl(fd, inheritanceTarget) {
24
+ if (process.platform !== "darwin")
25
+ return;
26
+ const inspect = inspector();
27
+ const state = inspect(fd, inheritanceTarget)?.state;
28
+ if (state === "present") {
29
+ throw new FsSafeError("insecure-permissions", inheritanceTarget
30
+ ? "private creation parent has inheritable Darwin ACL entries"
31
+ : "private creation object has Darwin ACL entries");
32
+ }
33
+ if (state !== "absent" && state !== "empty") {
34
+ throw new FsSafeError("helper-unavailable", "native Darwin ACL inspection returned incomplete facts");
35
+ }
36
+ }
37
+ export function assertDarwinCreationDirectoryAcl(pathname, expected, inheritanceTarget) {
38
+ if (process.platform !== "darwin")
39
+ return;
40
+ assertDarwinPrivateCreationAvailable();
41
+ let fd;
42
+ try {
43
+ fd = fs.openSync(pathname, nodeDarwinDirectoryMetadataFlags());
44
+ }
45
+ catch (error) {
46
+ if (error.code !== "EACCES")
47
+ throw error;
48
+ const search = nodeDirectorySearchOnlyFlags();
49
+ if (!search)
50
+ throw error;
51
+ try {
52
+ fd = fs.openSync(pathname, search.flags | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
53
+ }
54
+ catch (cause) {
55
+ if (cause.code !== "EACCES")
56
+ throw cause;
57
+ throw new FsSafeError("helper-unavailable", "private Darwin directory ACL inspection requires owner read or search permission", { cause });
58
+ }
59
+ }
60
+ try {
61
+ const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }), expected);
62
+ if (!opened.isDirectory())
63
+ throw new FsSafeError("path-mismatch", "ACL target is not the admitted directory");
64
+ assertDarwinCreationAcl(fd, inheritanceTarget);
65
+ inspectDirectoryIdentitySync(pathname, expected);
66
+ }
67
+ finally {
68
+ fs.closeSync(fd);
69
+ }
70
+ }
@@ -0,0 +1,19 @@
1
+ import { type BigIntStats } from "node:fs";
2
+ import { FsSafeError } from "./errors.js";
3
+ export type CreationPublicationStatus = "not-published" | "published" | "indeterminate";
4
+ export declare function assertCreationFile(fd: number, pathname: string, expected?: BigIntStats): BigIntStats;
5
+ export declare function assertPrivateCreationFile(stat: BigIntStats, fd: number): void;
6
+ export declare function removeRecordedCreationFileSync(pathname: string, identity: BigIntStats, assertParent: () => void): void;
7
+ export declare function removeRecordedCreationFile(pathname: string, identity: BigIntStats, assertParent: () => void): Promise<void>;
8
+ export declare function creationPublicationAfterFailure(error: unknown, recorded: CreationPublicationStatus): CreationPublicationStatus;
9
+ export declare function hasPreservedCreationArtifacts(error: unknown): boolean;
10
+ export declare function rethrowPrivateStageCreationFailure(error: unknown, path: string, stageDirectory: string): never;
11
+ export declare function privateFileSettlementFailure(params: {
12
+ primary: unknown;
13
+ cleanup: readonly unknown[];
14
+ publication: CreationPublicationStatus;
15
+ path: string;
16
+ stageDirectory: string;
17
+ preserved?: boolean;
18
+ }): FsSafeError;
19
+ //# sourceMappingURL=creation-file-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-file-state.d.ts","sourceRoot":"","sources":["../src/creation-file-state.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM1C,MAAM,MAAM,yBAAyB,GAAG,eAAe,GAAG,WAAW,GAAG,eAAe,CAAC;AAExF,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,CAOpG;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAS7E;AAQD,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,GAAG,IAAI,CAUtH;AAED,wBAAsB,0BAA0B,CAC9C,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,GAChE,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,yBAAyB,GAClD,yBAAyB,CAO3B;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMrE;AAED,wBAAgB,kCAAkC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,KAAK,CAuB9G;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IAC5B,WAAW,EAAE,yBAAyB,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,WAAW,CAUd"}
@@ -0,0 +1,118 @@
1
+ import fs, {} from "node:fs";
2
+ import fsAsync from "node:fs/promises";
3
+ import { FsSafeError } from "./errors.js";
4
+ import { sameFileIdentityForCleanup } from "./file-identity.js";
5
+ import { inspectFileIdentitySync } from "./strict-file-identity.js";
6
+ import { hasUnsettledWindowsSecurityCommand } from "./windows-security-command.js";
7
+ import { assertDarwinCreationAcl } from "./creation-darwin.js";
8
+ export function assertCreationFile(fd, pathname, expected) {
9
+ const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }), expected);
10
+ const named = inspectFileIdentitySync(() => fs.lstatSync(pathname, { bigint: true }), opened);
11
+ if (!opened.isFile() || !named.isFile() || named.isSymbolicLink() || opened.nlink !== 1n || named.nlink !== 1n) {
12
+ throw new FsSafeError("path-mismatch", "created file is not the expected single-linked regular file");
13
+ }
14
+ return opened;
15
+ }
16
+ export function assertPrivateCreationFile(stat, fd) {
17
+ if (process.platform === "win32")
18
+ return;
19
+ if (typeof process.getuid !== "function" || stat.uid !== BigInt(process.getuid())) {
20
+ throw new FsSafeError("not-owned", "created private file must belong to the current user");
21
+ }
22
+ if ((stat.mode & 3647n) !== 0n) {
23
+ throw new FsSafeError("insecure-permissions", "created private file is not owner-only");
24
+ }
25
+ assertDarwinCreationAcl(fd);
26
+ }
27
+ function assertRecordedFile(current, identity) {
28
+ if (!current.isFile() || current.isSymbolicLink() || !sameFileIdentityForCleanup(current, identity)) {
29
+ throw new FsSafeError("path-mismatch", "created file cleanup preserved a replacement");
30
+ }
31
+ }
32
+ export function removeRecordedCreationFileSync(pathname, identity, assertParent) {
33
+ assertParent();
34
+ let current;
35
+ try {
36
+ current = fs.lstatSync(pathname, { bigint: true });
37
+ }
38
+ catch (error) {
39
+ if (error?.code === "ENOENT")
40
+ return;
41
+ throw error;
42
+ }
43
+ assertRecordedFile(current, identity);
44
+ fs.unlinkSync(pathname);
45
+ }
46
+ export async function removeRecordedCreationFile(pathname, identity, assertParent) {
47
+ assertParent();
48
+ let current;
49
+ try {
50
+ current = await fsAsync.lstat(pathname, { bigint: true });
51
+ }
52
+ catch (error) {
53
+ if (error?.code === "ENOENT")
54
+ return;
55
+ throw error;
56
+ }
57
+ assertParent();
58
+ assertRecordedFile(current, identity);
59
+ // Recheck after the awaited observation before dispatching the unlink.
60
+ assertRecordedFile(fs.lstatSync(pathname, { bigint: true }), identity);
61
+ await fsAsync.unlink(pathname);
62
+ }
63
+ export function creationPublicationAfterFailure(error, recorded) {
64
+ if (error instanceof FsSafeError) {
65
+ const publication = error.details?.publication;
66
+ if (publication && typeof publication === "object" && "status" in publication &&
67
+ publication.status === "indeterminate")
68
+ return "indeterminate";
69
+ }
70
+ return recorded;
71
+ }
72
+ export function hasPreservedCreationArtifacts(error) {
73
+ if (!(error instanceof FsSafeError))
74
+ return false;
75
+ if (error.details?.cleanup === "preserved" || error.details?.cleanup === "failed")
76
+ return true;
77
+ const publication = error.details?.publication;
78
+ return publication !== null && typeof publication === "object" && "status" in publication &&
79
+ (publication.status === "published" || publication.status === "indeterminate");
80
+ }
81
+ export function rethrowPrivateStageCreationFailure(error, path, stageDirectory) {
82
+ if (error instanceof FsSafeError && error.code === "already-exists") {
83
+ throw new FsSafeError("helper-failed", "private file staging path already exists", {
84
+ cause: error, details: { publication: { status: "not-published" }, path, stageDirectory },
85
+ });
86
+ }
87
+ const publication = error instanceof FsSafeError ? error.details?.publication : undefined;
88
+ const created = error instanceof FsSafeError && error.details?.path === stageDirectory &&
89
+ publication !== null && typeof publication === "object" && "status" in publication &&
90
+ publication.status === "published";
91
+ let unconfirmed = hasUnsettledWindowsSecurityCommand(error);
92
+ if (error !== null && (typeof error === "object" || typeof error === "function")) {
93
+ try {
94
+ const outcome = Object.getOwnPropertyDescriptor(error, "creationOutcome");
95
+ unconfirmed ||= Boolean(outcome && "value" in outcome && outcome.value === "unconfirmed");
96
+ }
97
+ catch {
98
+ unconfirmed = true;
99
+ }
100
+ }
101
+ if (created || unconfirmed) {
102
+ throw privateFileSettlementFailure({
103
+ primary: error, cleanup: [], publication: "not-published", path, stageDirectory, preserved: true,
104
+ });
105
+ }
106
+ throw error;
107
+ }
108
+ export function privateFileSettlementFailure(params) {
109
+ return new FsSafeError("helper-failed", "file creation or staging settlement failed", {
110
+ cause: params.cleanup.length
111
+ ? new AggregateError([params.primary, ...params.cleanup], "file creation and cleanup failed")
112
+ : params.primary,
113
+ details: {
114
+ publication: { status: params.publication }, path: params.path, stageDirectory: params.stageDirectory,
115
+ cleanup: params.preserved || params.publication === "indeterminate" ? "preserved" : params.cleanup.length ? "failed" : "removed",
116
+ },
117
+ });
118
+ }
@@ -0,0 +1,21 @@
1
+ import { type BigIntStats } from "node:fs";
2
+ import { type AsyncDirectoryGuard, type AnyAsyncDirectoryGuard } from "./directory-guard.js";
3
+ export type CreationParentIdentity = Readonly<{
4
+ dev: bigint;
5
+ ino: bigint;
6
+ realPath?: string;
7
+ }>;
8
+ export type CreationPath = {
9
+ target: string;
10
+ parent: AsyncDirectoryGuard<BigIntStats>;
11
+ assertParent(): void;
12
+ };
13
+ export declare function creationAdmissionFromParent(parent: AnyAsyncDirectoryGuard): {
14
+ expectedParentIdentity: CreationParentIdentity;
15
+ };
16
+ export declare function prepareCreationPath(input: string, expectedParent?: CreationParentIdentity): CreationPath;
17
+ export declare function creationCollision(error: unknown): unknown;
18
+ /** Remove only the recorded empty stage; never traverse a replaced directory. */
19
+ export declare function removeCreationDirectory(directory: string, identity: BigIntStats, assertParent: () => void): void;
20
+ export declare function removeCreationDirectoryAsync(directory: string, identity: BigIntStats, assertParent: () => void): Promise<void>;
21
+ //# sourceMappingURL=creation-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-path.d.ts","sourceRoot":"","sources":["../src/creation-path.ts"],"names":[],"mappings":"AAAA,OAAW,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACzC,YAAY,IAAI,IAAI,CAAC;CACtB,CAAC;AAEF,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,sBAAsB,GAAG;IAAE,sBAAsB,EAAE,sBAAsB,CAAA;CAAE,CAO9H;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,sBAAsB,GAAG,YAAY,CAuBxG;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKzD;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,GAAG,IAAI,CAQhH;AAED,wBAAsB,4BAA4B,CAChD,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,GACjE,OAAO,CAAC,IAAI,CAAC,CAQf"}
@@ -0,0 +1,71 @@
1
+ import fs, {} from "node:fs";
2
+ import fsAsync from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { assertDirectoryIdentitySync, inspectDirectoryIdentitySync, } from "./directory-guard.js";
5
+ import { FsSafeError } from "./errors.js";
6
+ import { assertNoNulPathInput } from "./path.js";
7
+ import { realpathSync } from "./realpath.js";
8
+ import { assertNoWindowsPathAlias, resolvePathPreservingWindowsRoot } from "./windows-path-alias.js";
9
+ export function creationAdmissionFromParent(parent) {
10
+ const { dev, ino } = parent.stat;
11
+ if (typeof dev !== "bigint" || typeof ino !== "bigint") {
12
+ throw new FsSafeError("path-mismatch", "private creation requires an exact parent identity");
13
+ }
14
+ const identity = inspectDirectoryIdentitySync(parent.dir, { dev, ino });
15
+ return { expectedParentIdentity: { dev: identity.dev, ino: identity.ino, realPath: parent.realPath } };
16
+ }
17
+ export function prepareCreationPath(input, expectedParent) {
18
+ expectedParent = expectedParent && { dev: expectedParent.dev, ino: expectedParent.ino, realPath: expectedParent.realPath };
19
+ assertNoNulPathInput(input);
20
+ assertNoWindowsPathAlias(input, "filesystem");
21
+ if (process.platform === "win32" && input.replaceAll("/", "\\").split("\\")
22
+ .some(component => component.endsWith(".") || component.endsWith(" "))) {
23
+ throw new FsSafeError("invalid-path", "creation path contains an ambiguous Windows component");
24
+ }
25
+ const target = resolvePathPreservingWindowsRoot(input);
26
+ const directory = path.dirname(target);
27
+ if (target === directory || input.length === 0) {
28
+ throw new FsSafeError("invalid-path", "creation requires a child name");
29
+ }
30
+ if (expectedParent)
31
+ assertDirectoryIdentitySync(directory, expectedParent);
32
+ const stat = inspectDirectoryIdentitySync(directory);
33
+ const realPath = realpathSync.native(directory);
34
+ const parent = { dir: directory, realPath, stat };
35
+ const assertParent = () => {
36
+ assertDirectoryIdentitySync(directory, { dev: stat.dev, ino: stat.ino, realPath });
37
+ if (expectedParent)
38
+ assertDirectoryIdentitySync(directory, expectedParent);
39
+ };
40
+ assertParent();
41
+ return { target, parent, assertParent };
42
+ }
43
+ export function creationCollision(error) {
44
+ if (error?.code === "EEXIST") {
45
+ return new FsSafeError("already-exists", "creation target already exists", { cause: error });
46
+ }
47
+ return error;
48
+ }
49
+ /** Remove only the recorded empty stage; never traverse a replaced directory. */
50
+ export function removeCreationDirectory(directory, identity, assertParent) {
51
+ assertParent();
52
+ try {
53
+ assertDirectoryIdentitySync(directory, identity);
54
+ fs.rmdirSync(directory);
55
+ }
56
+ catch (error) {
57
+ if (error?.code !== "ENOENT")
58
+ throw error;
59
+ }
60
+ }
61
+ export async function removeCreationDirectoryAsync(directory, identity, assertParent) {
62
+ assertParent();
63
+ try {
64
+ assertDirectoryIdentitySync(directory, identity);
65
+ await fsAsync.rmdir(directory);
66
+ }
67
+ catch (error) {
68
+ if (error?.code !== "ENOENT")
69
+ throw error;
70
+ }
71
+ }
@@ -0,0 +1,19 @@
1
+ export type CreationPermissions = {
2
+ private?: boolean;
3
+ mode?: number;
4
+ };
5
+ export declare function resolveCreationPermissions(options: CreationPermissions, directory: boolean): {
6
+ private: boolean;
7
+ mode: number | undefined;
8
+ };
9
+ export declare function assertPrivateFileCreationAvailable(): void;
10
+ /** Full Windows identity, with security validation when requested; no repairs. */
11
+ export declare function inspectCreationDirectorySync(targetPath: string, privatePath: boolean): string;
12
+ export declare function inspectCreationDirectory(targetPath: string, privatePath: boolean): Promise<string>;
13
+ export declare function assertPrivateDirectorySync(targetPath: string): void;
14
+ export declare function assertPrivateDirectory(targetPath: string): Promise<void>;
15
+ export declare function protectCreatedFileSync(fd: number, targetPath: string, parentIdentity: string): string;
16
+ export declare function protectCreatedFile(fd: number, targetPath: string, parentIdentity: string): Promise<string>;
17
+ export declare function verifyCreatedFileSync(fd: number, targetPath: string, identity: string, parentIdentity: string, links?: number): void;
18
+ export declare function verifyCreatedFile(fd: number, targetPath: string, identity: string, parentIdentity: string, links?: number): Promise<void>;
19
+ //# sourceMappingURL=creation-permissions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creation-permissions.d.ts","sourceRoot":"","sources":["../src/creation-permissions.ts"],"names":[],"mappings":"AA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O,CAAC,IAAI,CAAC,CAQf"}
@@ -0,0 +1,125 @@
1
+ import { inspectDirectoryIdentitySync } from "./directory-guard.js";
2
+ import { FsSafeError } from "./errors.js";
3
+ import { getNativeBinding } from "./native.js";
4
+ import { getFsSafeNativeConfig } from "./native-config.js";
5
+ import { warnNativeFallback } from "./native-fallback-warning.js";
6
+ import { inspectWindowsDirectoryCommand, inspectWindowsDirectoryCommandSync, protectPrivateWindowsFileCommand, protectPrivateWindowsFileCommandSync, verifyPrivateWindowsFileCommand, verifyPrivateWindowsFileCommandSync, } from "./windows-security-command.js";
7
+ import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
8
+ import { assertDarwinCreationDirectoryAcl, assertDarwinPrivateCreationAvailable, assertDarwinPrivateDirectoryMode } from "./creation-darwin.js";
9
+ export function resolveCreationPermissions(options, directory) {
10
+ const privatePath = options.private;
11
+ const mode = options.mode;
12
+ if (privatePath !== undefined && typeof privatePath !== "boolean") {
13
+ throw new TypeError("private must be a boolean");
14
+ }
15
+ if (mode !== undefined && (!Number.isInteger(mode) || mode < 0 || mode > 0o7777)) {
16
+ throw new RangeError("mode must contain only permission bits");
17
+ }
18
+ if (privatePath && mode !== undefined && (mode & 0o7077) !== 0) {
19
+ throw new FsSafeError("insecure-permissions", "private creation requires owner-only permission bits");
20
+ }
21
+ if (privatePath)
22
+ assertDarwinPrivateCreationAvailable();
23
+ if (privatePath && directory)
24
+ assertDarwinPrivateDirectoryMode(mode ?? 0o700);
25
+ return { private: privatePath === true, mode: mode ?? (privatePath ? directory ? 0o700 : 0o600 : undefined) };
26
+ }
27
+ function assertPrivatePosixDirectory(stat) {
28
+ if (typeof process.getuid !== "function" || stat.uid !== BigInt(process.getuid())) {
29
+ throw new FsSafeError("not-owned", "private directory must belong to the current user");
30
+ }
31
+ if ((stat.mode & 3647n) !== 0n) {
32
+ throw new FsSafeError("insecure-permissions", "existing directory is not private");
33
+ }
34
+ }
35
+ function unavailable() {
36
+ throw new FsSafeError("helper-unavailable", "private Windows creation requires an up-to-date native helper");
37
+ }
38
+ export function assertPrivateFileCreationAvailable() {
39
+ const native = getNativeBinding();
40
+ if (process.platform !== "win32" || getFsSafeNativeConfig().mode !== "require")
41
+ return;
42
+ if (typeof native?.createPrivateDirectoryWithParentIdentity !== "function" ||
43
+ typeof native.inspectWindowsDirectory !== "function" ||
44
+ typeof native.protectPrivateWindowsFile !== "function" ||
45
+ typeof native.verifyPrivateWindowsFile !== "function")
46
+ unavailable();
47
+ }
48
+ function commandFallback() {
49
+ if (getFsSafeNativeConfig().mode === "require")
50
+ unavailable();
51
+ warnNativeFallback("windows-private-creation", "Private Windows creation uses a slower built-in system command.");
52
+ }
53
+ /** Full Windows identity, with security validation when requested; no repairs. */
54
+ export function inspectCreationDirectorySync(targetPath, privatePath) {
55
+ assertNoWindowsPathAlias(targetPath, "filesystem");
56
+ const native = getNativeBinding();
57
+ if (typeof native?.inspectWindowsDirectory === "function") {
58
+ return native.inspectWindowsDirectory(targetPath, privatePath).identity;
59
+ }
60
+ commandFallback();
61
+ return inspectWindowsDirectoryCommandSync(targetPath, privatePath).identity;
62
+ }
63
+ export async function inspectCreationDirectory(targetPath, privatePath) {
64
+ assertNoWindowsPathAlias(targetPath, "filesystem");
65
+ const native = getNativeBinding();
66
+ if (typeof native?.inspectWindowsDirectory === "function") {
67
+ return native.inspectWindowsDirectory(targetPath, privatePath).identity;
68
+ }
69
+ commandFallback();
70
+ return (await inspectWindowsDirectoryCommand(targetPath, privatePath)).identity;
71
+ }
72
+ export function assertPrivateDirectorySync(targetPath) {
73
+ const stat = inspectDirectoryIdentitySync(targetPath);
74
+ if (process.platform === "win32")
75
+ inspectCreationDirectorySync(targetPath, true);
76
+ else {
77
+ assertPrivatePosixDirectory(stat);
78
+ assertDarwinCreationDirectoryAcl(targetPath, stat);
79
+ }
80
+ inspectDirectoryIdentitySync(targetPath, stat);
81
+ }
82
+ export async function assertPrivateDirectory(targetPath) {
83
+ const stat = inspectDirectoryIdentitySync(targetPath);
84
+ if (process.platform === "win32")
85
+ await inspectCreationDirectory(targetPath, true);
86
+ else {
87
+ assertPrivatePosixDirectory(stat);
88
+ assertDarwinCreationDirectoryAcl(targetPath, stat);
89
+ }
90
+ inspectDirectoryIdentitySync(targetPath, stat);
91
+ }
92
+ export function protectCreatedFileSync(fd, targetPath, parentIdentity) {
93
+ const native = getNativeBinding();
94
+ if (typeof native?.protectPrivateWindowsFile === "function") {
95
+ return native.protectPrivateWindowsFile(fd, targetPath, parentIdentity).identity;
96
+ }
97
+ commandFallback();
98
+ return protectPrivateWindowsFileCommandSync(fd, targetPath, parentIdentity).identity;
99
+ }
100
+ export async function protectCreatedFile(fd, targetPath, parentIdentity) {
101
+ const native = getNativeBinding();
102
+ if (typeof native?.protectPrivateWindowsFile === "function") {
103
+ return native.protectPrivateWindowsFile(fd, targetPath, parentIdentity).identity;
104
+ }
105
+ commandFallback();
106
+ return (await protectPrivateWindowsFileCommand(fd, targetPath, parentIdentity)).identity;
107
+ }
108
+ export function verifyCreatedFileSync(fd, targetPath, identity, parentIdentity, links = 1) {
109
+ const native = getNativeBinding();
110
+ if (typeof native?.verifyPrivateWindowsFile === "function") {
111
+ native.verifyPrivateWindowsFile(fd, targetPath, identity, parentIdentity, links);
112
+ return;
113
+ }
114
+ commandFallback();
115
+ verifyPrivateWindowsFileCommandSync(fd, targetPath, identity, parentIdentity, links);
116
+ }
117
+ export async function verifyCreatedFile(fd, targetPath, identity, parentIdentity, links = 1) {
118
+ const native = getNativeBinding();
119
+ if (typeof native?.verifyPrivateWindowsFile === "function") {
120
+ native.verifyPrivateWindowsFile(fd, targetPath, identity, parentIdentity, links);
121
+ return;
122
+ }
123
+ commandFallback();
124
+ await verifyPrivateWindowsFileCommand(fd, targetPath, identity, parentIdentity, links);
125
+ }
@@ -1,15 +1,15 @@
1
- import { type Stats } from "node:fs";
2
- import { type FileIdentityStat } from "./file-identity.js";
1
+ import { type BigIntStats, type Stats } from "node:fs";
2
+ import type { FileIdentityStat } from "./file-identity.js";
3
3
  export type DirectorySyncOutcome = {
4
4
  status: "synced";
5
5
  } | {
6
6
  status: "unsupported";
7
7
  code?: string;
8
8
  };
9
- export type DirectoryReceipt = {
9
+ export type DirectoryReceipt<T extends Stats | BigIntStats = Stats> = {
10
10
  path: string;
11
11
  realPath: string;
12
- identity: Stats;
12
+ identity: T;
13
13
  };
14
14
  export type DurableDirectoryReceipt = DirectoryReceipt & {
15
15
  parentSync: DirectorySyncOutcome | {
@@ -29,13 +29,13 @@ export type EnsureDurableDirectoryOptions = {
29
29
  expectedExistingIdentity?: FileIdentityStat;
30
30
  create?: (directoryPath: string) => Promise<void>;
31
31
  };
32
- export declare function pinDirectory(directory: string | DirectoryReceipt, options?: {
32
+ export declare function pinDirectory(directory: string | DirectoryReceipt<Stats | BigIntStats>, options?: {
33
33
  label?: string;
34
34
  }): Promise<PinnedDirectory>;
35
- export declare function syncDirectory(directory: string | DirectoryReceipt, options?: {
35
+ export declare function syncDirectory(directory: string | DirectoryReceipt<Stats | BigIntStats>, options?: {
36
36
  label?: string;
37
37
  }): Promise<DirectorySyncOutcome>;
38
- export declare function syncDirectorySync(directory: string | DirectoryReceipt, options?: {
38
+ export declare function syncDirectorySync(directory: string | DirectoryReceipt<Stats | BigIntStats>, options?: {
39
39
  label?: string;
40
40
  }): DirectorySyncOutcome;
41
41
  export declare function syncDirectoryBestEffort(directoryPath: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"directory-durability.d.ts","sourceRoot":"","sources":["../src/directory-durability.ts"],"names":[],"mappings":"AAAA,OAAe,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAM7C,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAI7E,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7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