@unbrained/pm-cli 2026.11.30 → 2026.12.2

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 (382) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/commander-usage.js +10 -10
  3. package/dist/cli/error-guidance.js +5 -5
  4. package/dist/cli/extension-command-help.js +6 -6
  5. package/dist/cli/help-json-payload.js +7 -7
  6. package/dist/cli/main.js +5 -5
  7. package/dist/cli/register-list-query.js +10 -10
  8. package/dist/cli/register-mutation.js +3 -3
  9. package/dist/cli/runtime/invocation-command-path.js +2 -0
  10. package/dist/cli/runtime/read-output-mutation-retry.js +1 -1
  11. package/dist/cli-bundle/bundle-manifest.json +1 -1
  12. package/dist/cli-bundle/chunks/{chunk-DCWGM7CY.js → chunk-3HKPVOAN.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-Z7YL2SUM.js → chunk-3KEMIPKG.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-TX74QJ4W.js → chunk-4YYFY33T.js} +2 -2
  15. package/dist/cli-bundle/chunks/{chunk-47ZS6RPL.js → chunk-7NAO7I75.js} +2 -2
  16. package/dist/cli-bundle/chunks/{chunk-IGEFPHV7.js → chunk-7V65VACG.js} +52 -52
  17. package/dist/cli-bundle/chunks/chunk-A5ZEMOVR.js +2 -0
  18. package/dist/cli-bundle/chunks/{chunk-5PNOVDVO.js → chunk-AHV3CSQG.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-KCVSSONY.js → chunk-C6WM6ZN4.js} +3 -3
  20. package/dist/cli-bundle/chunks/chunk-CBUC4X7Q.js +127 -0
  21. package/dist/cli-bundle/chunks/{chunk-CCKM5YQM.js → chunk-G6TARHFK.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-TY55UX6M.js → chunk-GOEQXVOI.js} +2 -2
  23. package/dist/cli-bundle/chunks/chunk-I4SPJQQI.js +3 -0
  24. package/dist/cli-bundle/chunks/{chunk-Q4VZSMUL.js → chunk-L2ZSSMYY.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-NHBG5ET3.js → chunk-MZZ4ZJ5Z.js} +2 -2
  26. package/dist/cli-bundle/chunks/chunk-NRQCBUYD.js +113 -0
  27. package/dist/cli-bundle/chunks/{chunk-YVTALIN3.js → chunk-OBPO6V7H.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-KXTKLDKD.js → chunk-OXC5KBIQ.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-HXQ3OHQR.js → chunk-PCDTWL6V.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-AOTI76Q6.js → chunk-Q6K7HWZ7.js} +2 -2
  31. package/dist/cli-bundle/chunks/chunk-QDV7S2QS.js +2 -0
  32. package/dist/cli-bundle/chunks/{chunk-NZSXWIX7.js → chunk-ROTEELDL.js} +7 -7
  33. package/dist/cli-bundle/chunks/{chunk-WFYE34TO.js → chunk-SDXCJZKB.js} +23 -23
  34. package/dist/cli-bundle/chunks/{chunk-2SBTXR6C.js → chunk-SY5C3U32.js} +3 -3
  35. package/dist/cli-bundle/chunks/{chunk-FR7ULTM4.js → chunk-TKUG2X24.js} +2 -2
  36. package/dist/cli-bundle/chunks/{chunk-FECZV72T.js → chunk-UNBW2LF3.js} +2 -2
  37. package/dist/cli-bundle/chunks/chunk-V2S4XAX3.js +2 -0
  38. package/dist/cli-bundle/chunks/chunk-WSEIEDEK.js +2 -0
  39. package/dist/cli-bundle/chunks/{chunk-ZA5NS3PL.js → chunk-ZL6J6JYT.js} +6 -6
  40. package/dist/cli-bundle/chunks/{field-option-collisions-2F2Z7R7B.js → field-option-collisions-BBGTV7AD.js} +2 -2
  41. package/dist/cli-bundle/chunks/item-revision-3LENTXYF.js +2 -0
  42. package/dist/cli-bundle/chunks/item-transaction-56J5OCHA.js +2 -0
  43. package/dist/cli-bundle/chunks/{linked-resource-value-list-WXPPYUVQ.js → linked-resource-value-list-ZBIY4H23.js} +2 -2
  44. package/dist/cli-bundle/chunks/{mutation-actor-UK3QNEEB.js → mutation-actor-NHN33ITJ.js} +2 -2
  45. package/dist/cli-bundle/chunks/{mutation-admission-UTDYPFWP.js → mutation-admission-PGKJTCG6.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-list-query-DRA3CWHI.js → register-list-query-7S5QWDTI.js} +11 -11
  47. package/dist/cli-bundle/chunks/{register-mutation-WO74VLEQ.js → register-mutation-EK6DVIQK.js} +5 -5
  48. package/dist/cli-bundle/chunks/{register-operations-CRBKH7WN.js → register-operations-6MURXE4V.js} +2 -2
  49. package/dist/cli-bundle/chunks/{register-setup-6V6NQB5C.js → register-setup-RW26X3GJ.js} +2 -2
  50. package/dist/cli-bundle/chunks/{stage-DYEHGASU.js → stage-4ZCF74G4.js} +2 -2
  51. package/dist/cli-bundle/focused-chunks/{chunk-RQYVX2T6.js → chunk-2DGKVXFT.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/chunk-2UWKU2BQ.js +3 -0
  53. package/dist/cli-bundle/focused-chunks/{chunk-A3DORTXS.js → chunk-3COWDIPX.js} +54 -54
  54. package/dist/cli-bundle/focused-chunks/{chunk-UQJ4PY2Y.js → chunk-4SCFAWAW.js} +2 -2
  55. package/dist/cli-bundle/focused-chunks/{chunk-7G7JIXLL.js → chunk-6BKT6XQN.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/chunk-6IY5CVGJ.js +2 -0
  57. package/dist/cli-bundle/focused-chunks/chunk-7A6SEZEY.js +4 -0
  58. package/dist/cli-bundle/focused-chunks/{chunk-IJ3T3W4U.js → chunk-BHNBPCHP.js} +2 -2
  59. package/dist/cli-bundle/focused-chunks/{chunk-LWBZ7UGG.js → chunk-EQCQTYKO.js} +2 -2
  60. package/dist/cli-bundle/focused-chunks/{chunk-FM5WQ6ZU.js → chunk-HTDYNY4L.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-TQQO42C2.js → chunk-J72TRWR5.js} +26 -26
  62. package/dist/cli-bundle/focused-chunks/{chunk-L357ZAES.js → chunk-JPZGC3W4.js} +5 -5
  63. package/dist/cli-bundle/focused-chunks/{chunk-62AMZMR4.js → chunk-KNBGHCIP.js} +3 -3
  64. package/dist/cli-bundle/focused-chunks/chunk-N64AC5G6.js +100 -0
  65. package/dist/cli-bundle/focused-chunks/{chunk-IIVDBAJM.js → chunk-OG57ESZK.js} +2 -2
  66. package/dist/cli-bundle/focused-chunks/{chunk-MZNV26XE.js → chunk-P2H3GTJK.js} +2 -2
  67. package/dist/cli-bundle/focused-chunks/chunk-QZRYGYTI.js +2 -0
  68. package/dist/cli-bundle/focused-chunks/chunk-SQMOF65W.js +2 -0
  69. package/dist/cli-bundle/focused-chunks/chunk-T3ILWAEV.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/{chunk-SXC3NVZI.js → chunk-TR22GU7M.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{chunk-M57KDG7I.js → chunk-TXTPAFHJ.js} +2 -2
  72. package/dist/cli-bundle/focused-chunks/chunk-VK3IE3TS.js +29 -0
  73. package/dist/cli-bundle/focused-chunks/{chunk-NJTKGBSK.js → chunk-VQIC3UZB.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/{chunk-U35K7FSE.js → chunk-W4JMV7GF.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/{field-option-collisions-7TG7STO7.js → field-option-collisions-2C6DLUC4.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/item-revision-723XCQPS.js +2 -0
  77. package/dist/cli-bundle/focused-chunks/{item-transaction-2IC2MLML.js → item-transaction-LQLQLZE7.js} +2 -2
  78. package/dist/cli-bundle/focused-chunks/{mutation-actor-LJVF2HVD.js → mutation-actor-DJMZUIZI.js} +2 -2
  79. package/dist/cli-bundle/focused-chunks/mutation-admission-SDWQVVHN.js +2 -0
  80. package/dist/cli-bundle/focused-chunks/{stage-MWR73LTZ.js → stage-QBZIK3T5.js} +2 -2
  81. package/dist/cli-bundle/main.js +27 -27
  82. package/dist/cli-bundle/sdk-authoring.js +1 -1
  83. package/dist/cli-bundle/sdk-contracts.js +1 -1
  84. package/dist/cli-bundle/sdk-core.js +1 -1
  85. package/dist/cli-bundle/sdk-governance.js +1 -1
  86. package/dist/cli-bundle/sdk-graph.js +1 -1
  87. package/dist/cli-bundle/sdk-merge.js +61 -61
  88. package/dist/cli-bundle/sdk-query.js +1 -1
  89. package/dist/cli-bundle/sdk-runtime.js +1 -1
  90. package/dist/cli-bundle/sdk-testing.js +1 -1
  91. package/dist/cli-bundle/sdk.js +2 -2
  92. package/dist/core/extensions/reserved-host-flags.js +1 -1
  93. package/dist/core/shared/secret-rules.d.ts +86 -12
  94. package/dist/core/shared/secret-rules.js +7 -5
  95. package/dist/sdk/cli-bootstrap.js +1 -1
  96. package/dist/sdk/cli-contracts/flag-contracts.d.ts +50 -0
  97. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  98. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +3 -1
  99. package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
  100. package/dist/sdk/extension/command-options.js +1 -1
  101. package/dist/sdk/extension/install-sources.d.ts +2 -2
  102. package/dist/sdk/extension/install-sources.js +5 -5
  103. package/dist/sdk/lifecycle/expect-hash-admission.d.ts +15 -0
  104. package/dist/sdk/lifecycle/expect-hash-admission.js +2 -0
  105. package/dist/sdk/lifecycle/item-revision.d.ts +4 -1
  106. package/dist/sdk/lifecycle/item-revision.js +1 -1
  107. package/dist/sdk/mutation-guard.js +1 -1
  108. package/dist/sdk/output-contracts.js +1 -1
  109. package/dist/sdk/output-projection.d.ts +1 -1
  110. package/dist/sdk/output-projection.js +1 -1
  111. package/dist/sdk/public-surface.json +1 -1
  112. package/dist/sdk/query/aggregate.js +1 -1
  113. package/dist/sdk/query/context.js +1 -1
  114. package/dist/sdk/query/list.js +1 -1
  115. package/dist/sdk/query/next.js +1 -1
  116. package/dist/sdk/query/search-contracts.js +1 -1
  117. package/dist/sdk/read-output/surfaces.js +1 -1
  118. package/dist/sdk/read-output-budget.d.ts +1 -1
  119. package/dist/sdk/read-output-budget.js +1 -1
  120. package/dist/sdk/read-output-contracts.js +1 -1
  121. package/dist/sdk/read-output-rows.js +1 -1
  122. package/docs/COMMANDS.md +37 -0
  123. package/docs/MUTATION_INTEGRITY.md +226 -10
  124. package/docs/SDK.md +16 -6
  125. package/docs/agent-task-token-baseline.json +1 -1
  126. package/marketplace.json +1 -1
  127. package/node_modules/tar/README.md +1792 -1147
  128. package/node_modules/tar/dist/commonjs/bytes.d.ts +21 -0
  129. package/node_modules/tar/dist/commonjs/bytes.js +83 -0
  130. package/node_modules/tar/dist/commonjs/codec.d.ts +53 -0
  131. package/node_modules/tar/dist/commonjs/codec.js +35 -0
  132. package/node_modules/tar/dist/commonjs/concat.d.ts +3 -0
  133. package/node_modules/tar/dist/commonjs/concat.js +20 -0
  134. package/node_modules/tar/dist/commonjs/create.d.ts +39 -2
  135. package/node_modules/tar/dist/commonjs/create.js +150 -64
  136. package/node_modules/tar/dist/commonjs/dealias.d.ts +79 -0
  137. package/node_modules/tar/dist/commonjs/dealias.js +50 -0
  138. package/node_modules/tar/dist/commonjs/delete.d.ts +19 -0
  139. package/node_modules/tar/dist/commonjs/delete.js +121 -0
  140. package/node_modules/tar/dist/commonjs/entries.d.ts +82 -0
  141. package/node_modules/tar/dist/commonjs/entries.js +398 -0
  142. package/node_modules/tar/dist/commonjs/extract.d.ts +14 -2
  143. package/node_modules/tar/dist/commonjs/extract.js +40 -81
  144. package/node_modules/tar/dist/commonjs/fs.d.ts +201 -0
  145. package/node_modules/tar/dist/commonjs/fs.js +5 -0
  146. package/node_modules/tar/dist/commonjs/header.d.ts +4 -4
  147. package/node_modules/tar/dist/commonjs/header.js +71 -53
  148. package/node_modules/tar/dist/commonjs/index.d.ts +25 -18
  149. package/node_modules/tar/dist/commonjs/index.js +46 -18
  150. package/node_modules/tar/dist/commonjs/index.min.js +2 -3
  151. package/node_modules/tar/dist/commonjs/large-numbers.d.ts +2 -2
  152. package/node_modules/tar/dist/commonjs/large-numbers.js +4 -4
  153. package/node_modules/tar/dist/commonjs/list.d.ts +23 -6
  154. package/node_modules/tar/dist/commonjs/list.js +99 -138
  155. package/node_modules/tar/dist/commonjs/mkdir.d.ts +16 -11
  156. package/node_modules/tar/dist/commonjs/mkdir.js +121 -159
  157. package/node_modules/tar/dist/commonjs/normalize-unicode.js +9 -0
  158. package/node_modules/tar/dist/commonjs/options.d.ts +284 -513
  159. package/node_modules/tar/dist/commonjs/options.js +20 -61
  160. package/node_modules/tar/dist/commonjs/pack.d.ts +150 -96
  161. package/node_modules/tar/dist/commonjs/pack.js +752 -445
  162. package/node_modules/tar/dist/commonjs/parser.d.ts +98 -0
  163. package/node_modules/tar/dist/commonjs/parser.js +452 -0
  164. package/node_modules/tar/dist/commonjs/path-reservations.d.ts +17 -7
  165. package/node_modules/tar/dist/commonjs/path-reservations.js +110 -140
  166. package/node_modules/tar/dist/commonjs/path.d.ts +19 -0
  167. package/node_modules/tar/dist/commonjs/path.js +90 -0
  168. package/node_modules/tar/dist/commonjs/pax.d.ts +3 -1
  169. package/node_modules/tar/dist/commonjs/pax.js +67 -36
  170. package/node_modules/tar/dist/commonjs/read-entry.d.ts +97 -11
  171. package/node_modules/tar/dist/commonjs/read-entry.js +251 -97
  172. package/node_modules/tar/dist/commonjs/read-file.d.ts +22 -0
  173. package/node_modules/tar/dist/commonjs/read-file.js +104 -0
  174. package/node_modules/tar/dist/commonjs/replace.d.ts +45 -1
  175. package/node_modules/tar/dist/commonjs/replace.js +164 -211
  176. package/node_modules/tar/dist/commonjs/server/codecs.d.ts +38 -0
  177. package/node_modules/tar/dist/commonjs/server/codecs.js +252 -0
  178. package/node_modules/tar/dist/commonjs/server/index.d.ts +115 -0
  179. package/node_modules/tar/dist/commonjs/server/index.js +166 -0
  180. package/node_modules/tar/dist/commonjs/server/index.min.js +3 -0
  181. package/node_modules/tar/dist/commonjs/strip-absolute-path.d.ts +8 -0
  182. package/node_modules/tar/dist/commonjs/strip-absolute-path.js +17 -20
  183. package/node_modules/tar/dist/commonjs/to-stream.d.ts +7 -0
  184. package/node_modules/tar/dist/commonjs/to-stream.js +22 -0
  185. package/node_modules/tar/dist/commonjs/types.d.ts +4 -3
  186. package/node_modules/tar/dist/commonjs/types.js +4 -3
  187. package/node_modules/tar/dist/commonjs/unpack.d.ts +143 -89
  188. package/node_modules/tar/dist/commonjs/unpack.js +780 -725
  189. package/node_modules/tar/dist/commonjs/update.d.ts +11 -1
  190. package/node_modules/tar/dist/commonjs/update.js +37 -28
  191. package/node_modules/tar/dist/commonjs/warn.d.ts +27 -0
  192. package/node_modules/tar/dist/commonjs/warn.js +36 -0
  193. package/node_modules/tar/dist/commonjs/win32-path.d.ts +16 -0
  194. package/node_modules/tar/dist/commonjs/win32-path.js +67 -0
  195. package/node_modules/tar/dist/commonjs/write-entry.d.ts +64 -111
  196. package/node_modules/tar/dist/commonjs/write-entry.js +108 -672
  197. package/node_modules/tar/dist/commonjs/write-flag.d.ts +18 -0
  198. package/node_modules/tar/dist/commonjs/write-flag.js +29 -0
  199. package/node_modules/tar/dist/esm/bytes.d.ts +21 -0
  200. package/node_modules/tar/dist/esm/bytes.js +72 -0
  201. package/node_modules/tar/dist/esm/codec.d.ts +53 -0
  202. package/node_modules/tar/dist/esm/codec.js +32 -0
  203. package/node_modules/tar/dist/esm/concat.d.ts +3 -0
  204. package/node_modules/tar/dist/esm/concat.js +16 -0
  205. package/node_modules/tar/dist/esm/create.d.ts +39 -2
  206. package/node_modules/tar/dist/esm/create.js +144 -61
  207. package/node_modules/tar/dist/esm/dealias.d.ts +79 -0
  208. package/node_modules/tar/dist/esm/dealias.js +46 -0
  209. package/node_modules/tar/dist/esm/delete.d.ts +19 -0
  210. package/node_modules/tar/dist/esm/delete.js +117 -0
  211. package/node_modules/tar/dist/esm/entries.d.ts +82 -0
  212. package/node_modules/tar/dist/esm/entries.js +388 -0
  213. package/node_modules/tar/dist/esm/extract.d.ts +14 -2
  214. package/node_modules/tar/dist/esm/extract.js +37 -44
  215. package/node_modules/tar/dist/esm/fs.d.ts +201 -0
  216. package/node_modules/tar/dist/esm/fs.js +4 -0
  217. package/node_modules/tar/dist/esm/header.d.ts +4 -4
  218. package/node_modules/tar/dist/esm/header.js +71 -53
  219. package/node_modules/tar/dist/esm/index.d.ts +25 -18
  220. package/node_modules/tar/dist/esm/index.js +23 -18
  221. package/node_modules/tar/dist/esm/index.min.js +2 -3
  222. package/node_modules/tar/dist/esm/large-numbers.d.ts +2 -2
  223. package/node_modules/tar/dist/esm/large-numbers.js +4 -4
  224. package/node_modules/tar/dist/esm/list.d.ts +23 -6
  225. package/node_modules/tar/dist/esm/list.js +96 -101
  226. package/node_modules/tar/dist/esm/mkdir.d.ts +16 -11
  227. package/node_modules/tar/dist/esm/mkdir.js +119 -154
  228. package/node_modules/tar/dist/esm/normalize-unicode.js +9 -0
  229. package/node_modules/tar/dist/esm/options.d.ts +284 -513
  230. package/node_modules/tar/dist/esm/options.js +17 -51
  231. package/node_modules/tar/dist/esm/pack.d.ts +150 -96
  232. package/node_modules/tar/dist/esm/pack.js +750 -441
  233. package/node_modules/tar/dist/esm/parser.d.ts +98 -0
  234. package/node_modules/tar/dist/esm/parser.js +448 -0
  235. package/node_modules/tar/dist/esm/path-reservations.d.ts +17 -7
  236. package/node_modules/tar/dist/esm/path-reservations.js +110 -140
  237. package/node_modules/tar/dist/esm/path.d.ts +19 -0
  238. package/node_modules/tar/dist/esm/path.js +80 -0
  239. package/node_modules/tar/dist/esm/pax.d.ts +3 -1
  240. package/node_modules/tar/dist/esm/pax.js +66 -35
  241. package/node_modules/tar/dist/esm/read-entry.d.ts +97 -11
  242. package/node_modules/tar/dist/esm/read-entry.js +248 -96
  243. package/node_modules/tar/dist/esm/read-file.d.ts +22 -0
  244. package/node_modules/tar/dist/esm/read-file.js +99 -0
  245. package/node_modules/tar/dist/esm/replace.d.ts +45 -1
  246. package/node_modules/tar/dist/esm/replace.js +160 -207
  247. package/node_modules/tar/dist/esm/server/codecs.d.ts +38 -0
  248. package/node_modules/tar/dist/esm/server/codecs.js +214 -0
  249. package/node_modules/tar/dist/esm/server/index.d.ts +115 -0
  250. package/node_modules/tar/dist/esm/server/index.js +102 -0
  251. package/node_modules/tar/dist/esm/server/index.min.js +3 -0
  252. package/node_modules/tar/dist/esm/strip-absolute-path.d.ts +8 -0
  253. package/node_modules/tar/dist/esm/strip-absolute-path.js +17 -20
  254. package/node_modules/tar/dist/esm/to-stream.d.ts +7 -0
  255. package/node_modules/tar/dist/esm/to-stream.js +18 -0
  256. package/node_modules/tar/dist/esm/types.d.ts +4 -3
  257. package/node_modules/tar/dist/esm/types.js +4 -3
  258. package/node_modules/tar/dist/esm/unpack.d.ts +143 -89
  259. package/node_modules/tar/dist/esm/unpack.js +776 -719
  260. package/node_modules/tar/dist/esm/update.d.ts +11 -1
  261. package/node_modules/tar/dist/esm/update.js +35 -28
  262. package/node_modules/tar/dist/esm/warn.d.ts +27 -0
  263. package/node_modules/tar/dist/esm/warn.js +31 -0
  264. package/node_modules/tar/dist/esm/win32-path.d.ts +16 -0
  265. package/node_modules/tar/dist/esm/win32-path.js +60 -0
  266. package/node_modules/tar/dist/esm/write-entry.d.ts +64 -111
  267. package/node_modules/tar/dist/esm/write-entry.js +107 -633
  268. package/node_modules/tar/dist/esm/write-flag.d.ts +18 -0
  269. package/node_modules/tar/dist/esm/write-flag.js +25 -0
  270. package/node_modules/tar/package.json +68 -224
  271. package/package.json +2 -2
  272. package/packages/pm-beads/package.json +1 -1
  273. package/packages/pm-calendar/package.json +1 -1
  274. package/packages/pm-command-kit/package.json +1 -1
  275. package/packages/pm-digital-twin/package.json +1 -1
  276. package/packages/pm-governance-audit/package.json +1 -1
  277. package/packages/pm-guide-shell/package.json +1 -1
  278. package/packages/pm-kanban/package.json +1 -1
  279. package/packages/pm-lifecycle-hooks/package.json +1 -1
  280. package/packages/pm-linked-test-adapters/package.json +1 -1
  281. package/packages/pm-search-advanced/package.json +1 -1
  282. package/packages/pm-templates/package.json +1 -1
  283. package/packages/pm-todos/package.json +1 -1
  284. package/packages/pm-vcs/package.json +1 -1
  285. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  286. package/plugins/pm-claude/package.json +1 -1
  287. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  288. package/plugins/pm-codex/package.json +1 -1
  289. package/plugins/pm-codex/plugin.json +1 -1
  290. package/runtime-dependencies.json +1 -1
  291. package/dist/cli-bundle/chunks/chunk-3TXEWHQX.js +0 -125
  292. package/dist/cli-bundle/chunks/chunk-JPJNJHQW.js +0 -2
  293. package/dist/cli-bundle/chunks/chunk-NVYDPNQP.js +0 -2
  294. package/dist/cli-bundle/chunks/chunk-SJWIPGZW.js +0 -113
  295. package/dist/cli-bundle/chunks/chunk-USBTXMKS.js +0 -2
  296. package/dist/cli-bundle/chunks/chunk-VCXQ6A35.js +0 -3
  297. package/dist/cli-bundle/chunks/chunk-YPMNXG2C.js +0 -2
  298. package/dist/cli-bundle/chunks/item-revision-UAF6L47R.js +0 -2
  299. package/dist/cli-bundle/chunks/item-transaction-RJECL53Y.js +0 -2
  300. package/dist/cli-bundle/focused-chunks/chunk-2UUBS4BG.js +0 -2
  301. package/dist/cli-bundle/focused-chunks/chunk-4ER3VMST.js +0 -2
  302. package/dist/cli-bundle/focused-chunks/chunk-4YBMHMBJ.js +0 -2
  303. package/dist/cli-bundle/focused-chunks/chunk-HXM7K6VH.js +0 -100
  304. package/dist/cli-bundle/focused-chunks/chunk-NGHT2LNG.js +0 -3
  305. package/dist/cli-bundle/focused-chunks/chunk-P55AZPFN.js +0 -2
  306. package/dist/cli-bundle/focused-chunks/chunk-WAP3DF4B.js +0 -27
  307. package/dist/cli-bundle/focused-chunks/chunk-XR745UGE.js +0 -4
  308. package/dist/cli-bundle/focused-chunks/item-revision-J7EUGCHR.js +0 -2
  309. package/dist/cli-bundle/focused-chunks/mutation-admission-SLFAUONA.js +0 -2
  310. package/node_modules/@isaacs/fs-minipass/LICENSE +0 -15
  311. package/node_modules/@isaacs/fs-minipass/README.md +0 -71
  312. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.d.ts +0 -118
  313. package/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +0 -430
  314. package/node_modules/@isaacs/fs-minipass/dist/commonjs/package.json +0 -3
  315. package/node_modules/@isaacs/fs-minipass/dist/esm/index.d.ts +0 -118
  316. package/node_modules/@isaacs/fs-minipass/dist/esm/index.js +0 -420
  317. package/node_modules/@isaacs/fs-minipass/dist/esm/package.json +0 -3
  318. package/node_modules/@isaacs/fs-minipass/package.json +0 -72
  319. package/node_modules/chownr/LICENSE.md +0 -63
  320. package/node_modules/chownr/README.md +0 -3
  321. package/node_modules/chownr/dist/commonjs/index.d.ts +0 -3
  322. package/node_modules/chownr/dist/commonjs/index.js +0 -93
  323. package/node_modules/chownr/dist/commonjs/package.json +0 -3
  324. package/node_modules/chownr/dist/esm/index.d.ts +0 -3
  325. package/node_modules/chownr/dist/esm/index.js +0 -85
  326. package/node_modules/chownr/dist/esm/package.json +0 -3
  327. package/node_modules/chownr/package.json +0 -69
  328. package/node_modules/minipass/LICENSE.md +0 -55
  329. package/node_modules/minipass/README.md +0 -825
  330. package/node_modules/minipass/dist/commonjs/index.d.ts +0 -545
  331. package/node_modules/minipass/dist/commonjs/index.js +0 -1038
  332. package/node_modules/minipass/dist/commonjs/package.json +0 -3
  333. package/node_modules/minipass/dist/esm/index.d.ts +0 -545
  334. package/node_modules/minipass/dist/esm/index.js +0 -1020
  335. package/node_modules/minipass/dist/esm/package.json +0 -3
  336. package/node_modules/minipass/package.json +0 -77
  337. package/node_modules/minizlib/LICENSE +0 -26
  338. package/node_modules/minizlib/README.md +0 -64
  339. package/node_modules/minizlib/dist/commonjs/constants.d.ts +0 -2
  340. package/node_modules/minizlib/dist/commonjs/constants.js +0 -123
  341. package/node_modules/minizlib/dist/commonjs/index.d.ts +0 -99
  342. package/node_modules/minizlib/dist/commonjs/index.js +0 -416
  343. package/node_modules/minizlib/dist/commonjs/package.json +0 -3
  344. package/node_modules/minizlib/dist/esm/constants.d.ts +0 -2
  345. package/node_modules/minizlib/dist/esm/constants.js +0 -117
  346. package/node_modules/minizlib/dist/esm/index.d.ts +0 -99
  347. package/node_modules/minizlib/dist/esm/index.js +0 -363
  348. package/node_modules/minizlib/dist/esm/package.json +0 -3
  349. package/node_modules/minizlib/package.json +0 -80
  350. package/node_modules/tar/dist/commonjs/get-write-flag.d.ts +0 -2
  351. package/node_modules/tar/dist/commonjs/get-write-flag.js +0 -32
  352. package/node_modules/tar/dist/commonjs/make-command.d.ts +0 -49
  353. package/node_modules/tar/dist/commonjs/make-command.js +0 -52
  354. package/node_modules/tar/dist/commonjs/normalize-windows-path.d.ts +0 -2
  355. package/node_modules/tar/dist/commonjs/normalize-windows-path.js +0 -12
  356. package/node_modules/tar/dist/commonjs/parse.d.ts +0 -92
  357. package/node_modules/tar/dist/commonjs/parse.js +0 -655
  358. package/node_modules/tar/dist/commonjs/process-umask.d.ts +0 -2
  359. package/node_modules/tar/dist/commonjs/process-umask.js +0 -7
  360. package/node_modules/tar/dist/commonjs/warn-method.d.ts +0 -24
  361. package/node_modules/tar/dist/commonjs/warn-method.js +0 -31
  362. package/node_modules/tar/dist/esm/get-write-flag.d.ts +0 -2
  363. package/node_modules/tar/dist/esm/get-write-flag.js +0 -26
  364. package/node_modules/tar/dist/esm/make-command.d.ts +0 -49
  365. package/node_modules/tar/dist/esm/make-command.js +0 -48
  366. package/node_modules/tar/dist/esm/normalize-windows-path.d.ts +0 -2
  367. package/node_modules/tar/dist/esm/normalize-windows-path.js +0 -9
  368. package/node_modules/tar/dist/esm/parse.d.ts +0 -92
  369. package/node_modules/tar/dist/esm/parse.js +0 -651
  370. package/node_modules/tar/dist/esm/process-umask.d.ts +0 -2
  371. package/node_modules/tar/dist/esm/process-umask.js +0 -3
  372. package/node_modules/tar/dist/esm/warn-method.d.ts +0 -24
  373. package/node_modules/tar/dist/esm/warn-method.js +0 -27
  374. package/node_modules/yallist/LICENSE.md +0 -63
  375. package/node_modules/yallist/README.md +0 -205
  376. package/node_modules/yallist/dist/commonjs/index.d.ts +0 -39
  377. package/node_modules/yallist/dist/commonjs/index.js +0 -384
  378. package/node_modules/yallist/dist/commonjs/package.json +0 -3
  379. package/node_modules/yallist/dist/esm/index.d.ts +0 -39
  380. package/node_modules/yallist/dist/esm/index.js +0 -379
  381. package/node_modules/yallist/dist/esm/package.json +0 -3
  382. package/node_modules/yallist/package.json +0 -68
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
- // the PEND/UNPEND stuff tracks whether we're ready to emit end/close yet.
3
- // but the path reservations are required to avoid race conditions where
4
- // parallelized unpack ops may mess with one another, due to dependencies
5
- // (like a Link depending on its target) or destructive operations (like
6
- // clobbering an fs object to create one of a different type.)
7
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
3
  if (k2 === undefined) k2 = k;
9
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -37,376 +32,336 @@ var __importStar = (this && this.__importStar) || (function () {
37
32
  return result;
38
33
  };
39
34
  })();
40
- var __importDefault = (this && this.__importDefault) || function (mod) {
41
- return (mod && mod.__esModule) ? mod : { "default": mod };
42
- };
43
35
  Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.UnpackSync = exports.Unpack = void 0;
45
- const fsm = __importStar(require("@isaacs/fs-minipass"));
46
- const node_assert_1 = __importDefault(require("node:assert"));
47
- const node_crypto_1 = require("node:crypto");
48
- const node_fs_1 = __importDefault(require("node:fs"));
49
- const node_path_1 = __importDefault(require("node:path"));
50
- const get_write_flag_js_1 = require("./get-write-flag.js");
51
- const mkdir_js_1 = require("./mkdir.js");
52
- const normalize_windows_path_js_1 = require("./normalize-windows-path.js");
53
- const parse_js_1 = require("./parse.js");
54
- const strip_absolute_path_js_1 = require("./strip-absolute-path.js");
36
+ exports.UnpackSync = exports.Unpack = exports.UnpackBase = void 0;
37
+ const symlink_error_js_1 = require("./symlink-error.js");
55
38
  const wc = __importStar(require("./winchars.js"));
39
+ const entries_js_1 = require("./entries.js");
40
+ const mkdir_js_1 = require("./mkdir.js");
41
+ const options_js_1 = require("./options.js");
56
42
  const path_reservations_js_1 = require("./path-reservations.js");
57
- const symlink_error_js_1 = require("./symlink-error.js");
58
- const process_umask_js_1 = require("./process-umask.js");
59
- const ONENTRY = Symbol('onEntry');
60
- const CHECKFS = Symbol('checkFs');
61
- const CHECKFS2 = Symbol('checkFs2');
62
- const ISREUSABLE = Symbol('isReusable');
63
- const MAKEFS = Symbol('makeFs');
64
- const FILE = Symbol('file');
65
- const DIRECTORY = Symbol('directory');
66
- const LINK = Symbol('link');
67
- const SYMLINK = Symbol('symlink');
68
- const HARDLINK = Symbol('hardlink');
69
- const ENSURE_NO_SYMLINK = Symbol('ensureNoSymlink');
70
- const UNSUPPORTED = Symbol('unsupported');
71
- const CHECKPATH = Symbol('checkPath');
72
- const STRIPABSOLUTEPATH = Symbol('stripAbsolutePath');
73
- const MKDIR = Symbol('mkdir');
74
- const ONERROR = Symbol('onError');
75
- const PENDING = Symbol('pending');
76
- const PEND = Symbol('pend');
77
- const UNPEND = Symbol('unpend');
78
- const ENDED = Symbol('ended');
79
- const MAYBECLOSE = Symbol('maybeClose');
80
- const SKIP = Symbol('skip');
81
- const DOCHOWN = Symbol('doChown');
82
- const UID = Symbol('uid');
83
- const GID = Symbol('gid');
84
- const CHECKED_CWD = Symbol('checkedCwd');
85
- const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
86
- const isWindows = platform === 'win32';
43
+ const path_js_1 = require("./path.js");
44
+ const strip_absolute_path_js_1 = require("./strip-absolute-path.js");
45
+ const warn_js_1 = require("./warn.js");
46
+ const win32_path_js_1 = require("./win32-path.js");
47
+ const write_flag_js_1 = require("./write-flag.js");
87
48
  const DEFAULT_MAX_DEPTH = 1024;
88
- // Unlinks on Windows are not atomic.
89
- //
90
- // This means that if you have a file entry, followed by another
91
- // file entry with an identical name, and you cannot re-use the file
92
- // (because it's a hardlink, or because unlink:true is set, or it's
93
- // Windows, which does not have useful nlink values), then the unlink
94
- // will be committed to the disk AFTER the new file has been written
95
- // over the old one, deleting the new file.
96
- //
97
- // To work around this, on Windows systems, we rename the file and then
98
- // delete the renamed file. It's a sloppy kludge, but frankly, I do not
99
- // know of a better way to do this, given windows' non-atomic unlink
100
- // semantics.
101
- //
102
- // See: https://github.com/npm/node-tar/issues/183
103
- /* c8 ignore start */
104
- const unlinkFile = (path, cb) => {
105
- if (!isWindows) {
106
- return node_fs_1.default.unlink(path, cb);
107
- }
108
- const name = path + '.DELETE.' + (0, node_crypto_1.randomBytes)(16).toString('hex');
109
- node_fs_1.default.rename(path, name, er => {
110
- if (er) {
111
- return cb(er);
112
- }
113
- node_fs_1.default.unlink(name, cb);
114
- });
115
- };
116
- /* c8 ignore stop */
117
- /* c8 ignore start */
118
- const unlinkFileSync = (path) => {
119
- if (!isWindows) {
120
- return node_fs_1.default.unlinkSync(path);
121
- }
122
- const name = path + '.DELETE.' + (0, node_crypto_1.randomBytes)(16).toString('hex');
123
- node_fs_1.default.renameSync(path, name);
124
- node_fs_1.default.unlinkSync(name);
125
- };
126
- /* c8 ignore stop */
127
- // this.gid, entry.gid, this.processUid
128
- const uint32 = (a, b, c) => a !== undefined && a === a >>> 0 ? a
49
+ // Longer than any path that a supported platform can create.
50
+ const MAX_PATH_LENGTH = 32768;
51
+ const DEFAULT_JOBS = 16;
52
+ const fileTypes = new Set([
53
+ 'File',
54
+ 'OldFile',
55
+ 'ContiguousFile',
56
+ ]);
57
+ const dirTypes = new Set(['Directory', 'GNUDumpDir']);
58
+ const linkTypes = new Set(['Link', 'SymbolicLink']);
59
+ // The first of the values that is an unsigned 32-bit integer, or the
60
+ // last value.
61
+ const uint32 = (a, b, c) => a !== undefined ? a
129
62
  : b !== undefined && b === b >>> 0 ? b
130
63
  : c;
131
- class Unpack extends parse_js_1.Parser {
132
- [ENDED] = false;
133
- [CHECKED_CWD] = false;
134
- [PENDING] = 0;
135
- reservations = new path_reservations_js_1.PathReservations();
136
- transform;
137
- writable = true;
138
- readable = false;
64
+ /**
65
+ * The parts of the extraction that do not use the file system: the
66
+ * options, the checks of each entry, and the warnings. `Unpack` and
67
+ * `UnpackSync` add the file system work.
68
+ */
69
+ class UnpackBase {
70
+ /** The options, with no prototype. */
71
+ opt;
72
+ /** The absolute path of the extraction directory. */
73
+ cwd;
74
+ win32;
75
+ strip;
76
+ maxDepth;
77
+ preservePaths;
78
+ unlink;
79
+ keep;
80
+ newer;
81
+ noMtime;
82
+ chmod;
139
83
  uid;
140
84
  gid;
141
- setOwner;
142
85
  preserveOwner;
143
- processGid;
144
- processUid;
145
- maxDepth;
146
86
  forceChown;
147
- win32;
148
- newer;
149
- keep;
150
- noMtime;
151
- preservePaths;
152
- unlink;
153
- cwd;
154
- strip;
87
+ processUid;
88
+ processGid;
155
89
  processUmask;
156
90
  umask;
157
91
  dmode;
158
92
  fmode;
159
- chmod;
160
- constructor(opt = {}) {
161
- opt.ondone = () => {
162
- this[ENDED] = true;
163
- this[MAYBECLOSE]();
164
- };
165
- super(opt);
166
- this.transform = opt.transform;
167
- this.chmod = !!opt.chmod;
93
+ /** Gives the `open` flag for a new file of a given size. */
94
+ writeFlag;
95
+ /** Resolve a path from an absolute path. */
96
+ resolve;
97
+ /** The parent directory of an absolute path. */
98
+ dirname;
99
+ /** Set when an error stops the extraction. */
100
+ fatal;
101
+ constructor(options) {
102
+ const opt = (this.opt = (0, options_js_1.ownOptions)(options));
103
+ const win32 = (this.win32 = opt.platform === 'win32');
104
+ this.resolve = win32 ? win32_path_js_1.win32Resolve : path_js_1.resolve;
105
+ this.dirname = win32 ? win32_path_js_1.win32Dirname : path_js_1.dirname;
106
+ if (typeof opt.cwd !== 'string') {
107
+ throw new TypeError('cwd is required');
108
+ }
109
+ const cwd = win32 ? opt.cwd.replaceAll('\\', '/') : opt.cwd;
110
+ if (!(win32 ? win32_path_js_1.win32IsAbsolute : path_js_1.isAbsolute)(cwd)) {
111
+ throw new TypeError('cwd must be an absolute path');
112
+ }
113
+ this.cwd = this.resolve(cwd, '');
168
114
  if (typeof opt.uid === 'number' || typeof opt.gid === 'number') {
169
115
  // need both or neither
170
116
  if (typeof opt.uid !== 'number' || typeof opt.gid !== 'number') {
171
117
  throw new TypeError('cannot set owner without number uid and gid');
172
118
  }
119
+ // A value that is not valid must not fall back to the owner
120
+ // in the archive.
121
+ if (opt.uid !== opt.uid >>> 0 || opt.gid !== opt.gid >>> 0) {
122
+ throw new TypeError('uid and gid must be unsigned 32-bit integers');
123
+ }
173
124
  if (opt.preserveOwner) {
174
125
  throw new TypeError('cannot preserve owner in archive and also set owner explicitly');
175
126
  }
176
127
  this.uid = opt.uid;
177
128
  this.gid = opt.gid;
178
- this.setOwner = true;
179
- }
180
- else {
181
- this.uid = undefined;
182
- this.gid = undefined;
183
- this.setOwner = false;
184
129
  }
185
- // default true for root
130
+ this.processUid = opt.processUid;
131
+ this.processGid = opt.processGid;
186
132
  this.preserveOwner =
187
133
  opt.preserveOwner === undefined && typeof opt.uid !== 'number' ?
188
- !!(process.getuid?.() === 0)
134
+ opt.processUid === 0
189
135
  : !!opt.preserveOwner;
190
- this.processUid =
191
- (this.preserveOwner || this.setOwner) && process.getuid ?
192
- process.getuid()
193
- : undefined;
194
- this.processGid =
195
- (this.preserveOwner || this.setOwner) && process.getgid ?
196
- process.getgid()
197
- : undefined;
198
- // prevent excessively deep nesting of subfolders
199
- // set to `Infinity` to remove this restriction
136
+ this.forceChown = opt.forceChown === true;
200
137
  this.maxDepth =
201
138
  typeof opt.maxDepth === 'number' ? opt.maxDepth : DEFAULT_MAX_DEPTH;
202
- // mostly just for testing, but useful in some cases.
203
- // Forcibly trigger a chown on every entry, no matter what
204
- this.forceChown = opt.forceChown === true;
205
- // turn ><?| in filenames into 0xf000-higher encoded forms
206
- this.win32 = !!opt.win32 || isWindows;
207
- // do not unpack over files that are newer than what's in the archive
208
- this.newer = !!opt.newer;
209
- // do not unpack over ANY files
210
- this.keep = !!opt.keep;
211
- // do not set mtime/atime of extracted entries
212
- this.noMtime = !!opt.noMtime;
213
- // allow .., absolute path entries, and unpacking through symlinks
214
- // without this, warn and skip .., relativize absolutes, and error
215
- // on symlinks in extraction path
139
+ this.strip = Number(opt.strip) || 0;
216
140
  this.preservePaths = !!opt.preservePaths;
217
- // unlink files and links before writing. This breaks existing hard
218
- // links, and removes symlink directories rather than erroring
219
141
  this.unlink = !!opt.unlink;
220
- this.cwd = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(opt.cwd || process.cwd()));
221
- this.strip = Number(opt.strip) || 0;
222
- // if we're not chmodding, then we don't need the process umask
142
+ this.keep = !!opt.keep;
143
+ this.newer = !!opt.newer;
144
+ this.noMtime = !!opt.noMtime;
145
+ this.chmod = !!opt.chmod;
146
+ // Without chmod, the umask of the process is not needed.
223
147
  this.processUmask =
224
148
  !this.chmod ? 0
225
149
  : typeof opt.processUmask === 'number' ? opt.processUmask
226
- : (0, process_umask_js_1.umask)();
150
+ : 0o22;
227
151
  this.umask =
228
152
  typeof opt.umask === 'number' ? opt.umask : this.processUmask;
229
- // default mode for dirs created as parents
230
- this.dmode = opt.dmode || 0o0777 & ~this.umask;
231
- this.fmode = opt.fmode || 0o0666 & ~this.umask;
232
- this.on('entry', entry => this[ONENTRY](entry));
233
- }
234
- // a bad or damaged archive is a warning for Parser, but an error
235
- // when extracting. Mark those errors as unrecoverable, because
236
- // the Unpack contract cannot be met.
237
- warn(code, msg, data = {}) {
153
+ this.dmode = opt.dmode || 0o777 & ~this.umask;
154
+ this.fmode = opt.fmode || 0o666 & ~this.umask;
155
+ this.writeFlag = (0, write_flag_js_1.writeFlags)(opt.fs.constants, win32);
156
+ }
157
+ /**
158
+ * Report a problem to `onwarn`, or throw it if `strict` is set. A
159
+ * damaged archive is always an error here, because the extraction
160
+ * cannot be complete.
161
+ */
162
+ warn(code, message, data = {}) {
238
163
  if (code === 'TAR_BAD_ARCHIVE' || code === 'TAR_ABORT') {
239
164
  data.recoverable = false;
240
165
  }
241
- return super.warn(code, msg, data);
166
+ data.cwd = this.cwd;
167
+ (0, warn_js_1.warn)(this.opt, code, message, data);
242
168
  }
243
- [MAYBECLOSE]() {
244
- if (this[ENDED] && this[PENDING] === 0) {
245
- this.emit('prefinish');
246
- this.emit('finish');
247
- this.emit('end');
248
- }
169
+ /** The options for the reader. Its warnings go to `warn()`. */
170
+ readerOptions() {
171
+ return (0, options_js_1.ownOptions)(this.opt, {
172
+ strict: false,
173
+ onwarn: (code, message, data) => this.warn(code, message, data),
174
+ });
249
175
  }
250
- // return false if we need to skip this file
251
- // return true if the field was successfully sanitized
252
- [STRIPABSOLUTEPATH](entry, field) {
176
+ /**
177
+ * Report the failure of one entry as a `TAR_ENTRY_ERROR` warning.
178
+ * Throws the error if it stops the extraction: the extraction
179
+ * directory is not usable, the archive cannot be read, or `strict`
180
+ * is set.
181
+ */
182
+ entryError(er, entry) {
183
+ if (this.fatal?.error === er || er?.name === 'CwdError') {
184
+ throw er;
185
+ }
186
+ this.warn('TAR_ENTRY_ERROR', er, { entry });
187
+ }
188
+ /** Record the error that stops the extraction. Returns it. */
189
+ fail(error) {
190
+ this.fatal ??= { error };
191
+ return error;
192
+ }
193
+ // Remove the root of an absolute path, and refuse a path that can
194
+ // leave the extraction directory. False if the entry is refused.
195
+ #stripAbsolutePath(entry, field) {
253
196
  const p = entry[field];
254
- const { type } = entry;
255
197
  if (!p || this.preservePaths)
256
198
  return true;
257
- // strip off the root
258
199
  const [root, stripped] = (0, strip_absolute_path_js_1.stripAbsolutePath)(p);
259
- const parts = stripped.replaceAll(/\\/g, '/').split('/');
260
- if (parts.includes('..') ||
261
- /* c8 ignore next */
262
- (isWindows && /^[a-z]:\.\.$/i.test(parts[0] ?? ''))) {
263
- // For linkpath, check if the resolved path escapes cwd rather than
264
- // just rejecting any path with '..' - relative symlinks like
265
- // '../sibling/file' are valid if they resolve within the cwd.
266
- // For paths, they just simply may not ever use .. at all.
267
- if (field === 'path' || type === 'Link') {
200
+ const parts = stripped.replaceAll('\\', '/').split('/');
201
+ if (parts.includes('..')) {
202
+ // A path, and the target of a hard link, cannot have '..' at
203
+ // all. The target of a symbolic link is relative to the
204
+ // directory of the link, so '../sibling/file' can be valid.
205
+ if (field === 'path' || entry.type === 'Link') {
268
206
  this.warn('TAR_ENTRY_ERROR', `${field} contains '..'`, {
269
207
  entry,
270
208
  [field]: p,
271
209
  });
272
- // not ok!
273
210
  return false;
274
211
  }
275
- // Resolve linkpath relative to the entry's directory.
276
- // `path.posix` is safe to use because we're operating on
277
- // tar paths, not a filesystem.
278
- const entryDir = node_path_1.default.posix.dirname(entry.path);
279
- const resolved = node_path_1.default.posix.normalize(node_path_1.default.posix.join(entryDir, parts.join('/')));
280
- // If the resolved path escapes (starts with ..), reject it
212
+ // A '..' is only safe at the start of the target. Any named
213
+ // part before it can be a symlink, and then the '..' goes to
214
+ // the parent of the target of that symlink.
215
+ const firstName = parts.findIndex(part => part !== '..' && part !== '.' && part !== '');
216
+ if (firstName !== -1 && parts.includes('..', firstName)) {
217
+ this.warn('TAR_ENTRY_ERROR', `${field} contains '..' after a path portion`, { entry, [field]: p });
218
+ return false;
219
+ }
220
+ // Normalize the path, so that the directory is the one where
221
+ // the link is created. The path 'x/.' creates the link 'x'.
222
+ const entryDir = (0, path_js_1.dirname)((0, path_js_1.normalize)(entry.path));
223
+ const resolved = (0, path_js_1.normalize)((0, path_js_1.join)(entryDir, parts.join('/')));
281
224
  if (resolved.startsWith('../') || resolved === '..') {
282
- this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, {
283
- entry,
284
- [field]: p,
285
- });
225
+ this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, { entry, [field]: p });
286
226
  return false;
287
227
  }
288
228
  }
289
229
  if (root) {
290
- // ok, but triggers warning about stripping root
291
- entry[field] = String(stripped);
292
- this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, {
293
- entry,
294
- [field]: p,
295
- });
230
+ ;
231
+ entry[field] = stripped;
232
+ this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute ${field}`, { entry, [field]: p });
296
233
  }
297
234
  return true;
298
235
  }
299
- // no IO, just string checking for absolute indicators
300
- [CHECKPATH](entry) {
301
- const p = (0, normalize_windows_path_js_1.normalizeWindowsPath)(entry.path);
236
+ /**
237
+ * Check the entry, with no use of the file system. Set its
238
+ * `absolute` path, and change its `path`, `linkpath`, and `mode` to
239
+ * the values to extract. False if the entry must not be extracted.
240
+ */
241
+ check(entry) {
242
+ const p = entry.path;
302
243
  const parts = p.split('/');
303
244
  if (this.strip) {
304
- if (parts.length < this.strip) {
245
+ if (parts.length < this.strip)
305
246
  return false;
306
- }
307
247
  if (entry.type === 'Link') {
308
- const linkparts = (0, normalize_windows_path_js_1.normalizeWindowsPath)(String(entry.linkpath)).split('/');
309
- if (linkparts.length >= this.strip) {
310
- entry.linkpath = linkparts.slice(this.strip).join('/');
311
- }
312
- else {
248
+ const linkparts = String(entry.linkpath).split('/');
249
+ if (linkparts.length < this.strip)
313
250
  return false;
314
- }
251
+ entry.linkpath = linkparts.slice(this.strip).join('/');
315
252
  }
316
253
  parts.splice(0, this.strip);
254
+ // No part of the path is left, as for the top directory of a
255
+ // package. The entry must not change the extraction directory.
256
+ if (parts.every(part => part === ''))
257
+ return false;
317
258
  entry.path = parts.join('/');
318
259
  }
319
- if (isFinite(this.maxDepth) && parts.length > this.maxDepth) {
260
+ const { maxDepth } = this;
261
+ if (isFinite(maxDepth) && parts.length > maxDepth) {
320
262
  this.warn('TAR_ENTRY_ERROR', 'path excessively deep', {
321
263
  entry,
322
264
  path: p,
323
265
  depth: parts.length,
324
- maxDepth: this.maxDepth,
266
+ maxDepth,
267
+ });
268
+ return false;
269
+ }
270
+ // The path reservations do work for each parent directory of the
271
+ // path and of the linkpath.
272
+ const { linkpath } = entry;
273
+ if (linkpath &&
274
+ isFinite(maxDepth) &&
275
+ linkpath.split('/').length > maxDepth) {
276
+ this.warn('TAR_ENTRY_ERROR', 'linkpath excessively deep', {
277
+ entry,
278
+ path: p,
279
+ linkpath,
280
+ maxDepth,
325
281
  });
326
282
  return false;
327
283
  }
328
- if (!this[STRIPABSOLUTEPATH](entry, 'path') ||
329
- !this[STRIPABSOLUTEPATH](entry, 'linkpath')) {
284
+ for (const field of ['path', 'linkpath']) {
285
+ const { length } = entry[field] ?? '';
286
+ if (length > MAX_PATH_LENGTH) {
287
+ this.warn('TAR_ENTRY_ERROR', `${field} excessively long`, {
288
+ entry,
289
+ path: p,
290
+ length,
291
+ maxLength: MAX_PATH_LENGTH,
292
+ });
293
+ return false;
294
+ }
295
+ }
296
+ if (!this.#stripAbsolutePath(entry, 'path') ||
297
+ !this.#stripAbsolutePath(entry, 'linkpath')) {
330
298
  return false;
331
299
  }
332
- entry.absolute =
333
- node_path_1.default.isAbsolute(entry.path) ?
334
- (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(entry.path))
335
- : (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(this.cwd, entry.path));
336
- // if we somehow ended up with a path that escapes the cwd, and we are
337
- // not in preservePaths mode, then something is fishy! This should have
338
- // been prevented above, so ignore this for coverage.
339
- /* c8 ignore start - defense in depth */
300
+ const { cwd } = this;
301
+ let absolute = this.resolve(cwd, entry.path);
302
+ // The checks above refuse a path that leaves the extraction
303
+ // directory. This check is defense in depth.
340
304
  if (!this.preservePaths &&
341
- typeof entry.absolute === 'string' &&
342
- entry.absolute.indexOf(this.cwd + '/') !== 0 &&
343
- entry.absolute !== this.cwd) {
305
+ absolute !== cwd &&
306
+ // A root, such as `/` or `c:/`, ends with a slash.
307
+ !absolute.startsWith(cwd.endsWith('/') ? cwd : cwd + '/')) {
344
308
  this.warn('TAR_ENTRY_ERROR', 'path escaped extraction target', {
345
309
  entry,
346
- path: (0, normalize_windows_path_js_1.normalizeWindowsPath)(entry.path),
347
- resolvedPath: entry.absolute,
348
- cwd: this.cwd,
310
+ path: entry.path,
311
+ resolvedPath: absolute,
312
+ cwd,
349
313
  });
350
314
  return false;
351
315
  }
352
- /* c8 ignore stop */
353
- // an archive can set properties on the extraction directory, but it
354
- // may not replace the cwd with a different kind of thing entirely.
355
- if (entry.absolute === this.cwd &&
356
- entry.type !== 'Directory' &&
357
- entry.type !== 'GNUDumpDir') {
316
+ // An archive can set properties of the extraction directory, but
317
+ // it cannot replace it with a different kind of thing.
318
+ if (absolute === cwd && !dirTypes.has(entry.type))
358
319
  return false;
359
- }
360
- // only encode : chars that aren't drive letter indicators
320
+ // Do not change the ':' of a drive letter.
361
321
  if (this.win32) {
362
- const { root: aRoot } = node_path_1.default.win32.parse(String(entry.absolute));
363
- entry.absolute =
364
- aRoot + wc.encode(String(entry.absolute).slice(aRoot.length));
365
- const { root: pRoot } = node_path_1.default.win32.parse(entry.path);
322
+ const aRoot = (0, win32_path_js_1.win32Root)(absolute);
323
+ absolute = aRoot + wc.encode(absolute.slice(aRoot.length));
324
+ const pRoot = (0, win32_path_js_1.win32Root)(entry.path);
366
325
  entry.path = pRoot + wc.encode(entry.path.slice(pRoot.length));
367
326
  }
368
- return true;
369
- }
370
- [ONENTRY](entry) {
371
- if (!this[CHECKPATH](entry)) {
372
- return entry.resume();
373
- }
374
- node_assert_1.default.equal(typeof entry.absolute, 'string');
375
- switch (entry.type) {
376
- case 'Directory':
377
- case 'GNUDumpDir':
378
- if (entry.mode) {
379
- entry.mode = entry.mode | 0o700;
380
- }
381
- // eslint-disable-next-line no-fallthrough
382
- case 'File':
383
- case 'OldFile':
384
- case 'ContiguousFile':
385
- case 'Link':
386
- case 'SymbolicLink':
387
- return this[CHECKFS](entry);
388
- case 'CharacterDevice':
389
- case 'BlockDevice':
390
- case 'FIFO':
391
- default:
392
- return this[UNSUPPORTED](entry);
393
- }
394
- }
395
- [ONERROR](er, entry) {
396
- // Cwd has to exist, or else nothing works. That's serious.
397
- // Other errors are warnings, which raise the error in strict
398
- // mode, but otherwise continue on.
399
- if (er.name === 'CwdError') {
400
- this.emit('error', er);
401
- }
402
- else {
403
- this.warn('TAR_ENTRY_ERROR', er, { entry });
404
- this[UNPEND]();
405
- entry.resume();
327
+ entry.absolute = absolute;
328
+ // Never set the setuid, setgid, or sticky bit from an archive.
329
+ if (typeof entry.mode === 'number')
330
+ entry.mode &= 0o777;
331
+ if (dirTypes.has(entry.type)) {
332
+ if (entry.mode)
333
+ entry.mode |= 0o700;
334
+ }
335
+ else if (!fileTypes.has(entry.type) && !linkTypes.has(entry.type)) {
336
+ // A device or a FIFO is never made.
337
+ entry.unsupported = true;
338
+ this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
339
+ return false;
406
340
  }
341
+ return true;
407
342
  }
408
- [MKDIR](dir, mode, cb) {
409
- void (0, mkdir_js_1.mkdir)((0, normalize_windows_path_js_1.normalizeWindowsPath)(dir), {
343
+ /**
344
+ * The paths that the entry must have for itself while it is made.
345
+ * A link also reserves its target, so that an entry that makes the
346
+ * target, and an entry that goes through the link, do not run at
347
+ * the same time as the link.
348
+ */
349
+ reservedPaths(entry) {
350
+ const { path, linkpath } = entry;
351
+ if (!linkpath)
352
+ return [path];
353
+ // The target of a symlink is relative to the directory of the
354
+ // link. The target of a hard link is relative to the cwd.
355
+ return [
356
+ path,
357
+ entry.type === 'SymbolicLink' && !(0, path_js_1.isAbsolute)(linkpath) ?
358
+ (0, path_js_1.join)((0, path_js_1.dirname)(path), linkpath)
359
+ : linkpath,
360
+ ];
361
+ }
362
+ /** The options to make a directory with a mode. */
363
+ mkdirOptions(mode) {
364
+ return {
410
365
  uid: this.uid,
411
366
  gid: this.gid,
412
367
  processUid: this.processUid,
@@ -415,517 +370,617 @@ class Unpack extends parse_js_1.Parser {
415
370
  preserve: this.preservePaths,
416
371
  unlink: this.unlink,
417
372
  cwd: this.cwd,
418
- mode: mode,
419
- }, cb);
373
+ mode,
374
+ };
420
375
  }
421
- [DOCHOWN](entry) {
422
- // in preserve owner mode, chown if the entry doesn't match process
423
- // in set owner mode, chown if setting doesn't match process
424
- return (this.forceChown ||
376
+ /**
377
+ * The owner to set on the entry, if it needs one: with
378
+ * `preserveOwner`, when the owner in the archive is not the process
379
+ * owner, and with `uid` and `gid`, when they are not the process
380
+ * owner.
381
+ */
382
+ owner(entry) {
383
+ const doChown = this.forceChown ||
425
384
  (this.preserveOwner &&
426
385
  ((typeof entry.uid === 'number' &&
427
386
  entry.uid !== this.processUid) ||
428
387
  (typeof entry.gid === 'number' &&
429
388
  entry.gid !== this.processGid))) ||
430
389
  (typeof this.uid === 'number' && this.uid !== this.processUid) ||
431
- (typeof this.gid === 'number' && this.gid !== this.processGid));
432
- }
433
- [UID](entry) {
434
- return uint32(this.uid, entry.uid, this.processUid);
435
- }
436
- [GID](entry) {
437
- return uint32(this.gid, entry.gid, this.processGid);
390
+ (typeof this.gid === 'number' && this.gid !== this.processGid);
391
+ const uid = uint32(this.uid, entry.uid, this.processUid);
392
+ const gid = uint32(this.gid, entry.gid, this.processGid);
393
+ return doChown && typeof uid === 'number' && typeof gid === 'number' ?
394
+ { uid, gid }
395
+ : undefined;
396
+ }
397
+ /** The times to set on the entry, if it needs them. */
398
+ times(entry) {
399
+ return entry.mtime && !this.noMtime ?
400
+ { atime: entry.atime || new Date(), mtime: entry.mtime }
401
+ : undefined;
402
+ }
403
+ /** True if the object on disk at the path of the entry must stay. */
404
+ skip(entry, st) {
405
+ return (this.keep || (this.newer && st.mtime > (entry.mtime ?? st.mtime)));
406
+ }
407
+ /**
408
+ * True if the entry can be written into the file that is on disk.
409
+ * A file with more than one link is not used, because the write
410
+ * would change the other links. Windows does not report a useful
411
+ * link count.
412
+ */
413
+ isReusable(entry, st) {
414
+ return (entry.type === 'File' &&
415
+ !this.unlink &&
416
+ st.isFile() &&
417
+ st.nlink <= 1 &&
418
+ !this.win32);
419
+ }
420
+ /**
421
+ * The parts of the path from the extraction directory to the
422
+ * target of a link entry. None of them can be a symbolic link.
423
+ */
424
+ linkParts(entry, absolute) {
425
+ const linkpath = String(entry.linkpath);
426
+ return entry.type === 'Link' ?
427
+ linkpath.split('/')
428
+ : (0, path_js_1.relative)(this.cwd, this.resolve(this.dirname(absolute), linkpath)).split('/');
429
+ }
430
+ /**
431
+ * The parts of the path from the extraction directory to the
432
+ * parent directory of an entry. The extraction checks them again
433
+ * after it makes the entry: none of them can be a symbolic link
434
+ * then. So a directory that another process replaced with a
435
+ * symbolic link during the extraction is an error of the entry.
436
+ */
437
+ parentParts(absolute) {
438
+ const { cwd } = this;
439
+ const parent = absolute === cwd ? cwd : this.dirname(absolute);
440
+ return parent === cwd ? [] : (0, path_js_1.relative)(cwd, parent).split('/');
441
+ }
442
+ /** The error for a link target that goes through a symbolic link. */
443
+ symlinkError(symlink, parts) {
444
+ return new symlink_error_js_1.SymlinkError(symlink, this.resolve(this.cwd, parts.join('/')));
438
445
  }
439
- [FILE](entry, fullyDone) {
440
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
441
- const stream = new fsm.WriteStream(String(entry.absolute), {
442
- // slight lie, but it can be numeric flags
443
- flags: (0, get_write_flag_js_1.getWriteFlag)(entry.size),
444
- mode: mode,
445
- autoClose: false,
446
- });
447
- stream.on('error', (er) => {
448
- if (stream.fd) {
449
- node_fs_1.default.close(stream.fd, () => { });
450
- }
451
- // flush all the data out so that we aren't left hanging
452
- // if the error wasn't actually fatal. otherwise the parse
453
- // is blocked, and we never proceed.
454
- stream.write = () => true;
455
- this[ONERROR](er, entry);
456
- fullyDone();
457
- });
458
- let actions = 1;
459
- const done = (er) => {
460
- if (er) {
461
- /* c8 ignore start - we should always have a fd by now */
462
- if (stream.fd) {
463
- node_fs_1.default.close(stream.fd, () => { });
446
+ }
447
+ exports.UnpackBase = UnpackBase;
448
+ // Unlinks on Windows are not atomic. A file that is made at the path
449
+ // of a file that was just removed can be removed with it. So rename
450
+ // the file first, and then remove it under the new name.
451
+ const deleteName = (path) => path +
452
+ '.DELETE.' +
453
+ Array.from(crypto.getRandomValues(new Uint8Array(16)), b => b.toString(16).padStart(2, '0')).join('');
454
+ /**
455
+ * Extracts the entries of an archive with async file system
456
+ * functions.
457
+ *
458
+ * Several entries are extracted at one time. Entries that use the
459
+ * same path, or a path and a directory above it, are extracted in
460
+ * the order of the archive.
461
+ */
462
+ class Unpack extends UnpackBase {
463
+ #fs;
464
+ #reservations;
465
+ #jobs;
466
+ // the number of entries that are in work
467
+ #active = 0;
468
+ #wake;
469
+ #checkedCwd = false;
470
+ #cwdCheck;
471
+ constructor(opt) {
472
+ super(opt);
473
+ this.#fs = this.opt.fs;
474
+ this.#reservations = new path_reservations_js_1.PathReservations(this.win32);
475
+ this.#jobs = (0, options_js_1.countOption)('jobs', this.opt.jobs, DEFAULT_JOBS);
476
+ }
477
+ /**
478
+ * Extract the archive. The promise settles when all the file
479
+ * system work is done. It rejects with the first error that stops
480
+ * the extraction.
481
+ */
482
+ async extract(input) {
483
+ const reader = new entries_js_1.TarReader(input, this.readerOptions());
484
+ const { onEntry } = this.opt;
485
+ const stream = !!this.opt.transform;
486
+ try {
487
+ while (!this.fatal) {
488
+ const entry = reader.poll();
489
+ if (entry === null)
490
+ break;
491
+ if (entry === undefined) {
492
+ await reader.fill();
493
+ continue;
464
494
  }
465
- /* c8 ignore stop */
466
- this[ONERROR](er, entry);
467
- fullyDone();
468
- return;
469
- }
470
- if (--actions === 0) {
471
- if (stream.fd !== undefined) {
472
- node_fs_1.default.close(stream.fd, er => {
473
- if (er) {
474
- this[ONERROR](er, entry);
495
+ if (onEntry)
496
+ await onEntry(entry);
497
+ // The caller took the content, so there is nothing to write.
498
+ if (entry.bodyUsed)
499
+ continue;
500
+ if (!this.check(entry))
501
+ continue;
502
+ // A file whose content is all in memory is written while the
503
+ // next entries are read. Other files are written as their
504
+ // content arrives.
505
+ const body = [];
506
+ let inMemory = !stream;
507
+ if (inMemory && fileTypes.has(entry.type)) {
508
+ for (;;) {
509
+ const part = reader.readBody(entry);
510
+ if (part === null)
511
+ break;
512
+ if (part === undefined) {
513
+ inMemory = false;
514
+ break;
475
515
  }
476
- else {
477
- this[UNPEND]();
478
- }
479
- fullyDone();
480
- });
516
+ body.push(part);
517
+ }
481
518
  }
519
+ const work = this.#start(entry, body, inMemory ? undefined : reader);
520
+ if (!inMemory)
521
+ await work;
522
+ while (this.#active >= this.#jobs)
523
+ await this.#idle();
482
524
  }
483
- };
484
- stream.on('finish', () => {
485
- // if futimes fails, try utimes
486
- // if utimes fails, fail with the original error
487
- // same for fchown/chown
488
- const abs = String(entry.absolute);
489
- const fd = stream.fd;
490
- if (typeof fd === 'number' && entry.mtime && !this.noMtime) {
491
- actions++;
492
- const atime = entry.atime || new Date();
493
- const mtime = entry.mtime;
494
- node_fs_1.default.futimes(fd, atime, mtime, er => er ?
495
- node_fs_1.default.utimes(abs, atime, mtime, er2 => done(er2 && er))
496
- : done());
497
- }
498
- if (typeof fd === 'number' && this[DOCHOWN](entry)) {
499
- actions++;
500
- const uid = this[UID](entry);
501
- const gid = this[GID](entry);
502
- if (typeof uid === 'number' && typeof gid === 'number') {
503
- node_fs_1.default.fchown(fd, uid, gid, er => er ? node_fs_1.default.chown(abs, uid, gid, er2 => done(er2 && er)) : done());
504
- }
525
+ }
526
+ catch (er) {
527
+ this.fail(er);
528
+ }
529
+ await reader.return().catch(er => this.fail(er));
530
+ while (this.#active > 0)
531
+ await this.#idle();
532
+ if (this.fatal) {
533
+ const { error } = this.fatal;
534
+ if (error && typeof error === 'object' && 'tarCode' in error) {
535
+ Object.assign(error, { cwd: this.cwd });
505
536
  }
506
- done();
507
- });
508
- const tx = this.transform ? this.transform(entry) || entry : entry;
509
- if (tx !== entry) {
510
- tx.on('error', er => {
511
- this[ONERROR](er, entry);
512
- fullyDone();
513
- });
514
- entry.pipe(tx);
537
+ throw error;
515
538
  }
516
- tx.pipe(stream);
517
539
  }
518
- [DIRECTORY](entry, fullyDone) {
519
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
520
- this[MKDIR](String(entry.absolute), mode, er => {
521
- if (er) {
522
- this[ONERROR](er, entry);
523
- fullyDone();
524
- return;
540
+ // Resolves when an entry that is in work is done.
541
+ #idle() {
542
+ return new Promise(res => {
543
+ this.#wake = res;
544
+ });
545
+ }
546
+ // Extract the entry when its paths are free. The promise never
547
+ // rejects: a failure is a warning, or it sets `fatal`.
548
+ #start(entry, body, reader) {
549
+ this.#active++;
550
+ return this.#reservations.reserve(this.reservedPaths(entry), async () => {
551
+ try {
552
+ if (!this.fatal)
553
+ await this.#extract(entry, body, reader);
525
554
  }
526
- let actions = 1;
527
- const done = () => {
528
- if (--actions === 0) {
529
- fullyDone();
530
- this[UNPEND]();
531
- entry.resume();
555
+ catch (er) {
556
+ try {
557
+ this.entryError(er, entry);
558
+ }
559
+ catch (fatal) {
560
+ this.fail(fatal);
532
561
  }
533
- };
534
- if (entry.mtime && !this.noMtime) {
535
- actions++;
536
- node_fs_1.default.utimes(String(entry.absolute), entry.atime || new Date(), entry.mtime, done);
537
- }
538
- if (this[DOCHOWN](entry)) {
539
- actions++;
540
- node_fs_1.default.chown(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)), done);
541
562
  }
542
- done();
543
- });
544
- }
545
- [UNSUPPORTED](entry) {
546
- entry.unsupported = true;
547
- this.warn('TAR_ENTRY_UNSUPPORTED', `unsupported entry type: ${entry.type}`, { entry });
548
- entry.resume();
549
- }
550
- [SYMLINK](entry, done) {
551
- const parts = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.relative(this.cwd, node_path_1.default.resolve(node_path_1.default.dirname(String(entry.absolute)), String(entry.linkpath)))).split('/');
552
- this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, String(entry.linkpath), 'symlink', done), er => {
553
- this[ONERROR](er, entry);
554
- done();
555
- });
556
- }
557
- [HARDLINK](entry, done) {
558
- const linkpath = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(this.cwd, String(entry.linkpath)));
559
- const parts = (0, normalize_windows_path_js_1.normalizeWindowsPath)(String(entry.linkpath)).split('/');
560
- this[ENSURE_NO_SYMLINK](entry, this.cwd, parts, () => this[LINK](entry, linkpath, 'link', done), er => {
561
- this[ONERROR](er, entry);
562
- done();
563
- });
564
- }
565
- [ENSURE_NO_SYMLINK](entry, cwd, parts, done, onError) {
566
- const p = parts.shift();
567
- if (this.preservePaths || p === undefined)
568
- return done();
569
- const t = node_path_1.default.resolve(cwd, p);
570
- node_fs_1.default.lstat(t, (er, st) => {
571
- if (er)
572
- return done();
573
- if (st?.isSymbolicLink()) {
574
- return onError(new symlink_error_js_1.SymlinkError(t, node_path_1.default.resolve(t, parts.join('/'))));
575
- }
576
- this[ENSURE_NO_SYMLINK](entry, t, parts, done, onError);
563
+ this.#active--;
564
+ this.#wake?.();
577
565
  });
578
566
  }
579
- [PEND]() {
580
- this[PENDING]++;
581
- }
582
- [UNPEND]() {
583
- this[PENDING]--;
584
- this[MAYBECLOSE]();
567
+ #mkdir(dir, mode) {
568
+ return (0, mkdir_js_1.mkdir)(this.#fs, dir, this.mkdirOptions(mode));
569
+ }
570
+ // The extraction directory must exist. Entries that start at the
571
+ // same time share one check.
572
+ #checkCwd() {
573
+ return (this.#cwdCheck ??= this.#mkdir(this.cwd, this.dmode).then(() => {
574
+ this.#checkedCwd = true;
575
+ }, er => {
576
+ this.#cwdCheck = undefined;
577
+ throw er;
578
+ }));
579
+ }
580
+ async #extract(entry, body, reader) {
581
+ const fs = this.#fs;
582
+ const absolute = entry.absolute;
583
+ const { cwd } = this;
584
+ if (!this.#checkedCwd)
585
+ await this.#checkCwd();
586
+ if (absolute !== cwd) {
587
+ const parent = this.dirname(absolute);
588
+ if (parent !== cwd)
589
+ await this.#mkdir(parent, this.dmode);
590
+ }
591
+ // Remove what is at the path, if the entry cannot use it.
592
+ const st = await fs.lstat(absolute).catch(() => undefined);
593
+ if (st && this.skip(entry, st))
594
+ return;
595
+ if (st && !this.isReusable(entry, st)) {
596
+ if (st.isDirectory() && dirTypes.has(entry.type)) {
597
+ if (this.chmod &&
598
+ entry.mode &&
599
+ (st.mode & 0o7777) !== entry.mode) {
600
+ await fs.chmod(absolute, entry.mode);
601
+ }
602
+ }
603
+ else if (absolute !== cwd) {
604
+ if (st.isDirectory())
605
+ await fs.rmdir(absolute);
606
+ else
607
+ await this.#unlink(absolute);
608
+ }
609
+ }
610
+ if (fileTypes.has(entry.type)) {
611
+ return this.#file(entry, absolute, body, reader);
612
+ }
613
+ if (dirTypes.has(entry.type))
614
+ await this.#directory(entry, absolute);
615
+ else {
616
+ await this.#ensureNoSymlink(this.linkParts(entry, absolute));
617
+ const linkpath = String(entry.linkpath);
618
+ if (entry.type === 'Link') {
619
+ await fs.link(this.resolve(cwd, linkpath), absolute);
620
+ }
621
+ else {
622
+ await fs.symlink(linkpath, absolute);
623
+ }
624
+ }
625
+ await this.#ensureNoSymlink(this.parentParts(absolute));
585
626
  }
586
- [SKIP](entry) {
587
- this[UNPEND]();
588
- entry.resume();
627
+ async #unlink(path) {
628
+ const fs = this.#fs;
629
+ if (!this.win32)
630
+ return fs.unlink(path);
631
+ const name = deleteName(path);
632
+ await fs.rename(path, name);
633
+ await fs.unlink(name);
589
634
  }
590
- // Check if we can reuse an existing filesystem entry safely and
591
- // overwrite it, rather than unlinking and recreating
592
- // Windows doesn't report a useful nlink, so we just never reuse entries
593
- [ISREUSABLE](entry, st) {
594
- return (entry.type === 'File' &&
595
- !this.unlink &&
596
- st.isFile() &&
597
- st.nlink <= 1 &&
598
- !isWindows);
635
+ async #ensureNoSymlink(parts) {
636
+ if (this.preservePaths)
637
+ return;
638
+ let t = this.cwd;
639
+ for (const p of parts) {
640
+ t = this.resolve(t, p);
641
+ const st = await this.#fs.lstat(t).catch(() => undefined);
642
+ if (!st)
643
+ return;
644
+ if (st.isSymbolicLink())
645
+ throw this.symlinkError(t, parts);
646
+ }
599
647
  }
600
- // check if a thing is there, and if so, try to clobber it
601
- [CHECKFS](entry) {
602
- this[PEND]();
603
- const paths = [entry.path];
604
- if (entry.linkpath) {
605
- paths.push(entry.linkpath);
648
+ async #directory(entry, absolute) {
649
+ const fs = this.#fs;
650
+ await this.#mkdir(absolute, entry.mode ?? this.dmode);
651
+ // These do not follow a symbolic link that replaced the
652
+ // directory. A failure is not an error of the entry.
653
+ const times = this.times(entry);
654
+ if (times) {
655
+ await fs.lutimes(absolute, times.atime, times.mtime).catch(() => { });
656
+ }
657
+ const owner = this.owner(entry);
658
+ if (owner) {
659
+ await fs.lchown(absolute, owner.uid, owner.gid).catch(() => { });
606
660
  }
607
- this.reservations.reserve(paths, done => this[CHECKFS2](entry, done));
608
661
  }
609
- [CHECKFS2](entry, fullyDone) {
610
- const done = (er) => {
611
- fullyDone(er);
612
- };
613
- const checkCwd = () => {
614
- this[MKDIR](this.cwd, this.dmode, er => {
615
- if (er) {
616
- this[ONERROR](er, entry);
617
- done();
618
- return;
662
+ async #file(entry, absolute, body, reader) {
663
+ const fs = this.#fs;
664
+ const handle = await fs.open(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
665
+ try {
666
+ // The file is open. Write to it only if no parent directory
667
+ // became a symbolic link before the open.
668
+ await this.#ensureNoSymlink(this.parentParts(absolute));
669
+ if (reader)
670
+ await this.#pipe(entry, body, reader, handle);
671
+ else
672
+ for (const part of body)
673
+ await handle.write(part);
674
+ // Use the open file, so that a symbolic link that replaced the
675
+ // path is not followed. If that fails, use the path.
676
+ const times = this.times(entry);
677
+ if (times) {
678
+ const { atime, mtime } = times;
679
+ await handle.utimes(atime, mtime).catch(async (er) => {
680
+ await fs.utimes(absolute, atime, mtime).catch(() => {
681
+ throw er;
682
+ });
683
+ });
684
+ }
685
+ const owner = this.owner(entry);
686
+ if (owner) {
687
+ const { uid, gid } = owner;
688
+ await handle.chown(uid, gid).catch(async (er) => {
689
+ await fs.chown(absolute, uid, gid).catch(() => {
690
+ throw er;
691
+ });
692
+ });
693
+ }
694
+ }
695
+ catch (er) {
696
+ await handle.close().catch(() => { });
697
+ throw er;
698
+ }
699
+ await handle.close();
700
+ }
701
+ // Write the content of the entry as it arrives, through the
702
+ // transform stream if there is one.
703
+ async #pipe(entry, body, reader, handle) {
704
+ let i = 0;
705
+ const next = async () => {
706
+ if (i < body.length)
707
+ return body[i++];
708
+ try {
709
+ for (;;) {
710
+ const part = reader.readBody(entry);
711
+ if (part !== undefined)
712
+ return part;
713
+ await reader.fill();
619
714
  }
620
- this[CHECKED_CWD] = true;
621
- start();
622
- });
715
+ }
716
+ catch (er) {
717
+ // The archive cannot be read.
718
+ throw this.fail(er);
719
+ }
623
720
  };
624
- const start = () => {
625
- if (entry.absolute !== this.cwd) {
626
- const parent = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.dirname(String(entry.absolute)));
627
- if (parent !== this.cwd) {
628
- return this[MKDIR](parent, this.dmode, er => {
629
- if (er) {
630
- this[ONERROR](er, entry);
631
- done();
632
- return;
633
- }
634
- afterMakeParent();
721
+ const tx = this.opt.transform?.(entry);
722
+ if (!tx) {
723
+ // Write one part while the next part is read.
724
+ let writing;
725
+ let failed;
726
+ try {
727
+ for (let part; (part = await next());) {
728
+ await writing;
729
+ if (failed)
730
+ break;
731
+ writing = handle.write(part).then(() => { }, error => {
732
+ failed = { error };
635
733
  });
636
734
  }
637
735
  }
638
- afterMakeParent();
736
+ finally {
737
+ await writing;
738
+ }
739
+ if (failed)
740
+ throw failed.error;
741
+ return;
742
+ }
743
+ const writer = tx.writable.getWriter();
744
+ const out = tx.readable.getReader();
745
+ let failed;
746
+ // Stop the two streams. A read that waits gets the end of the
747
+ // stream, and a write that waits fails.
748
+ const stop = async (error) => {
749
+ failed ??= { error };
750
+ await out.cancel(error).catch(() => { });
751
+ await writer.abort(error).catch(() => { });
639
752
  };
640
- const afterMakeParent = () => {
641
- node_fs_1.default.lstat(String(entry.absolute), (lstatEr, st) => {
642
- if (st &&
643
- (this.keep ||
644
- /* c8 ignore next */
645
- (this.newer && st.mtime > (entry.mtime ?? st.mtime)))) {
646
- this[SKIP](entry);
647
- done();
648
- return;
649
- }
650
- if (lstatEr || this[ISREUSABLE](entry, st)) {
651
- return this[MAKEFS](null, entry, done);
652
- }
653
- if (st.isDirectory()) {
654
- if (entry.type === 'Directory') {
655
- const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
656
- const afterChmod = (er) => this[MAKEFS](er ?? null, entry, done);
657
- if (!needChmod) {
658
- return afterChmod();
659
- }
660
- return node_fs_1.default.chmod(String(entry.absolute), Number(entry.mode), afterChmod);
661
- }
662
- // Not a dir entry, have to remove it.
663
- // NB: the only way to end up with an entry that is the cwd
664
- // itself, in such a way that == does not detect, is a
665
- // tricky windows absolute path with UNC or 8.3 parts (and
666
- // preservePaths:true, or else it will have been stripped).
667
- // In that case, the user has opted out of path protections
668
- // explicitly, so if they blow away the cwd, c'est la vie.
669
- if (entry.absolute !== this.cwd) {
670
- return node_fs_1.default.rmdir(String(entry.absolute), (er) => this[MAKEFS](er ?? null, entry, done));
671
- }
753
+ const feed = (async () => {
754
+ try {
755
+ for (let part; (part = await next());)
756
+ await writer.write(part);
757
+ await writer.close();
758
+ }
759
+ catch (er) {
760
+ await stop(er);
761
+ }
762
+ })();
763
+ try {
764
+ for (;;) {
765
+ const { done, value } = await out.read();
766
+ if (done)
767
+ break;
768
+ await handle.write(value);
769
+ }
770
+ }
771
+ catch (er) {
772
+ await stop(er);
773
+ }
774
+ // The feed reads the archive, so it must end before the next
775
+ // entry is read.
776
+ await feed;
777
+ if (failed)
778
+ throw failed.error;
779
+ }
780
+ }
781
+ exports.Unpack = Unpack;
782
+ /**
783
+ * Extracts the entries of an archive with sync file system
784
+ * functions, one entry at a time.
785
+ */
786
+ class UnpackSync extends UnpackBase {
787
+ #fs;
788
+ #checkedCwd = false;
789
+ constructor(opt) {
790
+ super(opt);
791
+ this.#fs = this.opt.fs;
792
+ }
793
+ /** Extract the archive. Throws the first error that stops it. */
794
+ extract(input) {
795
+ const reader = new entries_js_1.TarReaderSync(input, this.readerOptions());
796
+ const { onEntry } = this.opt;
797
+ try {
798
+ for (const entry of reader) {
799
+ onEntry?.(entry);
800
+ if (entry.bodyUsed)
801
+ continue;
802
+ if (!this.check(entry))
803
+ continue;
804
+ try {
805
+ this.#extract(entry, reader);
672
806
  }
673
- // not a dir, and not reusable
674
- // don't remove if the cwd, we want that error
675
- if (entry.absolute === this.cwd) {
676
- return this[MAKEFS](null, entry, done);
807
+ catch (er) {
808
+ this.entryError(er, entry);
677
809
  }
678
- unlinkFile(String(entry.absolute), er => this[MAKEFS](er ?? null, entry, done));
679
- });
680
- };
681
- if (this[CHECKED_CWD]) {
682
- start();
810
+ }
683
811
  }
684
- else {
685
- checkCwd();
812
+ catch (error) {
813
+ if (error && typeof error === 'object' && 'tarCode' in error) {
814
+ Object.assign(error, { cwd: this.cwd });
815
+ }
816
+ throw error;
686
817
  }
687
818
  }
688
- [MAKEFS](er, entry, done) {
689
- if (er) {
690
- this[ONERROR](er, entry);
691
- done();
819
+ #mkdir(dir, mode) {
820
+ (0, mkdir_js_1.mkdirSync)(this.#fs, dir, this.mkdirOptions(mode));
821
+ }
822
+ #extract(entry, reader) {
823
+ const fs = this.#fs;
824
+ const absolute = entry.absolute;
825
+ const { cwd } = this;
826
+ if (!this.#checkedCwd) {
827
+ this.#mkdir(cwd, this.dmode);
828
+ this.#checkedCwd = true;
829
+ }
830
+ if (absolute !== cwd) {
831
+ const parent = this.dirname(absolute);
832
+ if (parent !== cwd)
833
+ this.#mkdir(parent, this.dmode);
834
+ }
835
+ // Remove what is at the path, if the entry cannot use it.
836
+ let st;
837
+ try {
838
+ st = fs.lstatSync(absolute);
839
+ }
840
+ catch { }
841
+ if (st && this.skip(entry, st))
692
842
  return;
843
+ if (st && !this.isReusable(entry, st)) {
844
+ if (st.isDirectory() && dirTypes.has(entry.type)) {
845
+ if (this.chmod &&
846
+ entry.mode &&
847
+ (st.mode & 0o7777) !== entry.mode) {
848
+ fs.chmodSync(absolute, entry.mode);
849
+ }
850
+ }
851
+ else if (absolute !== cwd) {
852
+ if (st.isDirectory())
853
+ fs.rmdirSync(absolute);
854
+ else
855
+ this.#unlink(absolute);
856
+ }
857
+ }
858
+ if (fileTypes.has(entry.type)) {
859
+ return this.#file(entry, absolute, reader);
693
860
  }
694
- switch (entry.type) {
695
- case 'File':
696
- case 'OldFile':
697
- case 'ContiguousFile':
698
- return this[FILE](entry, done);
699
- case 'Link':
700
- return this[HARDLINK](entry, done);
701
- case 'SymbolicLink':
702
- return this[SYMLINK](entry, done);
703
- case 'Directory':
704
- case 'GNUDumpDir':
705
- return this[DIRECTORY](entry, done);
706
- }
707
- }
708
- [LINK](entry, linkpath, link, done) {
709
- node_fs_1.default[link](linkpath, String(entry.absolute), er => {
710
- if (er) {
711
- this[ONERROR](er, entry);
861
+ if (dirTypes.has(entry.type))
862
+ this.#directory(entry, absolute);
863
+ else {
864
+ this.#ensureNoSymlink(this.linkParts(entry, absolute));
865
+ const linkpath = String(entry.linkpath);
866
+ if (entry.type === 'Link') {
867
+ fs.linkSync(this.resolve(cwd, linkpath), absolute);
712
868
  }
713
869
  else {
714
- this[UNPEND]();
715
- entry.resume();
716
- }
717
- done();
718
- });
719
- }
720
- }
721
- exports.Unpack = Unpack;
722
- const callSync = (fn) => {
723
- try {
724
- return [null, fn()];
725
- }
726
- catch (er) {
727
- return [er, null];
728
- }
729
- };
730
- class UnpackSync extends Unpack {
731
- sync = true;
732
- [MAKEFS](er, entry) {
733
- return super[MAKEFS](er, entry, () => { });
734
- }
735
- [CHECKFS](entry) {
736
- if (!this[CHECKED_CWD]) {
737
- const er = this[MKDIR](this.cwd, this.dmode);
738
- if (er) {
739
- return this[ONERROR](er, entry);
740
- }
741
- this[CHECKED_CWD] = true;
742
- }
743
- // don't bother to make the parent if the current entry is the cwd,
744
- // we've already checked it.
745
- if (entry.absolute !== this.cwd) {
746
- const parent = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.dirname(String(entry.absolute)));
747
- if (parent !== this.cwd) {
748
- const mkParent = this[MKDIR](parent, this.dmode);
749
- if (mkParent) {
750
- return this[ONERROR](mkParent, entry);
751
- }
870
+ fs.symlinkSync(linkpath, absolute);
752
871
  }
753
872
  }
754
- const [lstatEr, st] = callSync(() => node_fs_1.default.lstatSync(String(entry.absolute)));
755
- if (st &&
756
- (this.keep ||
757
- /* c8 ignore next */
758
- (this.newer && st.mtime > (entry.mtime ?? st.mtime)))) {
759
- return this[SKIP](entry);
760
- }
761
- if (lstatEr || this[ISREUSABLE](entry, st)) {
762
- return this[MAKEFS](null, entry);
763
- }
764
- if (st.isDirectory()) {
765
- if (entry.type === 'Directory') {
766
- const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
767
- const [er] = needChmod ?
768
- callSync(() => {
769
- node_fs_1.default.chmodSync(String(entry.absolute), Number(entry.mode));
770
- })
771
- : [];
772
- return this[MAKEFS](er, entry);
773
- }
774
- // not a dir entry, have to remove it
775
- const [er] = callSync(() => node_fs_1.default.rmdirSync(String(entry.absolute)));
776
- this[MAKEFS](er, entry);
777
- }
778
- // not a dir, and not reusable.
779
- // don't remove if it's the cwd, since we want that error.
780
- const [er] = entry.absolute === this.cwd ?
781
- []
782
- : callSync(() => unlinkFileSync(String(entry.absolute)));
783
- this[MAKEFS](er, entry);
784
- }
785
- [FILE](entry, done) {
786
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
787
- const oner = (er) => {
788
- let closeError;
873
+ this.#ensureNoSymlink(this.parentParts(absolute));
874
+ }
875
+ #unlink(path) {
876
+ const fs = this.#fs;
877
+ if (!this.win32)
878
+ return fs.unlinkSync(path);
879
+ const name = deleteName(path);
880
+ fs.renameSync(path, name);
881
+ fs.unlinkSync(name);
882
+ }
883
+ #ensureNoSymlink(parts) {
884
+ if (this.preservePaths)
885
+ return;
886
+ let t = this.cwd;
887
+ for (const p of parts) {
888
+ t = this.resolve(t, p);
889
+ let st;
789
890
  try {
790
- node_fs_1.default.closeSync(fd);
891
+ st = this.#fs.lstatSync(t);
791
892
  }
792
- catch (e) {
793
- closeError = e;
794
- }
795
- if (er || closeError) {
796
- this[ONERROR](er || closeError, entry);
893
+ catch {
894
+ return;
797
895
  }
798
- done();
799
- };
800
- let fd;
801
- try {
802
- fd = node_fs_1.default.openSync(String(entry.absolute), (0, get_write_flag_js_1.getWriteFlag)(entry.size), mode);
803
- /* c8 ignore start - This is only a problem if the file was successfully
804
- * statted, BUT failed to open. Testing this is annoying, and we
805
- * already have ample testint for other uses of oner() methods.
806
- */
896
+ if (st.isSymbolicLink())
897
+ throw this.symlinkError(t, parts);
807
898
  }
808
- catch (er) {
809
- return oner(er);
810
- }
811
- /* c8 ignore stop */
812
- const tx = this.transform ? this.transform(entry) || entry : entry;
813
- if (tx !== entry) {
814
- tx.on('error', er => this[ONERROR](er, entry));
815
- entry.pipe(tx);
899
+ }
900
+ #directory(entry, absolute) {
901
+ const fs = this.#fs;
902
+ this.#mkdir(absolute, entry.mode ?? this.dmode);
903
+ // These do not follow a symbolic link that replaced the
904
+ // directory. A failure is not an error of the entry.
905
+ const times = this.times(entry);
906
+ if (times) {
907
+ try {
908
+ fs.lutimesSync(absolute, times.atime, times.mtime);
909
+ }
910
+ catch { }
816
911
  }
817
- tx.on('data', (chunk) => {
912
+ const owner = this.owner(entry);
913
+ if (owner) {
818
914
  try {
819
- node_fs_1.default.writeSync(fd, chunk, 0, chunk.length);
915
+ fs.lchownSync(absolute, owner.uid, owner.gid);
820
916
  }
821
- catch (er) {
822
- oner(er);
917
+ catch { }
918
+ }
919
+ }
920
+ #file(entry, absolute, reader) {
921
+ const fs = this.#fs;
922
+ const fd = fs.openSync(absolute, this.writeFlag(entry.size), entry.mode ?? this.fmode);
923
+ try {
924
+ // The file is open. Write to it only if no parent directory
925
+ // became a symbolic link before the open.
926
+ this.#ensureNoSymlink(this.parentParts(absolute));
927
+ const tx = this.opt.transform?.(entry);
928
+ for (;;) {
929
+ let part;
930
+ try {
931
+ part = reader.readBody(entry);
932
+ }
933
+ catch (er) {
934
+ // The archive cannot be read.
935
+ throw this.fail(er);
936
+ }
937
+ if (!part)
938
+ break;
939
+ fs.writeSync(fd, tx ? tx(part) : part);
823
940
  }
824
- });
825
- tx.on('end', () => {
826
- let er = null;
827
- // try both, falling futimes back to utimes
828
- // if either fails, handle the first error
829
- if (entry.mtime && !this.noMtime) {
830
- const atime = entry.atime || new Date();
831
- const mtime = entry.mtime;
941
+ // Use the open file, so that a symbolic link that replaced the
942
+ // path is not followed. If that fails, use the path.
943
+ const times = this.times(entry);
944
+ if (times) {
945
+ const { atime, mtime } = times;
832
946
  try {
833
- node_fs_1.default.futimesSync(fd, atime, mtime);
947
+ fs.futimesSync(fd, atime, mtime);
834
948
  }
835
- catch (futimeser) {
949
+ catch (er) {
836
950
  try {
837
- node_fs_1.default.utimesSync(String(entry.absolute), atime, mtime);
951
+ fs.utimesSync(absolute, atime, mtime);
838
952
  }
839
953
  catch {
840
- er = futimeser;
954
+ throw er;
841
955
  }
842
956
  }
843
957
  }
844
- if (this[DOCHOWN](entry)) {
845
- const uid = this[UID](entry);
846
- const gid = this[GID](entry);
958
+ const owner = this.owner(entry);
959
+ if (owner) {
960
+ const { uid, gid } = owner;
847
961
  try {
848
- node_fs_1.default.fchownSync(fd, Number(uid), Number(gid));
962
+ fs.fchownSync(fd, uid, gid);
849
963
  }
850
- catch (fchowner) {
964
+ catch (er) {
851
965
  try {
852
- node_fs_1.default.chownSync(String(entry.absolute), Number(uid), Number(gid));
966
+ fs.chownSync(absolute, uid, gid);
853
967
  }
854
968
  catch {
855
- er = er || fchowner;
969
+ throw er;
856
970
  }
857
971
  }
858
972
  }
859
- oner(er);
860
- });
861
- }
862
- [DIRECTORY](entry, done) {
863
- const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
864
- const er = this[MKDIR](String(entry.absolute), mode);
865
- if (er) {
866
- this[ONERROR](er, entry);
867
- done();
868
- return;
869
- }
870
- if (entry.mtime && !this.noMtime) {
871
- try {
872
- node_fs_1.default.utimesSync(String(entry.absolute), entry.atime || new Date(), entry.mtime);
873
- /* c8 ignore next */
874
- }
875
- catch { }
876
973
  }
877
- if (this[DOCHOWN](entry)) {
974
+ catch (er) {
975
+ // Close the file one time, and do not use the descriptor again:
976
+ // the system can give its number to a different file.
878
977
  try {
879
- node_fs_1.default.chownSync(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)));
978
+ fs.closeSync(fd);
880
979
  }
881
980
  catch { }
981
+ throw er;
882
982
  }
883
- done();
884
- entry.resume();
885
- }
886
- [MKDIR](dir, mode) {
887
- try {
888
- return (0, mkdir_js_1.mkdirSync)((0, normalize_windows_path_js_1.normalizeWindowsPath)(dir), {
889
- uid: this.uid,
890
- gid: this.gid,
891
- processUid: this.processUid,
892
- processGid: this.processGid,
893
- umask: this.processUmask,
894
- preserve: this.preservePaths,
895
- unlink: this.unlink,
896
- cwd: this.cwd,
897
- mode: mode,
898
- });
899
- }
900
- catch (er) {
901
- return er;
902
- }
903
- }
904
- [ENSURE_NO_SYMLINK](_entry, cwd, parts, done, onError) {
905
- if (this.preservePaths || parts.length === 0)
906
- return done();
907
- let t = cwd;
908
- for (const p of parts) {
909
- t = node_path_1.default.resolve(t, p);
910
- const [er, st] = callSync(() => node_fs_1.default.lstatSync(t));
911
- if (er)
912
- return done();
913
- if (st.isSymbolicLink()) {
914
- return onError(new symlink_error_js_1.SymlinkError(t, node_path_1.default.resolve(cwd, parts.join('/'))));
915
- }
916
- }
917
- done();
918
- }
919
- [LINK](entry, linkpath, link, done) {
920
- const linkSync = `${link}Sync`;
921
- try {
922
- node_fs_1.default[linkSync](linkpath, String(entry.absolute));
923
- done();
924
- entry.resume();
925
- }
926
- catch (er) {
927
- return this[ONERROR](er, entry);
928
- }
983
+ fs.closeSync(fd);
929
984
  }
930
985
  }
931
986
  exports.UnpackSync = UnpackSync;