@camstack/system 1.2.381 → 1.2.383

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 (133) hide show
  1. package/dist/addon-runner.js +4 -2
  2. package/dist/addon-runner.mjs +4 -2
  3. package/dist/addon-utils.js +1 -1
  4. package/dist/addon-utils.mjs +1 -1
  5. package/dist/auth/admin-token-manager.d.ts +75 -0
  6. package/dist/auth/api-key-manager.d.ts +1 -14
  7. package/dist/auth/auth-audit-log.d.ts +59 -0
  8. package/dist/auth/auth-manager.d.ts +28 -16
  9. package/dist/auth/cidr.d.ts +22 -0
  10. package/dist/auth/login-session-manager.d.ts +158 -0
  11. package/dist/auth/user-management-internal.d.ts +69 -0
  12. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  13. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  14. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  15. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  16. package/dist/builtins/alerts/alerts.addon.js +1 -1
  17. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  18. package/dist/builtins/autotrack/index.js +1 -1
  19. package/dist/builtins/autotrack/index.mjs +1 -1
  20. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.d.ts +14 -0
  21. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +291 -3631
  22. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +284 -3617
  23. package/dist/builtins/backup-orchestrator/encryption-key-store.d.ts +36 -0
  24. package/dist/builtins/backup-orchestrator/manifest-store.d.ts +19 -1
  25. package/dist/builtins/backup-orchestrator/restore-archive.d.ts +24 -0
  26. package/dist/builtins/calendars/calendars.addon.js +1 -1
  27. package/dist/builtins/calendars/calendars.addon.mjs +1 -1
  28. package/dist/builtins/camera-grid/index.js +1 -1
  29. package/dist/builtins/camera-grid/index.mjs +1 -1
  30. package/dist/builtins/composer/composer.addon.js +2 -2
  31. package/dist/builtins/composer/composer.addon.mjs +2 -2
  32. package/dist/builtins/console-logging/index.js +1 -1
  33. package/dist/builtins/console-logging/index.mjs +1 -1
  34. package/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
  35. package/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
  36. package/dist/builtins/device-manager/device-manager.addon.js +2 -2
  37. package/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
  38. package/dist/builtins/hub-forwarder/index.js +1 -1
  39. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  40. package/dist/builtins/keychain/index.js +1110 -735
  41. package/dist/builtins/keychain/index.mjs +1109 -734
  42. package/dist/builtins/keychain/keychain-reset-trigger.d.ts +25 -0
  43. package/dist/builtins/keychain/keychain-service.d.ts +36 -3
  44. package/dist/builtins/keychain/keychain-store.d.ts +24 -1
  45. package/dist/builtins/keychain/system-held-secrets.d.ts +2 -1
  46. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  47. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  48. package/dist/builtins/local-auth/local-auth.addon.d.ts +16 -0
  49. package/dist/builtins/local-auth/local-auth.addon.js +1028 -294
  50. package/dist/builtins/local-auth/local-auth.addon.mjs +1035 -299
  51. package/dist/builtins/local-network/local-network.addon.js +3 -3
  52. package/dist/builtins/local-network/local-network.addon.mjs +3 -3
  53. package/dist/builtins/loki-logging/index.js +97 -29
  54. package/dist/builtins/loki-logging/index.mjs +97 -29
  55. package/dist/builtins/loki-logging/loki-logging.addon.d.ts +7 -23
  56. package/dist/builtins/loki-logging/retire-enabled-flag.d.ts +23 -0
  57. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  58. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  59. package/dist/builtins/platform-probe/index.js +1 -1
  60. package/dist/builtins/platform-probe/index.mjs +1 -1
  61. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  62. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  63. package/dist/builtins/snapshot/index.js +1 -1
  64. package/dist/builtins/snapshot/index.mjs +1 -1
  65. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  66. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  67. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  68. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  69. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +2 -2
  70. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +2 -2
  71. package/dist/builtins/system-backup/backup-encryption.d.ts +57 -0
  72. package/dist/builtins/system-backup/system-backup.service.d.ts +16 -1
  73. package/dist/builtins/system-config/cluster-secret-keeper.d.ts +7 -0
  74. package/dist/builtins/system-config/index.d.ts +1 -0
  75. package/dist/builtins/system-config/index.js +2 -0
  76. package/dist/builtins/system-config/index.mjs +2 -2
  77. package/dist/builtins/system-config/mesh-actions.d.ts +19 -0
  78. package/dist/builtins/system-config/system-config.addon.d.ts +47 -4
  79. package/dist/builtins/system-config/system-config.addon.js +87858 -43
  80. package/dist/builtins/system-config/system-config.addon.mjs +87813 -39
  81. package/dist/builtins/winston-logging/index.js +1 -1
  82. package/dist/builtins/winston-logging/index.mjs +1 -1
  83. package/dist/{child-cap-dispatch-hf-Gce_4.js → child-cap-dispatch-BD8fhJ1b.js} +7 -4
  84. package/dist/{child-cap-dispatch-BTe4eKep.mjs → child-cap-dispatch-C68N2a6Y.mjs} +11 -8
  85. package/dist/{composition-sources-4SmsP0O4.js → composition-sources-ChpT_Yw4.js} +1 -1
  86. package/dist/{composition-sources-CgOQVIwa.mjs → composition-sources-DM7Ft_tp.mjs} +1 -1
  87. package/dist/{cluster-secret-BUiG8DCo.js → constants-CDpry1_T.js} +82 -1
  88. package/dist/{cluster-secret-DgJTZ4qY.mjs → constants-e3mCa1jG.mjs} +23 -2
  89. package/dist/{dist-BugrtARh.js → dist-CUNGH0fs.js} +1755 -157
  90. package/dist/{dist-BC0GnGeg.mjs → dist-osl3bkF0.mjs} +1732 -158
  91. package/dist/{event-loop-stall-monitor-GgpnfAC0.mjs → event-loop-stall-monitor-BeeWMnyT.mjs} +15 -15
  92. package/dist/{event-loop-stall-monitor-CnQ-K6Gn.js → event-loop-stall-monitor-Dk28EF8B.js} +15 -15
  93. package/dist/{hub-cap-forward-CH6_VWVO.mjs → hub-cap-forward-CDiN1p98.mjs} +18 -2
  94. package/dist/{hub-cap-forward-COCmYaup.js → hub-cap-forward-W8oEm4ME.js} +23 -1
  95. package/dist/index.d.ts +16 -1
  96. package/dist/index.js +1023 -83525
  97. package/dist/index.mjs +1218 -83794
  98. package/dist/{jwt-signing-key-CsuVKA1W.mjs → jwt-signing-key-MQLxLfgF.mjs} +1 -1
  99. package/dist/{jwt-signing-key-CjoZcol8.js → jwt-signing-key-WI6z7JBo.js} +1 -1
  100. package/dist/kernel/index.d.ts +17 -1
  101. package/dist/kernel/moleculer/agent-mesh-authenticator.d.ts +41 -0
  102. package/dist/kernel/moleculer/broker-factory.d.ts +25 -2
  103. package/dist/kernel/moleculer/child-addon-call-dispatch.d.ts +1 -0
  104. package/dist/kernel/moleculer/hub-service.d.ts +9 -0
  105. package/dist/kernel/moleculer/mesh-access-middleware.d.ts +33 -0
  106. package/dist/kernel/moleculer/mesh-auth-mode.d.ts +64 -0
  107. package/dist/kernel/moleculer/mesh-authenticator.d.ts +71 -0
  108. package/dist/kernel/moleculer/mesh-auto-enforce.d.ts +26 -0
  109. package/dist/kernel/moleculer/mesh-join-client.d.ts +51 -0
  110. package/dist/kernel/moleculer/mesh-join-proof.d.ts +39 -0
  111. package/dist/kernel/moleculer/mesh-mtls/constants.d.ts +20 -0
  112. package/dist/kernel/moleculer/mesh-mtls/index.d.ts +9 -0
  113. package/dist/kernel/moleculer/mesh-mtls/mesh-ca-keeper.d.ts +55 -0
  114. package/dist/kernel/moleculer/mesh-mtls/mesh-ca.d.ts +45 -0
  115. package/dist/kernel/moleculer/mesh-mtls/mesh-crl.d.ts +16 -0
  116. package/dist/kernel/moleculer/mesh-mtls/mesh-enroll.d.ts +27 -0
  117. package/dist/kernel/moleculer/mesh-mtls/mesh-join-token.d.ts +55 -0
  118. package/dist/kernel/moleculer/mesh-mtls/mesh-tls-enabler.d.ts +5 -0
  119. package/dist/kernel/moleculer/mesh-mtls/tls-tcp-transporter.d.ts +92 -0
  120. package/dist/kernel/system-settings-policy.d.ts +4 -3
  121. package/dist/kernel/transport/hub-cap-forward.d.ts +14 -3
  122. package/dist/kernel/transport/index.d.ts +1 -1
  123. package/dist/ms-DlIWNkkk.mjs +160 -0
  124. package/dist/ms-t68_FaqE.js +171 -0
  125. package/dist/restore-archive-C5f9yX90.js +4139 -0
  126. package/dist/restore-archive-CZRtI1k9.mjs +4045 -0
  127. package/dist/{retired-settings-keys-MCVhxPkJ.mjs → retired-settings-keys-LuDd4y3M.mjs} +1 -1
  128. package/dist/{retired-settings-keys-DCuetwOt.js → retired-settings-keys-WLrbzdPR.js} +1 -1
  129. package/dist/tls-BWpwU-d5.js +1160 -0
  130. package/dist/tls-C2NT-Orr.mjs +949 -0
  131. package/dist/{tls-CCMX7MjX.js → x509.es-BhTzcFhZ.js} +65 -1108
  132. package/dist/{tls-CJHogwTl.mjs → x509.es-Xf3K_brW.mjs} +40 -950
  133. package/package.json +3 -2
@@ -1,3614 +1,9 @@
1
- import { In as storageOccupancyCapability, Ir as nodePin, Qr as EventCategory, Y as backupCapability, Yr as toNodeId, g as DATABASE_SNAPSHOT_SUFFIX, lr as BaseAddon, nn as mayWriteToLocation } from "../../dist-BC0GnGeg.mjs";
2
- import { randomBytes, randomUUID } from "node:crypto";
3
- import { Buffer as Buffer$1 } from "buffer";
1
+ import { $r as toNodeId, Br as nodePin, Ln as storageOccupancyCapability, X as backupCapability, ni as EventCategory, rn as mayWriteToLocation, ur as BaseAddon } from "../../dist-osl3bkF0.mjs";
2
+ import { a as BackupSnapshotRefusedError, c as BackupKeyFormatError, d as generateBackupKeyPair, f as parseBackupPublicKey, i as BackupCancelledError, n as precheckRestoreKey, o as SystemBackupService, p as parseBackupSecretKey, r as prepareRestoreArchive, u as ENCRYPTED_BACKUP_SUFFIX } from "../../restore-archive-CZRtI1k9.mjs";
3
+ import { randomUUID } from "node:crypto";
4
4
  import * as fsp from "node:fs/promises";
5
- import jn from "node:fs/promises";
6
5
  import * as path$1 from "node:path";
7
- import path, { basename, join, posix, win32 } from "node:path";
8
6
  import * as fs from "node:fs";
9
- import Kt from "node:fs";
10
- import * as zlib from "node:zlib";
11
- import { EventEmitter } from "node:events";
12
- import As, { Transform } from "node:stream";
13
- import { StringDecoder } from "node:string_decoder";
14
- import I from "fs";
15
- import qs, { dirname as dirname$1, parse } from "path";
16
- import * as Ms from "zlib";
17
- import Jr from "zlib";
18
- import Pi from "assert";
19
- import $r, { EventEmitter as EventEmitter$1 } from "events";
20
- import { pipeline } from "node:stream/promises";
21
- import no from "node:assert";
22
- //#region node_modules/tar/dist/esm/index.min.js
23
- var Mr = Object.defineProperty;
24
- var Br = (s, t) => {
25
- for (var e in t) Mr(s, e, {
26
- get: t[e],
27
- enumerable: !0
28
- });
29
- };
30
- var xs = typeof process == "object" && process ? process : {
31
- stdout: null,
32
- stderr: null
33
- }, zr = (s) => !!s && typeof s == "object" && (s instanceof A$1 || s instanceof As || Ur(s) || Hr(s)), Ur = (s) => !!s && typeof s == "object" && s instanceof EventEmitter && typeof s.pipe == "function" && s.pipe !== As.Writable.prototype.pipe, Hr = (s) => !!s && typeof s == "object" && s instanceof EventEmitter && typeof s.write == "function" && typeof s.end == "function", q = Symbol("EOF"), Q = Symbol("maybeEmitEnd"), rt = Symbol("emittedEnd"), Le = Symbol("emittingEnd"), qt = Symbol("emittedError"), Ne = Symbol("closed"), Ls = Symbol("read"), De = Symbol("flush"), Ns = Symbol("flushChunk"), z = Symbol("encoding"), Mt = Symbol("decoder"), g$1 = Symbol("flowing"), Qt = Symbol("paused"), Bt = Symbol("resume"), b$1 = Symbol("buffer"), D$1 = Symbol("pipes"), _$1 = Symbol("bufferLength"), gi = Symbol("bufferPush"), Ae = Symbol("bufferShift"), L = Symbol("objectMode"), w$1 = Symbol("destroyed"), bi = Symbol("error"), _i = Symbol("emitData"), Ds = Symbol("emitEnd"), Oi = Symbol("emitEnd2"), Z = Symbol("async"), Ti = Symbol("abort"), Ie = Symbol("aborted"), Jt = Symbol("signal"), Rt = Symbol("dataListeners"), F = Symbol("discarded"), jt = (s) => Promise.resolve().then(s), Wr = (s) => s(), Gr = (s) => s === "end" || s === "finish" || s === "prefinish", Zr = (s) => s instanceof ArrayBuffer || !!s && typeof s == "object" && s.constructor && s.constructor.name === "ArrayBuffer" && s.byteLength >= 0, Yr = (s) => !Buffer.isBuffer(s) && ArrayBuffer.isView(s), Fe = class {
34
- src;
35
- dest;
36
- opts;
37
- ondrain;
38
- constructor(t, e, i) {
39
- this.src = t, this.dest = e, this.opts = i, this.ondrain = () => t[Bt](), this.dest.on("drain", this.ondrain);
40
- }
41
- unpipe() {
42
- this.dest.removeListener("drain", this.ondrain);
43
- }
44
- proxyErrors(t) {}
45
- end() {
46
- this.unpipe(), this.opts.end && this.dest.end();
47
- }
48
- }, xi = class extends Fe {
49
- unpipe() {
50
- this.src.removeListener("error", this.proxyErrors), super.unpipe();
51
- }
52
- constructor(t, e, i) {
53
- super(t, e, i), this.proxyErrors = (r) => this.dest.emit("error", r), t.on("error", this.proxyErrors);
54
- }
55
- }, Kr = (s) => !!s.objectMode, Vr = (s) => !s.objectMode && !!s.encoding && s.encoding !== "buffer", A$1 = class extends EventEmitter {
56
- [g$1] = !1;
57
- [Qt] = !1;
58
- [D$1] = [];
59
- [b$1] = [];
60
- [L];
61
- [z];
62
- [Z];
63
- [Mt];
64
- [q] = !1;
65
- [rt] = !1;
66
- [Le] = !1;
67
- [Ne] = !1;
68
- [qt] = null;
69
- [_$1] = 0;
70
- [w$1] = !1;
71
- [Jt];
72
- [Ie] = !1;
73
- [Rt] = 0;
74
- [F] = !1;
75
- writable = !0;
76
- readable = !0;
77
- constructor(...t) {
78
- let e = t[0] || {};
79
- if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together");
80
- Kr(e) ? (this[L] = !0, this[z] = null) : Vr(e) ? (this[z] = e.encoding, this[L] = !1) : (this[L] = !1, this[z] = null), this[Z] = !!e.async, this[Mt] = this[z] ? new StringDecoder(this[z]) : null, e && e.debugExposeBuffer === !0 && Object.defineProperty(this, "buffer", { get: () => this[b$1] }), e && e.debugExposePipes === !0 && Object.defineProperty(this, "pipes", { get: () => this[D$1] });
81
- let { signal: i } = e;
82
- i && (this[Jt] = i, i.aborted ? this[Ti]() : i.addEventListener("abort", () => this[Ti]()));
83
- }
84
- get bufferLength() {
85
- return this[_$1];
86
- }
87
- get encoding() {
88
- return this[z];
89
- }
90
- set encoding(t) {
91
- throw new Error("Encoding must be set at instantiation time");
92
- }
93
- setEncoding(t) {
94
- throw new Error("Encoding must be set at instantiation time");
95
- }
96
- get objectMode() {
97
- return this[L];
98
- }
99
- set objectMode(t) {
100
- throw new Error("objectMode must be set at instantiation time");
101
- }
102
- get async() {
103
- return this[Z];
104
- }
105
- set async(t) {
106
- this[Z] = this[Z] || !!t;
107
- }
108
- [Ti]() {
109
- this[Ie] = !0, this.emit("abort", this[Jt]?.reason), this.destroy(this[Jt]?.reason);
110
- }
111
- get aborted() {
112
- return this[Ie];
113
- }
114
- set aborted(t) {}
115
- write(t, e, i) {
116
- if (this[Ie]) return !1;
117
- if (this[q]) throw new Error("write after end");
118
- if (this[w$1]) return this.emit("error", Object.assign(/* @__PURE__ */ new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), !0;
119
- typeof e == "function" && (i = e, e = "utf8"), e || (e = "utf8");
120
- let r = this[Z] ? jt : Wr;
121
- if (!this[L] && !Buffer.isBuffer(t)) {
122
- if (Yr(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
123
- else if (Zr(t)) t = Buffer.from(t);
124
- else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream");
125
- }
126
- return this[L] ? (this[g$1] && this[_$1] !== 0 && this[De](!0), this[g$1] ? this.emit("data", t) : this[gi](t), this[_$1] !== 0 && this.emit("readable"), i && r(i), this[g$1]) : t.length ? (typeof t == "string" && !(e === this[z] && !this[Mt]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[z] && (t = this[Mt].write(t)), this[g$1] && this[_$1] !== 0 && this[De](!0), this[g$1] ? this.emit("data", t) : this[gi](t), this[_$1] !== 0 && this.emit("readable"), i && r(i), this[g$1]) : (this[_$1] !== 0 && this.emit("readable"), i && r(i), this[g$1]);
127
- }
128
- read(t) {
129
- if (this[w$1]) return null;
130
- if (this[F] = !1, this[_$1] === 0 || t === 0 || t && t > this[_$1]) return this[Q](), null;
131
- this[L] && (t = null), this[b$1].length > 1 && !this[L] && (this[b$1] = [this[z] ? this[b$1].join("") : Buffer.concat(this[b$1], this[_$1])]);
132
- let e = this[Ls](t || null, this[b$1][0]);
133
- return this[Q](), e;
134
- }
135
- [Ls](t, e) {
136
- if (this[L]) this[Ae]();
137
- else {
138
- let i = e;
139
- t === i.length || t === null ? this[Ae]() : typeof i == "string" ? (this[b$1][0] = i.slice(t), e = i.slice(0, t), this[_$1] -= t) : (this[b$1][0] = i.subarray(t), e = i.subarray(0, t), this[_$1] -= t);
140
- }
141
- return this.emit("data", e), !this[b$1].length && !this[q] && this.emit("drain"), e;
142
- }
143
- end(t, e, i) {
144
- return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = "utf8"), t !== void 0 && this.write(t, e), i && this.once("end", i), this[q] = !0, this.writable = !1, (this[g$1] || !this[Qt]) && this[Q](), this;
145
- }
146
- [Bt]() {
147
- this[w$1] || (!this[Rt] && !this[D$1].length && (this[F] = !0), this[Qt] = !1, this[g$1] = !0, this.emit("resume"), this[b$1].length ? this[De]() : this[q] ? this[Q]() : this.emit("drain"));
148
- }
149
- resume() {
150
- return this[Bt]();
151
- }
152
- pause() {
153
- this[g$1] = !1, this[Qt] = !0, this[F] = !1;
154
- }
155
- get destroyed() {
156
- return this[w$1];
157
- }
158
- get flowing() {
159
- return this[g$1];
160
- }
161
- get paused() {
162
- return this[Qt];
163
- }
164
- [gi](t) {
165
- this[L] ? this[_$1] += 1 : this[_$1] += t.length, this[b$1].push(t);
166
- }
167
- [Ae]() {
168
- return this[L] ? this[_$1] -= 1 : this[_$1] -= this[b$1][0].length, this[b$1].shift();
169
- }
170
- [De](t = !1) {
171
- do ;
172
- while (this[Ns](this[Ae]()) && this[b$1].length);
173
- !t && !this[b$1].length && !this[q] && this.emit("drain");
174
- }
175
- [Ns](t) {
176
- return this.emit("data", t), this[g$1];
177
- }
178
- pipe(t, e) {
179
- if (this[w$1]) return t;
180
- this[F] = !1;
181
- let i = this[rt];
182
- return e = e || {}, t === xs.stdout || t === xs.stderr ? e.end = !1 : e.end = e.end !== !1, e.proxyErrors = !!e.proxyErrors, i ? e.end && t.end() : (this[D$1].push(e.proxyErrors ? new xi(this, t, e) : new Fe(this, t, e)), this[Z] ? jt(() => this[Bt]()) : this[Bt]()), t;
183
- }
184
- unpipe(t) {
185
- let e = this[D$1].find((i) => i.dest === t);
186
- e && (this[D$1].length === 1 ? (this[g$1] && this[Rt] === 0 && (this[g$1] = !1), this[D$1] = []) : this[D$1].splice(this[D$1].indexOf(e), 1), e.unpipe());
187
- }
188
- addListener(t, e) {
189
- return this.on(t, e);
190
- }
191
- on(t, e) {
192
- let i = super.on(t, e);
193
- if (t === "data") this[F] = !1, this[Rt]++, !this[D$1].length && !this[g$1] && this[Bt]();
194
- else if (t === "readable" && this[_$1] !== 0) super.emit("readable");
195
- else if (Gr(t) && this[rt]) super.emit(t), this.removeAllListeners(t);
196
- else if (t === "error" && this[qt]) {
197
- let r = e;
198
- this[Z] ? jt(() => r.call(this, this[qt])) : r.call(this, this[qt]);
199
- }
200
- return i;
201
- }
202
- removeListener(t, e) {
203
- return this.off(t, e);
204
- }
205
- off(t, e) {
206
- let i = super.off(t, e);
207
- return t === "data" && (this[Rt] = this.listeners("data").length, this[Rt] === 0 && !this[F] && !this[D$1].length && (this[g$1] = !1)), i;
208
- }
209
- removeAllListeners(t) {
210
- let e = super.removeAllListeners(t);
211
- return (t === "data" || t === void 0) && (this[Rt] = 0, !this[F] && !this[D$1].length && (this[g$1] = !1)), e;
212
- }
213
- get emittedEnd() {
214
- return this[rt];
215
- }
216
- [Q]() {
217
- !this[Le] && !this[rt] && !this[w$1] && this[b$1].length === 0 && this[q] && (this[Le] = !0, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Ne] && this.emit("close"), this[Le] = !1);
218
- }
219
- emit(t, ...e) {
220
- let i = e[0];
221
- if (t !== "error" && t !== "close" && t !== w$1 && this[w$1]) return !1;
222
- if (t === "data") return !this[L] && !i ? !1 : this[Z] ? (jt(() => this[_i](i)), !0) : this[_i](i);
223
- if (t === "end") return this[Ds]();
224
- if (t === "close") {
225
- if (this[Ne] = !0, !this[rt] && !this[w$1]) return !1;
226
- let n = super.emit("close");
227
- return this.removeAllListeners("close"), n;
228
- } else if (t === "error") {
229
- this[qt] = i, super.emit(bi, i);
230
- let n = !this[Jt] || this.listeners("error").length ? super.emit("error", i) : !1;
231
- return this[Q](), n;
232
- } else if (t === "resume") {
233
- let n = super.emit("resume");
234
- return this[Q](), n;
235
- } else if (t === "finish" || t === "prefinish") {
236
- let n = super.emit(t);
237
- return this.removeAllListeners(t), n;
238
- }
239
- let r = super.emit(t, ...e);
240
- return this[Q](), r;
241
- }
242
- [_i](t) {
243
- for (let i of this[D$1]) i.dest.write(t) === !1 && this.pause();
244
- let e = this[F] ? !1 : super.emit("data", t);
245
- return this[Q](), e;
246
- }
247
- [Ds]() {
248
- return this[rt] ? !1 : (this[rt] = !0, this.readable = !1, this[Z] ? (jt(() => this[Oi]()), !0) : this[Oi]());
249
- }
250
- [Oi]() {
251
- if (this[Mt]) {
252
- let e = this[Mt].end();
253
- if (e) {
254
- for (let i of this[D$1]) i.dest.write(e);
255
- this[F] || super.emit("data", e);
256
- }
257
- }
258
- for (let e of this[D$1]) e.end();
259
- let t = super.emit("end");
260
- return this.removeAllListeners("end"), t;
261
- }
262
- async collect() {
263
- let t = Object.assign([], { dataLength: 0 });
264
- this[L] || (t.dataLength = 0);
265
- let e = this.promise();
266
- return this.on("data", (i) => {
267
- t.push(i), this[L] || (t.dataLength += i.length);
268
- }), await e, t;
269
- }
270
- async concat() {
271
- if (this[L]) throw new Error("cannot concat in objectMode");
272
- let t = await this.collect();
273
- return this[z] ? t.join("") : Buffer.concat(t, t.dataLength);
274
- }
275
- async promise() {
276
- return new Promise((t, e) => {
277
- this.on(w$1, () => e(/* @__PURE__ */ new Error("stream destroyed"))), this.on("error", (i) => e(i)), this.on("end", () => t());
278
- });
279
- }
280
- [Symbol.asyncIterator]() {
281
- this[F] = !1;
282
- let t = !1, e = async () => (this.pause(), t = !0, {
283
- value: void 0,
284
- done: !0
285
- });
286
- return {
287
- next: () => {
288
- if (t) return e();
289
- let r = this.read();
290
- if (r !== null) return Promise.resolve({
291
- done: !1,
292
- value: r
293
- });
294
- if (this[q]) return e();
295
- let n, o, a = (d) => {
296
- this.off("data", h), this.off("end", l), this.off(w$1, c), e(), o(d);
297
- }, h = (d) => {
298
- this.off("error", a), this.off("end", l), this.off(w$1, c), this.pause(), n({
299
- value: d,
300
- done: !!this[q]
301
- });
302
- }, l = () => {
303
- this.off("error", a), this.off("data", h), this.off(w$1, c), e(), n({
304
- done: !0,
305
- value: void 0
306
- });
307
- }, c = () => a(/* @__PURE__ */ new Error("stream destroyed"));
308
- return new Promise((d, S) => {
309
- o = S, n = d, this.once(w$1, c), this.once("error", a), this.once("end", l), this.once("data", h);
310
- });
311
- },
312
- throw: e,
313
- return: e,
314
- [Symbol.asyncIterator]() {
315
- return this;
316
- },
317
- [Symbol.asyncDispose]: async () => {}
318
- };
319
- }
320
- [Symbol.iterator]() {
321
- this[F] = !1;
322
- let t = !1, e = () => (this.pause(), this.off(bi, e), this.off(w$1, e), this.off("end", e), t = !0, {
323
- done: !0,
324
- value: void 0
325
- }), i = () => {
326
- if (t) return e();
327
- let r = this.read();
328
- return r === null ? e() : {
329
- done: !1,
330
- value: r
331
- };
332
- };
333
- return this.once("end", e), this.once(bi, e), this.once(w$1, e), {
334
- next: i,
335
- throw: e,
336
- return: e,
337
- [Symbol.iterator]() {
338
- return this;
339
- },
340
- [Symbol.dispose]: () => {}
341
- };
342
- }
343
- destroy(t) {
344
- if (this[w$1]) return t ? this.emit("error", t) : this.emit(w$1), this;
345
- this[w$1] = !0, this[F] = !0, this[b$1].length = 0, this[_$1] = 0;
346
- let e = this;
347
- return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(w$1), this;
348
- }
349
- static get isStream() {
350
- return zr;
351
- }
352
- };
353
- var Xr = I.writev, ot = Symbol("_autoClose"), H = Symbol("_close"), te = Symbol("_ended"), m$1 = Symbol("_fd"), Ni = Symbol("_finished"), j = Symbol("_flags"), Di = Symbol("_flush"), Ci = Symbol("_handleChunk"), ki = Symbol("_makeBuf"), ie = Symbol("_mode"), Ce = Symbol("_needDrain"), Ut = Symbol("_onerror"), Ht = Symbol("_onopen"), Ai = Symbol("_onread"), Pt = Symbol("_onwrite"), ht = Symbol("_open"), U = Symbol("_path"), nt = Symbol("_pos"), Y = Symbol("_queue"), zt = Symbol("_read"), Ii = Symbol("_readSize"), J = Symbol("_reading"), ee = Symbol("_remain"), Fi = Symbol("_size"), ke = Symbol("_write"), gt = Symbol("_writing"), ve = Symbol("_defaultFlag"), bt = Symbol("_errored"), _t = class extends A$1 {
354
- [bt] = !1;
355
- [m$1];
356
- [U];
357
- [Ii];
358
- [J] = !1;
359
- [Fi];
360
- [ee];
361
- [ot];
362
- constructor(t, e) {
363
- if (e = e || {}, super(e), this.readable = !0, this.writable = !1, typeof t != "string") throw new TypeError("path must be a string");
364
- this[bt] = !1, this[m$1] = typeof e.fd == "number" ? e.fd : void 0, this[U] = t, this[Ii] = e.readSize || 16 * 1024 * 1024, this[J] = !1, this[Fi] = typeof e.size == "number" ? e.size : Infinity, this[ee] = this[Fi], this[ot] = typeof e.autoClose == "boolean" ? e.autoClose : !0, typeof this[m$1] == "number" ? this[zt]() : this[ht]();
365
- }
366
- get fd() {
367
- return this[m$1];
368
- }
369
- get path() {
370
- return this[U];
371
- }
372
- write() {
373
- throw new TypeError("this is a readable stream");
374
- }
375
- end() {
376
- throw new TypeError("this is a readable stream");
377
- }
378
- [ht]() {
379
- I.open(this[U], "r", (t, e) => this[Ht](t, e));
380
- }
381
- [Ht](t, e) {
382
- t ? this[Ut](t) : (this[m$1] = e, this.emit("open", e), this[zt]());
383
- }
384
- [ki]() {
385
- return Buffer.allocUnsafe(Math.min(this[Ii], this[ee]));
386
- }
387
- [zt]() {
388
- if (!this[J]) {
389
- this[J] = !0;
390
- let t = this[ki]();
391
- if (t.length === 0) return process.nextTick(() => this[Ai](null, 0, t));
392
- I.read(this[m$1], t, 0, t.length, null, (e, i, r) => this[Ai](e, i, r));
393
- }
394
- }
395
- [Ai](t, e, i) {
396
- this[J] = !1, t ? this[Ut](t) : this[Ci](e, i) && this[zt]();
397
- }
398
- [H]() {
399
- if (this[ot] && typeof this[m$1] == "number") {
400
- let t = this[m$1];
401
- this[m$1] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
402
- }
403
- }
404
- [Ut](t) {
405
- this[J] = !0, this[H](), this.emit("error", t);
406
- }
407
- [Ci](t, e) {
408
- let i = !1;
409
- return this[ee] -= t, t > 0 && (i = super.write(t < e.length ? e.subarray(0, t) : e)), (t === 0 || this[ee] <= 0) && (i = !1, this[H](), super.end()), i;
410
- }
411
- emit(t, ...e) {
412
- switch (t) {
413
- case "prefinish":
414
- case "finish": return !1;
415
- case "drain": return typeof this[m$1] == "number" && this[zt](), !1;
416
- case "error": return this[bt] ? !1 : (this[bt] = !0, super.emit(t, ...e));
417
- default: return super.emit(t, ...e);
418
- }
419
- }
420
- }, Me = class extends _t {
421
- [ht]() {
422
- let t = !0;
423
- try {
424
- this[Ht](null, I.openSync(this[U], "r")), t = !1;
425
- } finally {
426
- t && this[H]();
427
- }
428
- }
429
- [zt]() {
430
- let t = !0;
431
- try {
432
- if (!this[J]) {
433
- this[J] = !0;
434
- do {
435
- let e = this[ki](), i = e.length === 0 ? 0 : I.readSync(this[m$1], e, 0, e.length, null);
436
- if (!this[Ci](i, e)) break;
437
- } while (!0);
438
- this[J] = !1;
439
- }
440
- t = !1;
441
- } finally {
442
- t && this[H]();
443
- }
444
- }
445
- [H]() {
446
- if (this[ot] && typeof this[m$1] == "number") {
447
- let t = this[m$1];
448
- this[m$1] = void 0, I.closeSync(t), this.emit("close");
449
- }
450
- }
451
- }, tt = class extends $r {
452
- readable = !1;
453
- writable = !0;
454
- [bt] = !1;
455
- [gt] = !1;
456
- [te] = !1;
457
- [Y] = [];
458
- [Ce] = !1;
459
- [U];
460
- [ie];
461
- [ot];
462
- [m$1];
463
- [ve];
464
- [j];
465
- [Ni] = !1;
466
- [nt];
467
- constructor(t, e) {
468
- e = e || {}, super(e), this[U] = t, this[m$1] = typeof e.fd == "number" ? e.fd : void 0, this[ie] = e.mode === void 0 ? 438 : e.mode, this[nt] = typeof e.start == "number" ? e.start : void 0, this[ot] = typeof e.autoClose == "boolean" ? e.autoClose : !0;
469
- let i = this[nt] !== void 0 ? "r+" : "w";
470
- this[ve] = e.flags === void 0, this[j] = e.flags === void 0 ? i : e.flags, this[m$1] === void 0 && this[ht]();
471
- }
472
- emit(t, ...e) {
473
- if (t === "error") {
474
- if (this[bt]) return !1;
475
- this[bt] = !0;
476
- }
477
- return super.emit(t, ...e);
478
- }
479
- get fd() {
480
- return this[m$1];
481
- }
482
- get path() {
483
- return this[U];
484
- }
485
- [Ut](t) {
486
- this[H](), this[gt] = !0, this.emit("error", t);
487
- }
488
- [ht]() {
489
- I.open(this[U], this[j], this[ie], (t, e) => this[Ht](t, e));
490
- }
491
- [Ht](t, e) {
492
- this[ve] && this[j] === "r+" && t && t.code === "ENOENT" ? (this[j] = "w", this[ht]()) : t ? this[Ut](t) : (this[m$1] = e, this.emit("open", e), this[gt] || this[Di]());
493
- }
494
- end(t, e) {
495
- return t && this.write(t, e), this[te] = !0, !this[gt] && !this[Y].length && typeof this[m$1] == "number" && this[Pt](null, 0), this;
496
- }
497
- write(t, e) {
498
- return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", /* @__PURE__ */ new Error("write() after end()")), !1) : this[m$1] === void 0 || this[gt] || this[Y].length ? (this[Y].push(t), this[Ce] = !0, !1) : (this[gt] = !0, this[ke](t), !0);
499
- }
500
- [ke](t) {
501
- I.write(this[m$1], t, 0, t.length, this[nt], (e, i) => this[Pt](e, i));
502
- }
503
- [Pt](t, e) {
504
- t ? this[Ut](t) : (this[nt] !== void 0 && typeof e == "number" && (this[nt] += e), this[Y].length ? this[Di]() : (this[gt] = !1, this[te] && !this[Ni] ? (this[Ni] = !0, this[H](), this.emit("finish")) : this[Ce] && (this[Ce] = !1, this.emit("drain"))));
505
- }
506
- [Di]() {
507
- if (this[Y].length === 0) this[te] && this[Pt](null, 0);
508
- else if (this[Y].length === 1) this[ke](this[Y].pop());
509
- else {
510
- let t = this[Y];
511
- this[Y] = [], Xr(this[m$1], t, this[nt], (e, i) => this[Pt](e, i));
512
- }
513
- }
514
- [H]() {
515
- if (this[ot] && typeof this[m$1] == "number") {
516
- let t = this[m$1];
517
- this[m$1] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
518
- }
519
- }
520
- }, Wt = class extends tt {
521
- [ht]() {
522
- let t;
523
- if (this[ve] && this[j] === "r+") try {
524
- t = I.openSync(this[U], this[j], this[ie]);
525
- } catch (e) {
526
- if (e?.code === "ENOENT") return this[j] = "w", this[ht]();
527
- throw e;
528
- }
529
- else t = I.openSync(this[U], this[j], this[ie]);
530
- this[Ht](null, t);
531
- }
532
- [H]() {
533
- if (this[ot] && typeof this[m$1] == "number") {
534
- let t = this[m$1];
535
- this[m$1] = void 0, I.closeSync(t), this.emit("close");
536
- }
537
- }
538
- [ke](t) {
539
- let e = !0;
540
- try {
541
- this[Pt](null, I.writeSync(this[m$1], t, 0, t.length, this[nt])), e = !1;
542
- } finally {
543
- if (e) try {
544
- this[H]();
545
- } catch {}
546
- }
547
- }
548
- };
549
- var qr = new Map([
550
- ["C", "cwd"],
551
- ["f", "file"],
552
- ["z", "gzip"],
553
- ["P", "preservePaths"],
554
- ["U", "unlink"],
555
- ["strip-components", "strip"],
556
- ["stripComponents", "strip"],
557
- ["keep-newer", "newer"],
558
- ["keepNewer", "newer"],
559
- ["keep-newer-files", "newer"],
560
- ["keepNewerFiles", "newer"],
561
- ["k", "keep"],
562
- ["keep-existing", "keep"],
563
- ["keepExisting", "keep"],
564
- ["m", "noMtime"],
565
- ["no-mtime", "noMtime"],
566
- ["p", "preserveOwner"],
567
- ["L", "follow"],
568
- ["h", "follow"],
569
- ["onentry", "onReadEntry"]
570
- ]), Is = (s) => !!s.sync && !!s.file, Fs = (s) => !s.sync && !!s.file, Cs = (s) => !!s.sync && !s.file, ks = (s) => !s.sync && !s.file;
571
- var vs = (s) => !!s.file;
572
- var Qr = (s) => {
573
- return qr.get(s) || s;
574
- }, se = (s = {}) => {
575
- if (!s) return {};
576
- let t = {};
577
- for (let [e, i] of Object.entries(s)) {
578
- let r = Qr(e);
579
- t[r] = i;
580
- }
581
- return t.chmod === void 0 && t.noChmod === !1 && (t.chmod = !0), delete t.noChmod, t;
582
- };
583
- var K = (s, t, e, i, r) => Object.assign((n = [], o, a) => {
584
- Array.isArray(n) && (o = n, n = {}), typeof o == "function" && (a = o, o = void 0), o = o ? Array.from(o) : [];
585
- let h = se(n);
586
- if (r?.(h, o), Is(h)) {
587
- if (typeof a == "function") throw new TypeError("callback not supported for sync tar functions");
588
- return s(h, o);
589
- } else if (Fs(h)) {
590
- let l = t(h, o);
591
- return a ? l.then(() => a(), a) : l;
592
- } else if (Cs(h)) {
593
- if (typeof a == "function") throw new TypeError("callback not supported for sync tar functions");
594
- return e(h, o);
595
- } else if (ks(h)) {
596
- if (typeof a == "function") throw new TypeError("callback only supported with file option");
597
- return i(h, o);
598
- }
599
- throw new Error("impossible options??");
600
- }, {
601
- syncFile: s,
602
- asyncFile: t,
603
- syncNoFile: e,
604
- asyncNoFile: i,
605
- validate: r
606
- });
607
- var jr = Jr.constants || { ZLIB_VERNUM: 4736 }, M = Object.freeze(Object.assign(Object.create(null), {
608
- Z_NO_FLUSH: 0,
609
- Z_PARTIAL_FLUSH: 1,
610
- Z_SYNC_FLUSH: 2,
611
- Z_FULL_FLUSH: 3,
612
- Z_FINISH: 4,
613
- Z_BLOCK: 5,
614
- Z_OK: 0,
615
- Z_STREAM_END: 1,
616
- Z_NEED_DICT: 2,
617
- Z_ERRNO: -1,
618
- Z_STREAM_ERROR: -2,
619
- Z_DATA_ERROR: -3,
620
- Z_MEM_ERROR: -4,
621
- Z_BUF_ERROR: -5,
622
- Z_VERSION_ERROR: -6,
623
- Z_NO_COMPRESSION: 0,
624
- Z_BEST_SPEED: 1,
625
- Z_BEST_COMPRESSION: 9,
626
- Z_DEFAULT_COMPRESSION: -1,
627
- Z_FILTERED: 1,
628
- Z_HUFFMAN_ONLY: 2,
629
- Z_RLE: 3,
630
- Z_FIXED: 4,
631
- Z_DEFAULT_STRATEGY: 0,
632
- DEFLATE: 1,
633
- INFLATE: 2,
634
- GZIP: 3,
635
- GUNZIP: 4,
636
- DEFLATERAW: 5,
637
- INFLATERAW: 6,
638
- UNZIP: 7,
639
- BROTLI_DECODE: 8,
640
- BROTLI_ENCODE: 9,
641
- Z_MIN_WINDOWBITS: 8,
642
- Z_MAX_WINDOWBITS: 15,
643
- Z_DEFAULT_WINDOWBITS: 15,
644
- Z_MIN_CHUNK: 64,
645
- Z_MAX_CHUNK: Infinity,
646
- Z_DEFAULT_CHUNK: 16384,
647
- Z_MIN_MEMLEVEL: 1,
648
- Z_MAX_MEMLEVEL: 9,
649
- Z_DEFAULT_MEMLEVEL: 8,
650
- Z_MIN_LEVEL: -1,
651
- Z_MAX_LEVEL: 9,
652
- Z_DEFAULT_LEVEL: -1,
653
- BROTLI_OPERATION_PROCESS: 0,
654
- BROTLI_OPERATION_FLUSH: 1,
655
- BROTLI_OPERATION_FINISH: 2,
656
- BROTLI_OPERATION_EMIT_METADATA: 3,
657
- BROTLI_MODE_GENERIC: 0,
658
- BROTLI_MODE_TEXT: 1,
659
- BROTLI_MODE_FONT: 2,
660
- BROTLI_DEFAULT_MODE: 0,
661
- BROTLI_MIN_QUALITY: 0,
662
- BROTLI_MAX_QUALITY: 11,
663
- BROTLI_DEFAULT_QUALITY: 11,
664
- BROTLI_MIN_WINDOW_BITS: 10,
665
- BROTLI_MAX_WINDOW_BITS: 24,
666
- BROTLI_LARGE_MAX_WINDOW_BITS: 30,
667
- BROTLI_DEFAULT_WINDOW: 22,
668
- BROTLI_MIN_INPUT_BLOCK_BITS: 16,
669
- BROTLI_MAX_INPUT_BLOCK_BITS: 24,
670
- BROTLI_PARAM_MODE: 0,
671
- BROTLI_PARAM_QUALITY: 1,
672
- BROTLI_PARAM_LGWIN: 2,
673
- BROTLI_PARAM_LGBLOCK: 3,
674
- BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4,
675
- BROTLI_PARAM_SIZE_HINT: 5,
676
- BROTLI_PARAM_LARGE_WINDOW: 6,
677
- BROTLI_PARAM_NPOSTFIX: 7,
678
- BROTLI_PARAM_NDIRECT: 8,
679
- BROTLI_DECODER_RESULT_ERROR: 0,
680
- BROTLI_DECODER_RESULT_SUCCESS: 1,
681
- BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
682
- BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3,
683
- BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
684
- BROTLI_DECODER_PARAM_LARGE_WINDOW: 1,
685
- BROTLI_DECODER_NO_ERROR: 0,
686
- BROTLI_DECODER_SUCCESS: 1,
687
- BROTLI_DECODER_NEEDS_MORE_INPUT: 2,
688
- BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
689
- BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1,
690
- BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
691
- BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
692
- BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4,
693
- BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
694
- BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6,
695
- BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
696
- BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8,
697
- BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
698
- BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10,
699
- BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
700
- BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12,
701
- BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
702
- BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14,
703
- BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
704
- BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16,
705
- BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
706
- BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20,
707
- BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
708
- BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22,
709
- BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
710
- BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26,
711
- BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
712
- BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30,
713
- BROTLI_DECODER_ERROR_UNREACHABLE: -31
714
- }, jr));
715
- var tn = Buffer$1.concat, Bs = Object.getOwnPropertyDescriptor(Buffer$1, "concat"), en = (s) => s, Mi = Bs?.writable === !0 || Bs?.set !== void 0 ? (s) => {
716
- Buffer$1.concat = s ? en : tn;
717
- } : (s) => {}, Tt = Symbol("_superWrite"), Gt = class extends Error {
718
- code;
719
- errno;
720
- constructor(t, e) {
721
- super("zlib: " + t.message, { cause: t }), this.code = t.code, this.errno = t.errno, this.code || (this.code = "ZLIB_ERROR"), this.message = "zlib: " + t.message, Error.captureStackTrace(this, e ?? this.constructor);
722
- }
723
- get name() {
724
- return "ZlibError";
725
- }
726
- }, Bi = Symbol("flushFlag"), re = class extends A$1 {
727
- #t = !1;
728
- #i = !1;
729
- #s;
730
- #n;
731
- #r;
732
- #e;
733
- #o;
734
- get sawError() {
735
- return this.#t;
736
- }
737
- get handle() {
738
- return this.#e;
739
- }
740
- get flushFlag() {
741
- return this.#s;
742
- }
743
- constructor(t, e) {
744
- if (!t || typeof t != "object") throw new TypeError("invalid options for ZlibBase constructor");
745
- if (super(t), this.#s = t.flush ?? 0, this.#n = t.finishFlush ?? 0, this.#r = t.fullFlushFlag ?? 0, typeof Ms[e] != "function") throw new TypeError("Compression method not supported: " + e);
746
- try {
747
- this.#e = new Ms[e](t);
748
- } catch (i) {
749
- throw new Gt(i, this.constructor);
750
- }
751
- this.#o = (i) => {
752
- this.#t || (this.#t = !0, this.close(), this.emit("error", i));
753
- }, this.#e?.on("error", (i) => this.#o(new Gt(i))), this.once("end", () => this.close);
754
- }
755
- close() {
756
- this.#e && (this.#e.close(), this.#e = void 0, this.emit("close"));
757
- }
758
- reset() {
759
- if (!this.#t) return Pi(this.#e, "zlib binding closed"), this.#e.reset?.();
760
- }
761
- flush(t) {
762
- this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(Buffer$1.alloc(0), { [Bi]: t })));
763
- }
764
- end(t, e, i) {
765
- return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), t && (e ? this.write(t, e) : this.write(t)), this.flush(this.#n), this.#i = !0, super.end(i);
766
- }
767
- get ended() {
768
- return this.#i;
769
- }
770
- [Tt](t) {
771
- return super.write(t);
772
- }
773
- write(t, e, i) {
774
- if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t = Buffer$1.from(t, e)), this.#t) return;
775
- Pi(this.#e, "zlib binding closed");
776
- let r = this.#e._handle, n = r.close;
777
- r.close = () => {};
778
- let o = this.#e.close;
779
- this.#e.close = () => {}, Mi(!0);
780
- let a;
781
- try {
782
- let l = typeof t[Bi] == "number" ? t[Bi] : this.#s;
783
- a = this.#e._processChunk(t, l), Mi(!1);
784
- } catch (l) {
785
- Mi(!1), this.#o(new Gt(l, this.write));
786
- } finally {
787
- this.#e && (this.#e._handle = r, r.close = n, this.#e.close = o, this.#e.removeAllListeners("error"));
788
- }
789
- this.#e && this.#e.on("error", (l) => this.#o(new Gt(l, this.write)));
790
- let h;
791
- if (a) if (Array.isArray(a) && a.length > 0) {
792
- let l = a[0];
793
- h = this[Tt](Buffer$1.from(l));
794
- for (let c = 1; c < a.length; c++) h = this[Tt](a[c]);
795
- } else h = this[Tt](Buffer$1.from(a));
796
- return i && i(), h;
797
- }
798
- }, Be = class extends re {
799
- #t;
800
- #i;
801
- constructor(t, e) {
802
- t = t || {}, t.flush = t.flush || M.Z_NO_FLUSH, t.finishFlush = t.finishFlush || M.Z_FINISH, t.fullFlushFlag = M.Z_FULL_FLUSH, super(t, e), this.#t = t.level, this.#i = t.strategy;
803
- }
804
- params(t, e) {
805
- if (!this.sawError) {
806
- if (!this.handle) throw new Error("cannot switch params when binding is closed");
807
- if (!this.handle.params) throw new Error("not supported in this implementation");
808
- if (this.#t !== t || this.#i !== e) {
809
- this.flush(M.Z_SYNC_FLUSH), Pi(this.handle, "zlib binding closed");
810
- let i = this.handle.flush;
811
- this.handle.flush = (r, n) => {
812
- typeof r == "function" && (n = r, r = this.flushFlag), this.flush(r), n?.();
813
- };
814
- try {
815
- this.handle.params(t, e);
816
- } finally {
817
- this.handle.flush = i;
818
- }
819
- this.handle && (this.#t = t, this.#i = e);
820
- }
821
- }
822
- }
823
- };
824
- var Pe = class extends Be {
825
- #t;
826
- constructor(t) {
827
- super(t, "Gzip"), this.#t = t && !!t.portable;
828
- }
829
- [Tt](t) {
830
- return this.#t ? (this.#t = !1, t[9] = 255, super[Tt](t)) : super[Tt](t);
831
- }
832
- };
833
- var ze = class extends Be {
834
- constructor(t) {
835
- super(t, "Unzip");
836
- }
837
- }, Ue = class extends re {
838
- constructor(t, e) {
839
- t = t || {}, t.flush = t.flush || M.BROTLI_OPERATION_PROCESS, t.finishFlush = t.finishFlush || M.BROTLI_OPERATION_FINISH, t.fullFlushFlag = M.BROTLI_OPERATION_FLUSH, super(t, e);
840
- }
841
- }, He = class extends Ue {
842
- constructor(t) {
843
- super(t, "BrotliCompress");
844
- }
845
- }, We = class extends Ue {
846
- constructor(t) {
847
- super(t, "BrotliDecompress");
848
- }
849
- }, Ge = class extends re {
850
- constructor(t, e) {
851
- t = t || {}, t.flush = t.flush || M.ZSTD_e_continue, t.finishFlush = t.finishFlush || M.ZSTD_e_end, t.fullFlushFlag = M.ZSTD_e_flush, super(t, e);
852
- }
853
- }, Ze = class extends Ge {
854
- constructor(t) {
855
- super(t, "ZstdCompress");
856
- }
857
- }, Ye = class extends Ge {
858
- constructor(t) {
859
- super(t, "ZstdDecompress");
860
- }
861
- };
862
- var Ps = (s, t) => {
863
- if (Number.isSafeInteger(s)) s < 0 ? nn(s, t) : rn(s, t);
864
- else throw Error("cannot encode number outside of javascript safe integer range");
865
- return t;
866
- }, rn = (s, t) => {
867
- t[0] = 128;
868
- for (var e = t.length; e > 1; e--) t[e - 1] = s & 255, s = Math.floor(s / 256);
869
- }, nn = (s, t) => {
870
- t[0] = 255;
871
- var e = !1;
872
- s = s * -1;
873
- for (var i = t.length; i > 1; i--) {
874
- var r = s & 255;
875
- s = Math.floor(s / 256), e ? t[i - 1] = Us(r) : r === 0 ? t[i - 1] = 0 : (e = !0, t[i - 1] = Hs(r));
876
- }
877
- }, zs = (s) => {
878
- let t = s[0], e = t === 128 ? hn(s.subarray(1, s.length)) : t === 255 ? on(s) : null;
879
- if (e === null) throw Error("invalid base256 encoding");
880
- if (!Number.isSafeInteger(e)) throw Error("parsed number outside of javascript safe integer range");
881
- return e;
882
- }, on = (s) => {
883
- for (var t = s.length, e = 0, i = !1, r = t - 1; r > -1; r--) {
884
- var n = Number(s[r]), o;
885
- i ? o = Us(n) : n === 0 ? o = n : (i = !0, o = Hs(n)), o !== 0 && (e -= o * Math.pow(256, t - r - 1));
886
- }
887
- return e;
888
- }, hn = (s) => {
889
- for (var t = s.length, e = 0, i = t - 1; i > -1; i--) {
890
- var r = Number(s[i]);
891
- r !== 0 && (e += r * Math.pow(256, t - i - 1));
892
- }
893
- return e;
894
- }, Us = (s) => (255 ^ s) & 255, Hs = (s) => (255 ^ s) + 1 & 255;
895
- Br({}, {
896
- code: () => Ke,
897
- isCode: () => ne,
898
- isName: () => ln,
899
- name: () => oe,
900
- normalFsTypes: () => zi
901
- });
902
- var ne = (s) => oe.has(s), ln = (s) => Ke.has(s), zi = new Set([
903
- "0",
904
- "",
905
- "1",
906
- "2",
907
- "3",
908
- "4",
909
- "5",
910
- "6",
911
- "7",
912
- "D"
913
- ]), oe = new Map([
914
- ["0", "File"],
915
- ["", "OldFile"],
916
- ["1", "Link"],
917
- ["2", "SymbolicLink"],
918
- ["3", "CharacterDevice"],
919
- ["4", "BlockDevice"],
920
- ["5", "Directory"],
921
- ["6", "FIFO"],
922
- ["7", "ContiguousFile"],
923
- ["g", "GlobalExtendedHeader"],
924
- ["x", "ExtendedHeader"],
925
- ["A", "SolarisACL"],
926
- ["D", "GNUDumpDir"],
927
- ["I", "Inode"],
928
- ["K", "NextFileHasLongLinkpath"],
929
- ["L", "NextFileHasLongPath"],
930
- ["M", "ContinuationFile"],
931
- ["N", "OldGnuLongPath"],
932
- ["S", "SparseFile"],
933
- ["V", "TapeVolumeHeader"],
934
- ["X", "OldExtendedHeader"]
935
- ]), Ke = new Map(Array.from(oe).map((s) => [s[1], s[0]]));
936
- var C$1 = class {
937
- cksumValid = !1;
938
- needPax = !1;
939
- nullBlock = !1;
940
- block;
941
- path;
942
- mode;
943
- uid;
944
- gid;
945
- size;
946
- cksum;
947
- #t = "Unsupported";
948
- linkpath;
949
- uname;
950
- gname;
951
- devmaj = 0;
952
- devmin = 0;
953
- atime;
954
- ctime;
955
- mtime;
956
- charset;
957
- comment;
958
- constructor(t, e = 0, i, r) {
959
- Buffer.isBuffer(t) ? this.decode(t, e || 0, i, r) : t && this.#i(t);
960
- }
961
- decode(t, e, i, r) {
962
- if (e || (e = 0), !t || !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
963
- let n = xt(t, e + 156, 1), o = zi.has(n), a = o ? i : void 0, h = o ? r : void 0;
964
- if (this.path = a?.path ?? xt(t, e, 100), this.mode = a?.mode ?? h?.mode ?? at(t, e + 100, 8), this.uid = a?.uid ?? h?.uid ?? at(t, e + 108, 8), this.gid = a?.gid ?? h?.gid ?? at(t, e + 116, 8), this.size = a?.size ?? h?.size ?? at(t, e + 124, 12), this.mtime = a?.mtime ?? h?.mtime ?? Hi(t, e + 136, 12), this.cksum = at(t, e + 148, 12), h && this.#i(h, !0), a && this.#i(a), ne(n) && (this.#t = n || "0"), this.#t === "0" && this.path.slice(-1) === "/" && (this.#t = "5"), this.#t === "5" && (this.size = 0), this.linkpath = xt(t, e + 157, 100), t.subarray(e + 257, e + 265).toString() === "ustar\x0000") if (this.uname = a?.uname ?? h?.uname ?? xt(t, e + 265, 32), this.gname = a?.gname ?? h?.gname ?? xt(t, e + 297, 32), this.devmaj = a?.devmaj ?? h?.devmaj ?? at(t, e + 329, 8) ?? 0, this.devmin = a?.devmin ?? h?.devmin ?? at(t, e + 337, 8) ?? 0, t[e + 475] !== 0) {
965
- let c = xt(t, e + 345, 155);
966
- this.path = c + "/" + this.path;
967
- } else {
968
- let c = xt(t, e + 345, 130);
969
- c && (this.path = c + "/" + this.path), this.atime = i?.atime ?? r?.atime ?? Hi(t, e + 476, 12), this.ctime = i?.ctime ?? r?.ctime ?? Hi(t, e + 488, 12);
970
- }
971
- let l = 256;
972
- for (let c = e; c < e + 148; c++) l += t[c];
973
- for (let c = e + 156; c < e + 512; c++) l += t[c];
974
- this.cksumValid = l === this.cksum, this.cksum === void 0 && l === 256 && (this.nullBlock = !0);
975
- }
976
- #i(t, e = !1) {
977
- Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "path" && e || i === "linkpath" && e || i === "global"))));
978
- }
979
- encode(t, e = 0) {
980
- if (t || (t = this.block = Buffer.alloc(512)), this.#t === "Unsupported" && (this.#t = "0"), !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
981
- let i = this.ctime || this.atime ? 130 : 155, r = cn(this.path || "", i), n = r[0], o = r[1];
982
- this.needPax = !!r[2], this.needPax = Lt(t, e, 100, n) || this.needPax, this.needPax = lt(t, e + 100, 8, this.mode) || this.needPax, this.needPax = lt(t, e + 108, 8, this.uid) || this.needPax, this.needPax = lt(t, e + 116, 8, this.gid) || this.needPax, this.needPax = lt(t, e + 124, 12, this.size) || this.needPax, this.needPax = Wi(t, e + 136, 12, this.mtime) || this.needPax, t[e + 156] = Number(this.#t.codePointAt(0)), this.needPax = Lt(t, e + 157, 100, this.linkpath) || this.needPax, t.write("ustar\x0000", e + 257, 8), this.needPax = Lt(t, e + 265, 32, this.uname) || this.needPax, this.needPax = Lt(t, e + 297, 32, this.gname) || this.needPax, this.needPax = lt(t, e + 329, 8, this.devmaj) || this.needPax, this.needPax = lt(t, e + 337, 8, this.devmin) || this.needPax, this.needPax = Lt(t, e + 345, i, o) || this.needPax, t[e + 475] !== 0 ? this.needPax = Lt(t, e + 345, 155, o) || this.needPax : (this.needPax = Lt(t, e + 345, 130, o) || this.needPax, this.needPax = Wi(t, e + 476, 12, this.atime) || this.needPax, this.needPax = Wi(t, e + 488, 12, this.ctime) || this.needPax);
983
- let a = 256;
984
- for (let h = e; h < e + 148; h++) a += t[h];
985
- for (let h = e + 156; h < e + 512; h++) a += t[h];
986
- return this.cksum = a, lt(t, e + 148, 8, this.cksum), this.cksumValid = !0, this.needPax;
987
- }
988
- get type() {
989
- return this.#t === "Unsupported" ? this.#t : oe.get(this.#t);
990
- }
991
- get typeKey() {
992
- return this.#t;
993
- }
994
- set type(t) {
995
- let e = String(Ke.get(t));
996
- if (ne(e) || e === "Unsupported") this.#t = e;
997
- else if (ne(t)) this.#t = t;
998
- else throw new TypeError("invalid entry type: " + t);
999
- }
1000
- }, cn = (s, t) => {
1001
- let i = s, r = "", n, o = posix.parse(s).root || ".";
1002
- if (Buffer.byteLength(i) < 100) n = [
1003
- i,
1004
- r,
1005
- !1
1006
- ];
1007
- else {
1008
- r = posix.dirname(i), i = posix.basename(i);
1009
- do
1010
- Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [
1011
- i,
1012
- r,
1013
- !1
1014
- ] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [
1015
- i.slice(0, 99),
1016
- r,
1017
- !0
1018
- ] : (i = posix.join(posix.basename(r), i), r = posix.dirname(r));
1019
- while (r !== o && n === void 0);
1020
- n || (n = [
1021
- s.slice(0, 99),
1022
- "",
1023
- !0
1024
- ]);
1025
- }
1026
- return n;
1027
- }, xt = (s, t, e) => s.subarray(t, t + e).toString("utf8").replace(/\0.*/, ""), Hi = (s, t, e) => fn(at(s, t, e)), fn = (s) => s === void 0 ? void 0 : /* @__PURE__ */ new Date(s * 1e3), at = (s, t, e) => Number(s[t]) & 128 ? zs(s.subarray(t, t + e)) : un(s, t, e), dn = (s) => isNaN(s) ? void 0 : s, un = (s, t, e) => dn(parseInt(s.subarray(t, t + e).toString("utf8").replace(/\0.*$/, "").trim(), 8)), mn = {
1028
- 12: 8589934591,
1029
- 8: 2097151
1030
- }, lt = (s, t, e, i) => i === void 0 ? !1 : i > mn[e] || i < 0 ? (Ps(i, s.subarray(t, t + e)), !0) : (pn(s, t, e, i), !1), pn = (s, t, e, i) => s.write(En(i, e), t, e, "ascii"), En = (s, t) => wn(Math.floor(s).toString(8), t), wn = (s, t) => (s.length === t - 1 ? s : new Array(t - s.length - 1).join("0") + s + " ") + "\0", Wi = (s, t, e, i) => i === void 0 ? !1 : lt(s, t, e, i.getTime() / 1e3), Sn = new Array(156).join("\0"), Lt = (s, t, e, i) => i === void 0 ? !1 : (s.write(i + Sn, t, e, "utf8"), i.length !== Buffer.byteLength(i) || i.length > e);
1031
- var ct = class s {
1032
- atime;
1033
- mtime;
1034
- ctime;
1035
- charset;
1036
- comment;
1037
- gid;
1038
- uid;
1039
- gname;
1040
- uname;
1041
- linkpath;
1042
- dev;
1043
- ino;
1044
- nlink;
1045
- path;
1046
- size;
1047
- mode;
1048
- global;
1049
- constructor(t, e = !1) {
1050
- this.atime = t.atime, this.charset = t.charset, this.comment = t.comment, this.ctime = t.ctime, this.dev = t.dev, this.gid = t.gid, this.global = e, this.gname = t.gname, this.ino = t.ino, this.linkpath = t.linkpath, this.mtime = t.mtime, this.nlink = t.nlink, this.path = t.path, this.size = t.size, this.uid = t.uid, this.uname = t.uname;
1051
- }
1052
- encode() {
1053
- let t = this.encodeBody();
1054
- if (t === "") return Buffer.allocUnsafe(0);
1055
- let e = Buffer.byteLength(t), i = 512 * Math.ceil(1 + e / 512), r = Buffer.allocUnsafe(i);
1056
- for (let n = 0; n < 512; n++) r[n] = 0;
1057
- new C$1({
1058
- path: ("PaxHeader/" + basename(this.path ?? "")).slice(0, 99),
1059
- mode: this.mode || 420,
1060
- uid: this.uid,
1061
- gid: this.gid,
1062
- size: e,
1063
- mtime: this.mtime,
1064
- type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader",
1065
- linkpath: "",
1066
- uname: this.uname || "",
1067
- gname: this.gname || "",
1068
- devmaj: 0,
1069
- devmin: 0,
1070
- atime: this.atime,
1071
- ctime: this.ctime
1072
- }).encode(r), r.write(t, 512, e, "utf8");
1073
- for (let n = e + 512; n < r.length; n++) r[n] = 0;
1074
- return r;
1075
- }
1076
- encodeBody() {
1077
- return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname");
1078
- }
1079
- encodeField(t) {
1080
- if (this[t] === void 0) return "";
1081
- let e = this[t], i = e instanceof Date ? e.getTime() / 1e3 : e, r = " " + (t === "dev" || t === "ino" || t === "nlink" ? "SCHILY." : "") + t + "=" + i + `
1082
- `, n = Buffer.byteLength(r), o = Math.floor(Math.log(n) / Math.log(10)) + 1;
1083
- return n + o >= Math.pow(10, o) && (o += 1), o + n + r;
1084
- }
1085
- static parse(t, e, i = !1) {
1086
- return new s(Rn(gn(t), e), i);
1087
- }
1088
- }, Rn = (s, t) => t ? Object.assign({}, t, s) : s, gn = (s) => s.replace(/\n$/, "").split(`
1089
- `).reduce(bn, Object.create(null)), bn = (s, t) => {
1090
- let e = parseInt(t, 10);
1091
- if (e !== Buffer.byteLength(t) + 1) return s;
1092
- t = t.slice((e + " ").length);
1093
- let i = t.split("="), r = i.shift();
1094
- if (!r) return s;
1095
- let n = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1"), o = i.join("=");
1096
- return s[n] = /^([A-Z]+\.)?([mac]|birth|creation)time$/.test(n) ? /* @__PURE__ */ new Date(Number(o) * 1e3) : /^[0-9]+$/.test(o) ? +o : o, s;
1097
- };
1098
- var f$1 = (process.env.TESTING_TAR_FAKE_PLATFORM || process.platform) !== "win32" ? (s) => s : (s) => s && s.replaceAll(/\\/g, "/");
1099
- var Ve = class extends A$1 {
1100
- extended;
1101
- globalExtended;
1102
- header;
1103
- startBlockSize;
1104
- blockRemain;
1105
- remain;
1106
- type;
1107
- meta = !1;
1108
- ignore = !1;
1109
- path;
1110
- mode;
1111
- uid;
1112
- gid;
1113
- uname;
1114
- gname;
1115
- size = 0;
1116
- mtime;
1117
- atime;
1118
- ctime;
1119
- linkpath;
1120
- dev;
1121
- ino;
1122
- nlink;
1123
- invalid = !1;
1124
- absolute;
1125
- unsupported = !1;
1126
- constructor(t, e, i) {
1127
- switch (super({}), this.pause(), this.extended = e, this.globalExtended = i, this.header = t, this.remain = t.size ?? 0, this.startBlockSize = 512 * Math.ceil(this.remain / 512), this.blockRemain = this.startBlockSize, this.type = t.type, this.type) {
1128
- case "File":
1129
- case "OldFile":
1130
- case "Link":
1131
- case "SymbolicLink":
1132
- case "CharacterDevice":
1133
- case "BlockDevice":
1134
- case "Directory":
1135
- case "FIFO":
1136
- case "ContiguousFile":
1137
- case "GNUDumpDir": break;
1138
- case "NextFileHasLongLinkpath":
1139
- case "NextFileHasLongPath":
1140
- case "OldGnuLongPath":
1141
- case "GlobalExtendedHeader":
1142
- case "ExtendedHeader":
1143
- case "OldExtendedHeader":
1144
- this.meta = !0;
1145
- break;
1146
- default: this.ignore = !0;
1147
- }
1148
- if (!t.path) throw new Error("no path provided for tar.ReadEntry");
1149
- this.path = f$1(t.path), this.mode = t.mode, this.mode && (this.mode = this.mode & 4095), this.uid = t.uid, this.gid = t.gid, this.uname = t.uname, this.gname = t.gname, this.size = this.remain, this.mtime = t.mtime, this.atime = t.atime, this.ctime = t.ctime, this.linkpath = t.linkpath ? f$1(t.linkpath) : void 0, this.uname = t.uname, this.gname = t.gname, e && this.#t(e), i && this.#t(i, !0);
1150
- }
1151
- write(t) {
1152
- let e = t.length;
1153
- if (e > this.blockRemain) throw new Error("writing more to entry than is appropriate");
1154
- let i = this.remain, r = this.blockRemain;
1155
- return this.remain = Math.max(0, i - e), this.blockRemain = Math.max(0, r - e), this.ignore ? !0 : i >= e ? super.write(t) : super.write(t.subarray(0, i));
1156
- }
1157
- #t(t, e = !1) {
1158
- t.path && (t.path = f$1(t.path)), t.linkpath && (t.linkpath = f$1(t.linkpath)), Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "path" && e))));
1159
- }
1160
- };
1161
- var Nt = (s, t, e, i = {}) => {
1162
- s.file && (i.file = s.file), s.cwd && (i.cwd = s.cwd), i.code = e instanceof Error && e.code || t, i.tarCode = t, !s.strict && i.recoverable !== !1 ? (e instanceof Error && (i = Object.assign(e, i), e = e.message), s.emit("warn", t, e, i)) : e instanceof Error ? s.emit("error", Object.assign(e, i)) : s.emit("error", Object.assign(/* @__PURE__ */ new Error(`${t}: ${e}`), i));
1163
- };
1164
- var Tn = 1024 * 1024, Vi = Buffer.from([31, 139]), $i = Buffer.from([
1165
- 40,
1166
- 181,
1167
- 47,
1168
- 253
1169
- ]), xn = Math.max(Vi.length, $i.length), B = Symbol("state"), Dt = Symbol("writeEntry"), et = Symbol("readEntry"), Gi = Symbol("nextEntry"), Ws = Symbol("processEntry"), V = Symbol("extendedHeader"), he = Symbol("globalExtendedHeader"), ft = Symbol("meta"), Gs = Symbol("emitMeta"), p$1 = Symbol("buffer"), it = Symbol("queue"), dt = Symbol("ended"), Zi = Symbol("emittedEnd"), At = Symbol("emit"), y = Symbol("unzip"), $e = Symbol("consumeChunk"), Xe = Symbol("consumeChunkSub"), Yi = Symbol("consumeBody"), Zs = Symbol("consumeMeta"), Ys = Symbol("consumeHeader"), ae = Symbol("consuming"), Ki = Symbol("bufferConcat"), qe = Symbol("maybeEnd"), Yt = Symbol("writing"), ut = Symbol("aborted"), Qe = Symbol("onDone"), It = Symbol("sawValidEntry"), Je = Symbol("sawNullBlock"), je = Symbol("sawEOF"), Ks = Symbol("closeStream"), Ln = () => !0, st = class extends EventEmitter$1 {
1170
- file;
1171
- strict;
1172
- maxMetaEntrySize;
1173
- filter;
1174
- brotli;
1175
- zstd;
1176
- writable = !0;
1177
- readable = !1;
1178
- [it] = [];
1179
- [p$1];
1180
- [et];
1181
- [Dt];
1182
- [B] = "begin";
1183
- [ft] = "";
1184
- [V];
1185
- [he];
1186
- [dt] = !1;
1187
- [y];
1188
- [ut] = !1;
1189
- [It];
1190
- [Je] = !1;
1191
- [je] = !1;
1192
- [Yt] = !1;
1193
- [ae] = !1;
1194
- [Zi] = !1;
1195
- constructor(t = {}) {
1196
- super(), this.file = t.file || "", this.on(Qe, () => {
1197
- (this[B] === "begin" || this[It] === !1) && this.warn("TAR_BAD_ARCHIVE", "Unrecognized archive format");
1198
- }), t.ondone ? this.on(Qe, t.ondone) : this.on(Qe, () => {
1199
- this.emit("prefinish"), this.emit("finish"), this.emit("end");
1200
- }), this.strict = !!t.strict, this.maxMetaEntrySize = t.maxMetaEntrySize || Tn, this.filter = typeof t.filter == "function" ? t.filter : Ln;
1201
- let e = t.file && (t.file.endsWith(".tar.br") || t.file.endsWith(".tbr"));
1202
- this.brotli = !(t.gzip || t.zstd) && t.brotli !== void 0 ? t.brotli : e ? void 0 : !1;
1203
- let i = t.file && (t.file.endsWith(".tar.zst") || t.file.endsWith(".tzst"));
1204
- this.zstd = !(t.gzip || t.brotli) && t.zstd !== void 0 ? t.zstd : i ? !0 : void 0, this.on("end", () => this[Ks]()), typeof t.onwarn == "function" && this.on("warn", t.onwarn), typeof t.onReadEntry == "function" && this.on("entry", t.onReadEntry);
1205
- }
1206
- warn(t, e, i = {}) {
1207
- Nt(this, t, e, i);
1208
- }
1209
- [Ys](t, e) {
1210
- this[It] === void 0 && (this[It] = !1);
1211
- let i;
1212
- try {
1213
- i = new C$1(t, e, this[V], this[he]);
1214
- } catch (r) {
1215
- return this.warn("TAR_ENTRY_INVALID", r);
1216
- }
1217
- if (i.nullBlock) this[Je] ? (this[je] = !0, this[B] === "begin" && (this[B] = "header"), this[At]("eof")) : (this[Je] = !0, this[At]("nullBlock"));
1218
- else if (this[Je] = !1, !i.cksumValid) this.warn("TAR_ENTRY_INVALID", "checksum failure", { header: i });
1219
- else if (!i.path) this.warn("TAR_ENTRY_INVALID", "path is required", { header: i });
1220
- else {
1221
- let r = i.type;
1222
- if (/^(Symbolic)?Link$/.test(r) && !i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath required", { header: i });
1223
- else if (!/^(Symbolic)?Link$/.test(r) && !/^(Global)?ExtendedHeader$/.test(r) && i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath forbidden", { header: i });
1224
- else {
1225
- let n = this[Dt] = new Ve(i, this[V], this[he]);
1226
- if (!this[It]) if (n.remain) {
1227
- let o = () => {
1228
- n.invalid || (this[It] = !0);
1229
- };
1230
- n.on("end", o);
1231
- } else this[It] = !0;
1232
- n.meta ? n.size > this.maxMetaEntrySize ? (n.ignore = !0, this[At]("ignoredEntry", n), this[B] = "ignore", n.resume()) : n.size > 0 && (this[ft] = "", n.on("data", (o) => this[ft] += o), this[B] = "meta") : (this[V] = void 0, n.ignore = n.ignore || !this.filter(n.path, n), n.ignore ? (this[At]("ignoredEntry", n), this[B] = n.remain ? "ignore" : "header", n.resume()) : (n.remain ? this[B] = "body" : (this[B] = "header", n.end()), this[et] ? this[it].push(n) : (this[it].push(n), this[Gi]())));
1233
- }
1234
- }
1235
- }
1236
- [Ks]() {
1237
- queueMicrotask(() => this.emit("close"));
1238
- }
1239
- [Ws](t) {
1240
- let e = !0;
1241
- if (!t) this[et] = void 0, e = !1;
1242
- else if (Array.isArray(t)) {
1243
- let [i, ...r] = t;
1244
- this.emit(i, ...r);
1245
- } else this[et] = t, this.emit("entry", t), t.emittedEnd || (t.on("end", () => this[Gi]()), e = !1);
1246
- return e;
1247
- }
1248
- [Gi]() {
1249
- do ;
1250
- while (this[Ws](this[it].shift()));
1251
- if (this[it].length === 0) {
1252
- let t = this[et];
1253
- !t || t.flowing || t.size === t.remain ? this[Yt] || this.emit("drain") : t.once("drain", () => this.emit("drain"));
1254
- }
1255
- }
1256
- [Yi](t, e) {
1257
- let i = this[Dt];
1258
- if (!i) throw new Error("attempt to consume body without entry??");
1259
- let r = i.blockRemain ?? 0, n = r >= t.length && e === 0 ? t : t.subarray(e, e + r);
1260
- return i.write(n), i.blockRemain || (this[B] = "header", this[Dt] = void 0, i.end()), n.length;
1261
- }
1262
- [Zs](t, e) {
1263
- let i = this[Dt], r = this[Yi](t, e);
1264
- return !this[Dt] && i && this[Gs](i), r;
1265
- }
1266
- [At](t, e, i) {
1267
- this[it].length === 0 && !this[et] ? this.emit(t, e, i) : this[it].push([
1268
- t,
1269
- e,
1270
- i
1271
- ]);
1272
- }
1273
- [Gs](t) {
1274
- switch (this[At]("meta", this[ft]), t.type) {
1275
- case "ExtendedHeader":
1276
- case "OldExtendedHeader":
1277
- this[V] = ct.parse(this[ft], this[V], !1);
1278
- break;
1279
- case "GlobalExtendedHeader":
1280
- this[he] = ct.parse(this[ft], this[he], !0);
1281
- break;
1282
- case "NextFileHasLongPath":
1283
- case "OldGnuLongPath": {
1284
- let e = this[V] ?? Object.create(null);
1285
- this[V] = e, e.path = this[ft].replace(/\0.*/, "");
1286
- break;
1287
- }
1288
- case "NextFileHasLongLinkpath": {
1289
- let e = this[V] || Object.create(null);
1290
- this[V] = e, e.linkpath = this[ft].replace(/\0.*/, "");
1291
- break;
1292
- }
1293
- default: throw new Error("unknown meta: " + t.type);
1294
- }
1295
- }
1296
- abort(t) {
1297
- this[ut] = !0, this.emit("abort", t), this.warn("TAR_ABORT", t, { recoverable: !1 });
1298
- }
1299
- write(t, e, i) {
1300
- if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this[ut]) return i?.(), !1;
1301
- if ((this[y] === void 0 || this.brotli === void 0 && this[y] === !1) && t) {
1302
- if (this[p$1] && (t = Buffer.concat([this[p$1], t]), this[p$1] = void 0), t.length < xn) return this[p$1] = t, i?.(), !0;
1303
- for (let h = 0; this[y] === void 0 && h < Vi.length; h++) t[h] !== Vi[h] && (this[y] = !1);
1304
- let o = !1;
1305
- if (this[y] === !1 && this.zstd !== !1) {
1306
- o = !0;
1307
- for (let h = 0; h < $i.length; h++) if (t[h] !== $i[h]) {
1308
- o = !1;
1309
- break;
1310
- }
1311
- }
1312
- let a = this.brotli === void 0 && !o;
1313
- if (this[y] === !1 && a) if (t.length < 512) if (this[dt]) this.brotli = !0;
1314
- else return this[p$1] = t, i?.(), !0;
1315
- else try {
1316
- new C$1(t.subarray(0, 512)), this.brotli = !1;
1317
- } catch {
1318
- this.brotli = !0;
1319
- }
1320
- if (this[y] === void 0 || this[y] === !1 && (this.brotli || o)) {
1321
- let h = this[dt];
1322
- this[dt] = !1, this[y] = this[y] === void 0 ? new ze({}) : o ? new Ye({}) : new We({}), this[y].on("data", (c) => this[$e](c)), this[y].on("error", (c) => this.abort(c)), this[y].on("end", () => {
1323
- this[dt] = !0, this[$e]();
1324
- }), this[Yt] = !0;
1325
- let l = !!this[y][h ? "end" : "write"](t);
1326
- return this[Yt] = !1, i?.(), l;
1327
- }
1328
- }
1329
- this[Yt] = !0, this[y] ? this[y].write(t) : this[$e](t), this[Yt] = !1;
1330
- let n = this[it].length > 0 ? !1 : this[et] ? this[et].flowing : !0;
1331
- return !n && this[it].length === 0 && this[et]?.once("drain", () => this.emit("drain")), i?.(), n;
1332
- }
1333
- [Ki](t) {
1334
- t && !this[ut] && (this[p$1] = this[p$1] ? Buffer.concat([this[p$1], t]) : t);
1335
- }
1336
- [qe]() {
1337
- if (this[dt] && !this[Zi] && !this[ut] && !this[ae]) {
1338
- this[Zi] = !0;
1339
- let t = this[Dt];
1340
- if (t && t.blockRemain) {
1341
- let e = this[p$1] ? this[p$1].length : 0;
1342
- this.warn("TAR_BAD_ARCHIVE", `Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`, { entry: t }), this[p$1] && t.write(this[p$1]), t.end();
1343
- }
1344
- this[At](Qe);
1345
- }
1346
- }
1347
- [$e](t) {
1348
- if (this[ae] && t) this[Ki](t);
1349
- else if (!t && !this[p$1]) this[qe]();
1350
- else if (t) {
1351
- if (this[ae] = !0, this[p$1]) {
1352
- this[Ki](t);
1353
- let e = this[p$1];
1354
- this[p$1] = void 0, this[Xe](e);
1355
- } else this[Xe](t);
1356
- for (; this[p$1] && this[p$1]?.length >= 512 && !this[ut] && !this[je];) {
1357
- let e = this[p$1];
1358
- this[p$1] = void 0, this[Xe](e);
1359
- }
1360
- this[ae] = !1;
1361
- }
1362
- (!this[p$1] || this[dt]) && this[qe]();
1363
- }
1364
- [Xe](t) {
1365
- let e = 0, i = t.length;
1366
- for (; e + 512 <= i && !this[ut] && !this[je];) switch (this[B]) {
1367
- case "begin":
1368
- case "header":
1369
- this[Ys](t, e), e += 512;
1370
- break;
1371
- case "ignore":
1372
- case "body":
1373
- e += this[Yi](t, e);
1374
- break;
1375
- case "meta":
1376
- e += this[Zs](t, e);
1377
- break;
1378
- default: throw new Error("invalid state: " + this[B]);
1379
- }
1380
- e < i && (this[p$1] = this[p$1] ? Buffer.concat([t.subarray(e), this[p$1]]) : t.subarray(e));
1381
- }
1382
- end(t, e, i) {
1383
- return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[ut] || (this[y] ? (t && this[y].write(t), this[y].end()) : (this[dt] = !0, (this.brotli === void 0 || this.zstd === void 0) && (t = t || Buffer.alloc(0)), t && this.write(t), this[qe]())), this;
1384
- }
1385
- };
1386
- var mt = (s) => {
1387
- let t = s.length - 1, e = -1;
1388
- for (; t > -1 && s.charAt(t) === "/";) e = t, t--;
1389
- return e === -1 ? s : s.slice(0, e);
1390
- };
1391
- var An = (s) => {
1392
- let t = s.onReadEntry;
1393
- s.onReadEntry = t ? (e) => {
1394
- t(e), e.resume();
1395
- } : (e) => e.resume();
1396
- }, Xi = (s, t) => {
1397
- let e = new Map(t.map((n) => [mt(n), !0])), i = s.filter, r = (n, o = "") => {
1398
- let a = o || parse(n).root || ".", h;
1399
- if (n === a) h = !1;
1400
- else {
1401
- let l = e.get(n);
1402
- h = l !== void 0 ? l : r(dirname$1(n), a);
1403
- }
1404
- return e.set(n, h), h;
1405
- };
1406
- s.filter = i ? (n, o) => i(n, o) && r(mt(n)) : (n) => r(mt(n));
1407
- }, In = (s) => {
1408
- let t = new st(s), e = s.file, i;
1409
- try {
1410
- i = Kt.openSync(e, "r");
1411
- let r = Kt.fstatSync(i), n = s.maxReadSize || 16 * 1024 * 1024;
1412
- if (r.size < n) {
1413
- let o = Buffer.allocUnsafe(r.size), a = Kt.readSync(i, o, 0, r.size, 0);
1414
- t.end(a === o.byteLength ? o : o.subarray(0, a));
1415
- } else {
1416
- let o = 0, a = Buffer.allocUnsafe(n);
1417
- for (; o < r.size;) {
1418
- let h = Kt.readSync(i, a, 0, n, o);
1419
- if (h === 0) break;
1420
- o += h, t.write(a.subarray(0, h));
1421
- }
1422
- t.end();
1423
- }
1424
- } finally {
1425
- if (typeof i == "number") try {
1426
- Kt.closeSync(i);
1427
- } catch {}
1428
- }
1429
- }, Fn = (s, t) => {
1430
- let e = new st(s), i = s.maxReadSize || 16 * 1024 * 1024, r = s.file;
1431
- return new Promise((o, a) => {
1432
- e.on("error", a), e.on("end", o), Kt.stat(r, (h, l) => {
1433
- if (h) a(h);
1434
- else {
1435
- let c = new _t(r, {
1436
- readSize: i,
1437
- size: l.size
1438
- });
1439
- c.on("error", a), c.pipe(e);
1440
- }
1441
- });
1442
- });
1443
- }, Ft = K(In, Fn, (s) => new st(s), (s) => new st(s), (s, t) => {
1444
- t?.length && Xi(s, t), s.noResume || An(s);
1445
- });
1446
- var qi = (s, t, e) => (s &= 4095, e && (s = (s | 384) & -19), t && (s & 256 && (s |= 64), s & 32 && (s |= 8), s & 4 && (s |= 1)), s);
1447
- var { isAbsolute: kn, parse: Vs } = win32, le = (s) => {
1448
- let t = "", e = Vs(s);
1449
- for (; kn(s) || e.root;) {
1450
- let i = s.charAt(0) === "/" && s.slice(0, 4) !== "//?/" ? "/" : e.root;
1451
- s = s.slice(i.length), t += i, e = Vs(s);
1452
- }
1453
- return [t, s];
1454
- };
1455
- var ti = [
1456
- "|",
1457
- "<",
1458
- ">",
1459
- "?",
1460
- ":"
1461
- ], Qi = ti.map((s) => String.fromCodePoint(61440 + Number(s.codePointAt(0)))), vn = new Map(ti.map((s, t) => [s, Qi[t]])), Mn = new Map(Qi.map((s, t) => [s, ti[t]])), Ji = (s) => ti.reduce((t, e) => t.split(e).join(vn.get(e)), s), $s = (s) => Qi.reduce((t, e) => t.split(e).join(Mn.get(e)), s);
1462
- var er = (s, t) => t ? (s = f$1(s).replace(/^\.(\/|$)/, ""), mt(t) + "/" + s) : f$1(s), Bn = 16 * 1024 * 1024, Qs = Symbol("process"), Js = Symbol("file"), js = Symbol("directory"), ts = Symbol("symlink"), tr = Symbol("hardlink"), ce = Symbol("header"), ei = Symbol("read"), es = Symbol("lstat"), ii = Symbol("onlstat"), is = Symbol("onread"), ss = Symbol("onreadlink"), rs = Symbol("openfile"), ns = Symbol("onopenfile"), pt = Symbol("close"), si = Symbol("mode"), os = Symbol("awaitDrain"), ji = Symbol("ondrain"), X = Symbol("prefix"), fe = class extends A$1 {
1463
- path;
1464
- portable;
1465
- myuid = process.getuid && process.getuid() || 0;
1466
- myuser = process.env.USER || "";
1467
- maxReadSize;
1468
- linkCache;
1469
- statCache;
1470
- preservePaths;
1471
- cwd;
1472
- strict;
1473
- mtime;
1474
- noPax;
1475
- noMtime;
1476
- prefix;
1477
- fd;
1478
- blockLen = 0;
1479
- blockRemain = 0;
1480
- buf;
1481
- pos = 0;
1482
- remain = 0;
1483
- length = 0;
1484
- offset = 0;
1485
- win32;
1486
- absolute;
1487
- header;
1488
- type;
1489
- linkpath;
1490
- stat;
1491
- onWriteEntry;
1492
- #t = !1;
1493
- constructor(t, e = {}) {
1494
- let i = se(e);
1495
- super(), this.path = f$1(t), this.portable = !!i.portable, this.maxReadSize = i.maxReadSize || Bn, this.linkCache = i.linkCache || /* @__PURE__ */ new Map(), this.statCache = i.statCache || /* @__PURE__ */ new Map(), this.preservePaths = !!i.preservePaths, this.cwd = f$1(i.cwd || process.cwd()), this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.mtime = i.mtime, this.prefix = i.prefix ? f$1(i.prefix) : void 0, this.onWriteEntry = i.onWriteEntry, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
1496
- let r = !1;
1497
- if (!this.preservePaths) {
1498
- let [o, a] = le(this.path);
1499
- o && typeof a == "string" && (this.path = a, r = o);
1500
- }
1501
- this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = $s(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f$1(i.absolute || qs.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, {
1502
- entry: this,
1503
- path: r + this.path
1504
- });
1505
- let n = this.statCache.get(this.absolute);
1506
- n ? this[ii](n) : this[es]();
1507
- }
1508
- warn(t, e, i = {}) {
1509
- return Nt(this, t, e, i);
1510
- }
1511
- emit(t, ...e) {
1512
- return t === "error" && (this.#t = !0), super.emit(t, ...e);
1513
- }
1514
- [es]() {
1515
- I.lstat(this.absolute, (t, e) => {
1516
- if (t) return this.emit("error", t);
1517
- this[ii](e);
1518
- });
1519
- }
1520
- [ii](t) {
1521
- this.statCache.set(this.absolute, t), this.stat = t, t.isFile() || (t.size = 0), this.type = Pn(t), this.emit("stat", t), this[Qs]();
1522
- }
1523
- [Qs]() {
1524
- switch (this.type) {
1525
- case "File": return this[Js]();
1526
- case "Directory": return this[js]();
1527
- case "SymbolicLink": return this[ts]();
1528
- default: return this.end();
1529
- }
1530
- }
1531
- [si](t) {
1532
- return qi(t, this.type === "Directory", this.portable);
1533
- }
1534
- [X](t) {
1535
- return er(t, this.prefix);
1536
- }
1537
- [ce]() {
1538
- if (!this.stat) throw new Error("cannot write header before stat");
1539
- this.type === "Directory" && this.portable && (this.noMtime = !0), this.onWriteEntry?.(this), this.header = new C$1({
1540
- path: this[X](this.path),
1541
- linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[X](this.linkpath) : this.linkpath,
1542
- mode: this[si](this.stat.mode),
1543
- uid: this.portable ? void 0 : this.stat.uid,
1544
- gid: this.portable ? void 0 : this.stat.gid,
1545
- size: this.stat.size,
1546
- mtime: this.noMtime ? void 0 : this.mtime || this.stat.mtime,
1547
- type: this.type === "Unsupported" ? void 0 : this.type,
1548
- uname: this.portable ? void 0 : this.stat.uid === this.myuid ? this.myuser : "",
1549
- atime: this.portable ? void 0 : this.stat.atime,
1550
- ctime: this.portable ? void 0 : this.stat.ctime
1551
- }), this.header.encode() && !this.noPax && super.write(new ct({
1552
- atime: this.portable ? void 0 : this.header.atime,
1553
- ctime: this.portable ? void 0 : this.header.ctime,
1554
- gid: this.portable ? void 0 : this.header.gid,
1555
- mtime: this.noMtime ? void 0 : this.mtime || this.header.mtime,
1556
- path: this[X](this.path),
1557
- linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[X](this.linkpath) : this.linkpath,
1558
- size: this.header.size,
1559
- uid: this.portable ? void 0 : this.header.uid,
1560
- uname: this.portable ? void 0 : this.header.uname,
1561
- dev: this.portable ? void 0 : this.stat.dev,
1562
- ino: this.portable ? void 0 : this.stat.ino,
1563
- nlink: this.portable ? void 0 : this.stat.nlink
1564
- }).encode());
1565
- let t = this.header?.block;
1566
- if (!t) throw new Error("failed to encode header");
1567
- super.write(t);
1568
- }
1569
- [js]() {
1570
- if (!this.stat) throw new Error("cannot create directory entry without stat");
1571
- this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[ce](), this.end();
1572
- }
1573
- [ts]() {
1574
- I.readlink(this.absolute, (t, e) => {
1575
- if (t) return this.emit("error", t);
1576
- this[ss](e);
1577
- });
1578
- }
1579
- [ss](t) {
1580
- this.linkpath = f$1(t), this[ce](), this.end();
1581
- }
1582
- [tr](t) {
1583
- if (!this.stat) throw new Error("cannot create link entry without stat");
1584
- this.type = "Link", this.linkpath = f$1(qs.relative(this.cwd, t)), this.stat.size = 0, this[ce](), this.end();
1585
- }
1586
- [Js]() {
1587
- if (!this.stat) throw new Error("cannot create file entry without stat");
1588
- if (this.stat.nlink > 1) {
1589
- let t = `${this.stat.dev}:${this.stat.ino}`, e = this.linkCache.get(t);
1590
- if (e?.indexOf(this.cwd) === 0) return this[tr](e);
1591
- this.linkCache.set(t, this.absolute);
1592
- }
1593
- if (this[ce](), this.stat.size === 0) return this.end();
1594
- this[rs]();
1595
- }
1596
- [rs]() {
1597
- I.open(this.absolute, "r", (t, e) => {
1598
- if (t) return this.emit("error", t);
1599
- this[ns](e);
1600
- });
1601
- }
1602
- [ns](t) {
1603
- if (this.fd = t, this.#t) return this[pt]();
1604
- if (!this.stat) throw new Error("should stat before calling onopenfile");
1605
- this.blockLen = 512 * Math.ceil(this.stat.size / 512), this.blockRemain = this.blockLen;
1606
- let e = Math.min(this.blockLen, this.maxReadSize);
1607
- this.buf = Buffer.allocUnsafe(e), this.offset = 0, this.pos = 0, this.remain = this.stat.size, this.length = this.buf.length, this[ei]();
1608
- }
1609
- [ei]() {
1610
- let { fd: t, buf: e, offset: i, length: r, pos: n } = this;
1611
- if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening");
1612
- I.read(t, e, i, r, n, (o, a) => {
1613
- if (o) return this[pt](() => this.emit("error", o));
1614
- this[is](a);
1615
- });
1616
- }
1617
- [pt](t = () => {}) {
1618
- this.fd !== void 0 && I.close(this.fd, t);
1619
- }
1620
- [is](t) {
1621
- if (t <= 0 && this.remain > 0) {
1622
- let r = Object.assign(/* @__PURE__ */ new Error("encountered unexpected EOF"), {
1623
- path: this.absolute,
1624
- syscall: "read",
1625
- code: "EOF"
1626
- });
1627
- return this[pt](() => this.emit("error", r));
1628
- }
1629
- if (t > this.remain) {
1630
- let r = Object.assign(/* @__PURE__ */ new Error("did not encounter expected EOF"), {
1631
- path: this.absolute,
1632
- syscall: "read",
1633
- code: "EOF"
1634
- });
1635
- return this[pt](() => this.emit("error", r));
1636
- }
1637
- if (!this.buf) throw new Error("should have created buffer prior to reading");
1638
- if (t === this.remain) for (let r = t; r < this.length && t < this.blockRemain; r++) this.buf[r + this.offset] = 0, t++, this.remain++;
1639
- let e = this.offset === 0 && t === this.buf.length ? this.buf : this.buf.subarray(this.offset, this.offset + t);
1640
- this.write(e) ? this[ji]() : this[os](() => this[ji]());
1641
- }
1642
- [os](t) {
1643
- this.once("drain", t);
1644
- }
1645
- write(t, e, i) {
1646
- if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this.blockRemain < t.length) {
1647
- let r = Object.assign(/* @__PURE__ */ new Error("writing more data than expected"), { path: this.absolute });
1648
- return this.emit("error", r);
1649
- }
1650
- return this.remain -= t.length, this.blockRemain -= t.length, this.pos += t.length, this.offset += t.length, super.write(t, null, i);
1651
- }
1652
- [ji]() {
1653
- if (!this.remain) return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), this[pt]((t) => t ? this.emit("error", t) : this.end());
1654
- if (!this.buf) throw new Error("buffer lost somehow in ONDRAIN");
1655
- this.offset >= this.length && (this.buf = Buffer.allocUnsafe(Math.min(this.blockRemain, this.buf.length)), this.offset = 0), this.length = this.buf.length - this.offset, this[ei]();
1656
- }
1657
- }, ri = class extends fe {
1658
- sync = !0;
1659
- [es]() {
1660
- this[ii](I.lstatSync(this.absolute));
1661
- }
1662
- [ts]() {
1663
- this[ss](I.readlinkSync(this.absolute));
1664
- }
1665
- [rs]() {
1666
- this[ns](I.openSync(this.absolute, "r"));
1667
- }
1668
- [ei]() {
1669
- let t = !0;
1670
- try {
1671
- let { fd: e, buf: i, offset: r, length: n, pos: o } = this;
1672
- if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method");
1673
- let a = I.readSync(e, i, r, n, o);
1674
- this[is](a), t = !1;
1675
- } finally {
1676
- if (t) try {
1677
- this[pt](() => {});
1678
- } catch {}
1679
- }
1680
- }
1681
- [os](t) {
1682
- t();
1683
- }
1684
- [pt](t = () => {}) {
1685
- this.fd !== void 0 && I.closeSync(this.fd), t();
1686
- }
1687
- }, ni = class extends A$1 {
1688
- blockLen = 0;
1689
- blockRemain = 0;
1690
- buf = 0;
1691
- pos = 0;
1692
- remain = 0;
1693
- length = 0;
1694
- preservePaths;
1695
- portable;
1696
- strict;
1697
- noPax;
1698
- noMtime;
1699
- readEntry;
1700
- type;
1701
- prefix;
1702
- path;
1703
- mode;
1704
- uid;
1705
- gid;
1706
- uname;
1707
- gname;
1708
- header;
1709
- mtime;
1710
- atime;
1711
- ctime;
1712
- linkpath;
1713
- size;
1714
- onWriteEntry;
1715
- warn(t, e, i = {}) {
1716
- return Nt(this, t, e, i);
1717
- }
1718
- constructor(t, e = {}) {
1719
- let i = se(e);
1720
- super(), this.preservePaths = !!i.preservePaths, this.portable = !!i.portable, this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.onWriteEntry = i.onWriteEntry, this.readEntry = t;
1721
- let { type: r } = t;
1722
- if (r === "Unsupported") throw new Error("writing entry that should be ignored");
1723
- this.type = r, this.type === "Directory" && this.portable && (this.noMtime = !0), this.prefix = i.prefix, this.path = f$1(t.path), this.mode = t.mode !== void 0 ? this[si](t.mode) : void 0, this.uid = this.portable ? void 0 : t.uid, this.gid = this.portable ? void 0 : t.gid, this.uname = this.portable ? void 0 : t.uname, this.gname = this.portable ? void 0 : t.gname, this.size = t.size, this.mtime = this.noMtime ? void 0 : i.mtime || t.mtime, this.atime = this.portable ? void 0 : t.atime, this.ctime = this.portable ? void 0 : t.ctime, this.linkpath = t.linkpath !== void 0 ? f$1(t.linkpath) : void 0, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
1724
- let n = !1;
1725
- if (!this.preservePaths) {
1726
- let [a, h] = le(this.path);
1727
- a && typeof h == "string" && (this.path = h, n = a);
1728
- }
1729
- this.remain = t.size, this.blockRemain = t.startBlockSize, this.onWriteEntry?.(this), this.header = new C$1({
1730
- path: this[X](this.path),
1731
- linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[X](this.linkpath) : this.linkpath,
1732
- mode: this.mode,
1733
- uid: this.portable ? void 0 : this.uid,
1734
- gid: this.portable ? void 0 : this.gid,
1735
- size: this.size,
1736
- mtime: this.noMtime ? void 0 : this.mtime,
1737
- type: this.type,
1738
- uname: this.portable ? void 0 : this.uname,
1739
- atime: this.portable ? void 0 : this.atime,
1740
- ctime: this.portable ? void 0 : this.ctime
1741
- }), n && this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute path`, {
1742
- entry: this,
1743
- path: n + this.path
1744
- }), this.header.encode() && !this.noPax && super.write(new ct({
1745
- atime: this.portable ? void 0 : this.atime,
1746
- ctime: this.portable ? void 0 : this.ctime,
1747
- gid: this.portable ? void 0 : this.gid,
1748
- mtime: this.noMtime ? void 0 : this.mtime,
1749
- path: this[X](this.path),
1750
- linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[X](this.linkpath) : this.linkpath,
1751
- size: this.size,
1752
- uid: this.portable ? void 0 : this.uid,
1753
- uname: this.portable ? void 0 : this.uname,
1754
- dev: this.portable ? void 0 : this.readEntry.dev,
1755
- ino: this.portable ? void 0 : this.readEntry.ino,
1756
- nlink: this.portable ? void 0 : this.readEntry.nlink
1757
- }).encode());
1758
- let o = this.header?.block;
1759
- if (!o) throw new Error("failed to encode header");
1760
- super.write(o), t.pipe(this);
1761
- }
1762
- [X](t) {
1763
- return er(t, this.prefix);
1764
- }
1765
- [si](t) {
1766
- return qi(t, this.type === "Directory", this.portable);
1767
- }
1768
- write(t, e, i) {
1769
- typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8"));
1770
- let r = t.length;
1771
- if (r > this.blockRemain) throw new Error("writing more to entry than is appropriate");
1772
- return this.blockRemain -= r, super.write(t, i);
1773
- }
1774
- end(t, e, i) {
1775
- return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e ?? "utf8")), i && this.once("finish", i), t ? super.end(t, i) : super.end(i), this;
1776
- }
1777
- }, Pn = (s) => s.isFile() ? "File" : s.isDirectory() ? "Directory" : s.isSymbolicLink() ? "SymbolicLink" : "Unsupported";
1778
- var oi = class s {
1779
- tail;
1780
- head;
1781
- length = 0;
1782
- static create(t = []) {
1783
- return new s(t);
1784
- }
1785
- constructor(t = []) {
1786
- for (let e of t) this.push(e);
1787
- }
1788
- *[Symbol.iterator]() {
1789
- for (let t = this.head; t; t = t.next) yield t.value;
1790
- }
1791
- removeNode(t) {
1792
- if (t.list !== this) throw new Error("removing node which does not belong to this list");
1793
- let e = t.next, i = t.prev;
1794
- return e && (e.prev = i), i && (i.next = e), t === this.head && (this.head = e), t === this.tail && (this.tail = i), this.length--, t.next = void 0, t.prev = void 0, t.list = void 0, e;
1795
- }
1796
- unshiftNode(t) {
1797
- if (t === this.head) return;
1798
- t.list && t.list.removeNode(t);
1799
- let e = this.head;
1800
- t.list = this, t.next = e, e && (e.prev = t), this.head = t, this.tail || (this.tail = t), this.length++;
1801
- }
1802
- pushNode(t) {
1803
- if (t === this.tail) return;
1804
- t.list && t.list.removeNode(t);
1805
- let e = this.tail;
1806
- t.list = this, t.prev = e, e && (e.next = t), this.tail = t, this.head || (this.head = t), this.length++;
1807
- }
1808
- push(...t) {
1809
- for (let e = 0, i = t.length; e < i; e++) Un(this, t[e]);
1810
- return this.length;
1811
- }
1812
- unshift(...t) {
1813
- for (var e = 0, i = t.length; e < i; e++) Hn(this, t[e]);
1814
- return this.length;
1815
- }
1816
- pop() {
1817
- if (!this.tail) return;
1818
- let t = this.tail.value, e = this.tail;
1819
- return this.tail = this.tail.prev, this.tail ? this.tail.next = void 0 : this.head = void 0, e.list = void 0, this.length--, t;
1820
- }
1821
- shift() {
1822
- if (!this.head) return;
1823
- let t = this.head.value, e = this.head;
1824
- return this.head = this.head.next, this.head ? this.head.prev = void 0 : this.tail = void 0, e.list = void 0, this.length--, t;
1825
- }
1826
- forEach(t, e) {
1827
- e = e || this;
1828
- for (let i = this.head, r = 0; i; r++) t.call(e, i.value, r, this), i = i.next;
1829
- }
1830
- forEachReverse(t, e) {
1831
- e = e || this;
1832
- for (let i = this.tail, r = this.length - 1; i; r--) t.call(e, i.value, r, this), i = i.prev;
1833
- }
1834
- get(t) {
1835
- let e = 0, i = this.head;
1836
- for (; i && e < t; e++) i = i.next;
1837
- if (e === t && i) return i.value;
1838
- }
1839
- getReverse(t) {
1840
- let e = 0, i = this.tail;
1841
- for (; i && e < t; e++) i = i.prev;
1842
- if (e === t && i) return i.value;
1843
- }
1844
- map(t, e) {
1845
- e = e || this;
1846
- let i = new s();
1847
- for (let r = this.head; r;) i.push(t.call(e, r.value, this)), r = r.next;
1848
- return i;
1849
- }
1850
- mapReverse(t, e) {
1851
- e = e || this;
1852
- var i = new s();
1853
- for (let r = this.tail; r;) i.push(t.call(e, r.value, this)), r = r.prev;
1854
- return i;
1855
- }
1856
- reduce(t, e) {
1857
- let i, r = this.head;
1858
- if (arguments.length > 1) i = e;
1859
- else if (this.head) r = this.head.next, i = this.head.value;
1860
- else throw new TypeError("Reduce of empty list with no initial value");
1861
- for (var n = 0; r; n++) i = t(i, r.value, n), r = r.next;
1862
- return i;
1863
- }
1864
- reduceReverse(t, e) {
1865
- let i, r = this.tail;
1866
- if (arguments.length > 1) i = e;
1867
- else if (this.tail) r = this.tail.prev, i = this.tail.value;
1868
- else throw new TypeError("Reduce of empty list with no initial value");
1869
- for (let n = this.length - 1; r; n--) i = t(i, r.value, n), r = r.prev;
1870
- return i;
1871
- }
1872
- toArray() {
1873
- let t = new Array(this.length);
1874
- for (let e = 0, i = this.head; i; e++) t[e] = i.value, i = i.next;
1875
- return t;
1876
- }
1877
- toArrayReverse() {
1878
- let t = new Array(this.length);
1879
- for (let e = 0, i = this.tail; i; e++) t[e] = i.value, i = i.prev;
1880
- return t;
1881
- }
1882
- slice(t = 0, e = this.length) {
1883
- e < 0 && (e += this.length), t < 0 && (t += this.length);
1884
- let i = new s();
1885
- if (e < t || e < 0) return i;
1886
- t < 0 && (t = 0), e > this.length && (e = this.length);
1887
- let r = this.head, n = 0;
1888
- for (n = 0; r && n < t; n++) r = r.next;
1889
- for (; r && n < e; n++, r = r.next) i.push(r.value);
1890
- return i;
1891
- }
1892
- sliceReverse(t = 0, e = this.length) {
1893
- e < 0 && (e += this.length), t < 0 && (t += this.length);
1894
- let i = new s();
1895
- if (e < t || e < 0) return i;
1896
- t < 0 && (t = 0), e > this.length && (e = this.length);
1897
- let r = this.length, n = this.tail;
1898
- for (; n && r > e; r--) n = n.prev;
1899
- for (; n && r > t; r--, n = n.prev) i.push(n.value);
1900
- return i;
1901
- }
1902
- splice(t, e = 0, ...i) {
1903
- t > this.length && (t = this.length - 1), t < 0 && (t = this.length + t);
1904
- let r = this.head;
1905
- for (let o = 0; r && o < t; o++) r = r.next;
1906
- let n = [];
1907
- for (let o = 0; r && o < e; o++) n.push(r.value), r = this.removeNode(r);
1908
- r ? r !== this.tail && (r = r.prev) : r = this.tail;
1909
- for (let o of i) r = zn(this, r, o);
1910
- return n;
1911
- }
1912
- reverse() {
1913
- let t = this.head, e = this.tail;
1914
- for (let i = t; i; i = i.prev) {
1915
- let r = i.prev;
1916
- i.prev = i.next, i.next = r;
1917
- }
1918
- return this.head = e, this.tail = t, this;
1919
- }
1920
- };
1921
- function zn(s, t, e) {
1922
- let n = new de(e, t, t ? t.next : s.head, s);
1923
- return n.next === void 0 && (s.tail = n), n.prev === void 0 && (s.head = n), s.length++, n;
1924
- }
1925
- function Un(s, t) {
1926
- s.tail = new de(t, s.tail, void 0, s), s.head || (s.head = s.tail), s.length++;
1927
- }
1928
- function Hn(s, t) {
1929
- s.head = new de(t, void 0, s.head, s), s.tail || (s.tail = s.head), s.length++;
1930
- }
1931
- var de = class {
1932
- list;
1933
- next;
1934
- prev;
1935
- value;
1936
- constructor(t, e, i, r) {
1937
- this.list = r, this.value = t, e ? (e.next = this, this.prev = e) : this.prev = void 0, i ? (i.prev = this, this.next = i) : this.next = void 0;
1938
- }
1939
- };
1940
- var mi = class {
1941
- path;
1942
- absolute;
1943
- entry;
1944
- stat;
1945
- readdir;
1946
- pending = !1;
1947
- pendingLink = !1;
1948
- ignore = !1;
1949
- piped = !1;
1950
- constructor(t, e) {
1951
- this.path = t || "./", this.absolute = e;
1952
- }
1953
- }, ir = Buffer.alloc(1024), ai = Symbol("onStat"), ue = Symbol("ended"), W$1 = Symbol("queue"), me = Symbol("pendingLinks"), Et = Symbol("current"), Ct = Symbol("process"), pe = Symbol("processing"), hi = Symbol("processJob"), G = Symbol("jobs"), hs = Symbol("jobDone"), li = Symbol("addFSEntry"), sr = Symbol("addTarEntry"), cs = Symbol("stat"), fs$1 = Symbol("readdir"), ci = Symbol("onreaddir"), fi = Symbol("pipe"), rr = Symbol("entry"), as = Symbol("entryOpt"), di = Symbol("writeEntryClass"), or = Symbol("write"), ls = Symbol("ondrain"), wt = class extends A$1 {
1954
- sync = !1;
1955
- opt;
1956
- cwd;
1957
- maxReadSize;
1958
- preservePaths;
1959
- strict;
1960
- noPax;
1961
- prefix;
1962
- linkCache;
1963
- statCache;
1964
- file;
1965
- portable;
1966
- zip;
1967
- readdirCache;
1968
- noDirRecurse;
1969
- follow;
1970
- noMtime;
1971
- mtime;
1972
- filter;
1973
- jobs;
1974
- [di];
1975
- onWriteEntry;
1976
- [W$1];
1977
- [me] = /* @__PURE__ */ new Map();
1978
- [G] = 0;
1979
- [pe] = !1;
1980
- [ue] = !1;
1981
- constructor(t = {}) {
1982
- if (super(), this.opt = t, this.file = t.file || "", this.cwd = t.cwd || process.cwd(), this.maxReadSize = t.maxReadSize, this.preservePaths = !!t.preservePaths, this.strict = !!t.strict, this.noPax = !!t.noPax, this.prefix = f$1(t.prefix || ""), this.linkCache = t.linkCache || /* @__PURE__ */ new Map(), this.statCache = t.statCache || /* @__PURE__ */ new Map(), this.readdirCache = t.readdirCache || /* @__PURE__ */ new Map(), this.onWriteEntry = t.onWriteEntry, this[di] = fe, typeof t.onwarn == "function" && this.on("warn", t.onwarn), this.portable = !!t.portable, t.gzip || t.brotli || t.zstd) {
1983
- if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
1984
- if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = !0), this.zip = new Pe(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new He(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ze(t.zstd)), !this.zip) throw new Error("impossible");
1985
- let e = this.zip;
1986
- e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[ls]()), this.on("resume", () => e.resume());
1987
- } else this.on("drain", this[ls]);
1988
- this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => !0, this[W$1] = new oi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[pe] = !1, this[ue] = !1;
1989
- }
1990
- [or](t) {
1991
- return super.write(t);
1992
- }
1993
- add(t) {
1994
- return this.write(t), this;
1995
- }
1996
- end(t, e, i) {
1997
- return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = void 0), t && this.add(t), this[ue] = !0, this[Ct](), i && i(), this;
1998
- }
1999
- write(t) {
2000
- if (this[ue]) throw new Error("write after end");
2001
- return typeof t == "string" ? this[li](t) : this[sr](t), this.flowing;
2002
- }
2003
- [sr](t) {
2004
- let e = f$1(qs.resolve(this.cwd, t.path));
2005
- if (!this.filter(t.path, t)) t.resume();
2006
- else {
2007
- let i = new mi(t.path, e);
2008
- i.entry = new ni(t, this[as](i)), i.entry.on("end", () => this[hs](i)), this[G] += 1, this[W$1].push(i);
2009
- }
2010
- this[Ct]();
2011
- }
2012
- [li](t) {
2013
- let e = f$1(qs.resolve(this.cwd, t));
2014
- this[W$1].push(new mi(t, e)), this[Ct]();
2015
- }
2016
- [cs](t) {
2017
- t.pending = !0, this[G] += 1;
2018
- I[this.follow ? "stat" : "lstat"](t.absolute, (i, r) => {
2019
- t.pending = !1, this[G] -= 1, i ? this.emit("error", i) : this[ai](t, r);
2020
- });
2021
- }
2022
- [ai](t, e) {
2023
- if (this.statCache.set(t.absolute, e), t.stat = e, !this.filter(t.path, e)) t.ignore = !0;
2024
- else if (e.isFile() && e.nlink > 1 && !this.linkCache.get(`${e.dev}:${e.ino}`) && !this.sync) if (t === this[Et]) this[hi](t);
2025
- else {
2026
- let i = `${e.dev}:${e.ino}`, r = this[me].get(i);
2027
- r ? r.push(t) : this[me].set(i, [t]), t.pendingLink = !0, t.pending = !0;
2028
- }
2029
- this[Ct]();
2030
- }
2031
- [fs$1](t) {
2032
- t.pending = !0, this[G] += 1, I.readdir(t.absolute, (e, i) => {
2033
- if (t.pending = !1, this[G] -= 1, e) return this.emit("error", e);
2034
- this[ci](t, i);
2035
- });
2036
- }
2037
- [ci](t, e) {
2038
- this.readdirCache.set(t.absolute, e), t.readdir = e, this[Ct]();
2039
- }
2040
- [Ct]() {
2041
- if (!this[pe]) {
2042
- this[pe] = !0;
2043
- for (let t = this[W$1].head; t && this[G] < this.jobs; t = t.next) if (this[hi](t.value), t.value.ignore) {
2044
- let e = t.next;
2045
- this[W$1].removeNode(t), t.next = e;
2046
- }
2047
- this[pe] = !1, this[ue] && this[W$1].length === 0 && this[G] === 0 && (this.zip ? this.zip.end(ir) : (super.write(ir), super.end()));
2048
- }
2049
- }
2050
- get [Et]() {
2051
- return this[W$1] && this[W$1].head && this[W$1].head.value;
2052
- }
2053
- [hs](t) {
2054
- this[W$1].shift(), this[G] -= 1;
2055
- let { stat: e } = t;
2056
- if (e && e.isFile() && e.nlink > 1) {
2057
- let i = `${e.dev}:${e.ino}`, r = this[me].get(i);
2058
- if (r) {
2059
- this[me].delete(i);
2060
- for (let n of r) n.pending = !1, this[hi](n);
2061
- }
2062
- }
2063
- this[Ct]();
2064
- }
2065
- [hi](t) {
2066
- if (t.pending && t.pendingLink && t === this[Et] && (t.pending = !1, t.pendingLink = !1), !t.pending) {
2067
- if (t.entry) {
2068
- t === this[Et] && !t.piped && this[fi](t);
2069
- return;
2070
- }
2071
- if (!t.stat) {
2072
- let e = this.statCache.get(t.absolute);
2073
- e ? this[ai](t, e) : this[cs](t);
2074
- }
2075
- if (t.stat && !t.ignore) {
2076
- if (!this.noDirRecurse && t.stat.isDirectory() && !t.readdir) {
2077
- let e = this.readdirCache.get(t.absolute);
2078
- if (e ? this[ci](t, e) : this[fs$1](t), !t.readdir) return;
2079
- }
2080
- if (t.entry = this[rr](t), !t.entry) {
2081
- t.ignore = !0;
2082
- return;
2083
- }
2084
- t === this[Et] && !t.piped && this[fi](t);
2085
- }
2086
- }
2087
- }
2088
- [as](t) {
2089
- return {
2090
- onwarn: (e, i, r) => this.warn(e, i, r),
2091
- noPax: this.noPax,
2092
- cwd: this.cwd,
2093
- absolute: t.absolute,
2094
- preservePaths: this.preservePaths,
2095
- maxReadSize: this.maxReadSize,
2096
- strict: this.strict,
2097
- portable: this.portable,
2098
- linkCache: this.linkCache,
2099
- statCache: this.statCache,
2100
- noMtime: this.noMtime,
2101
- mtime: this.mtime,
2102
- prefix: this.prefix,
2103
- onWriteEntry: this.onWriteEntry
2104
- };
2105
- }
2106
- [rr](t) {
2107
- this[G] += 1;
2108
- try {
2109
- return new this[di](t.path, this[as](t)).on("end", () => this[hs](t)).on("error", (i) => this.emit("error", i));
2110
- } catch (e) {
2111
- this.emit("error", e);
2112
- }
2113
- }
2114
- [ls]() {
2115
- this[Et] && this[Et].entry && this[Et].entry.resume();
2116
- }
2117
- [fi](t) {
2118
- t.piped = !0, t.readdir && t.readdir.forEach((r) => {
2119
- let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
2120
- this[li](o + r);
2121
- });
2122
- let e = t.entry, i = this.zip;
2123
- if (!e) throw new Error("cannot pipe without source");
2124
- i ? e.on("data", (r) => {
2125
- i.write(r) || e.pause();
2126
- }) : e.on("data", (r) => {
2127
- super.write(r) || e.pause();
2128
- });
2129
- }
2130
- pause() {
2131
- return this.zip && this.zip.pause(), super.pause();
2132
- }
2133
- warn(t, e, i = {}) {
2134
- Nt(this, t, e, i);
2135
- }
2136
- }, kt = class extends wt {
2137
- sync = !0;
2138
- constructor(t) {
2139
- super(t), this[di] = ri;
2140
- }
2141
- pause() {}
2142
- resume() {}
2143
- [cs](t) {
2144
- let e = this.follow ? "statSync" : "lstatSync";
2145
- this[ai](t, I[e](t.absolute));
2146
- }
2147
- [fs$1](t) {
2148
- this[ci](t, I.readdirSync(t.absolute));
2149
- }
2150
- [fi](t) {
2151
- let e = t.entry, i = this.zip;
2152
- if (t.readdir && t.readdir.forEach((r) => {
2153
- let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
2154
- this[li](o + r);
2155
- }), !e) throw new Error("Cannot pipe without source");
2156
- i ? e.on("data", (r) => {
2157
- i.write(r);
2158
- }) : e.on("data", (r) => {
2159
- super[or](r);
2160
- });
2161
- }
2162
- };
2163
- var Wn = (s, t) => {
2164
- let e = new kt(s), i = new Wt(s.file, { mode: s.mode || 438 });
2165
- e.pipe(i), ar(e, t);
2166
- }, Gn = (s, t) => {
2167
- let e = new wt(s), i = new tt(s.file, { mode: s.mode || 438 });
2168
- e.pipe(i);
2169
- let r = new Promise((n, o) => {
2170
- i.on("error", o), i.on("close", n), e.on("error", o);
2171
- });
2172
- return lr(e, t).catch((n) => e.emit("error", n)), r;
2173
- }, ar = (s, t) => {
2174
- t.forEach((e) => {
2175
- e.charAt(0) === "@" ? Ft({
2176
- file: path.resolve(s.cwd, e.slice(1)),
2177
- sync: !0,
2178
- noResume: !0,
2179
- onReadEntry: (i) => s.add(i)
2180
- }) : s.add(e);
2181
- }), s.end();
2182
- }, lr = async (s, t) => {
2183
- for (let e of t) e.charAt(0) === "@" ? await Ft({
2184
- file: path.resolve(String(s.cwd), e.slice(1)),
2185
- noResume: !0,
2186
- onReadEntry: (i) => {
2187
- s.add(i);
2188
- }
2189
- }) : s.add(e);
2190
- s.end();
2191
- }, Zn = (s, t) => {
2192
- let e = new kt(s);
2193
- return ar(e, t), e;
2194
- }, Yn = (s, t) => {
2195
- let e = new wt(s);
2196
- return lr(e, t).catch((i) => e.emit("error", i)), e;
2197
- }, Kn = K(Wn, Gn, Zn, Yn, (s, t) => {
2198
- if (!t?.length) throw new TypeError("no paths specified to add to archive");
2199
- });
2200
- var ur = (process.env.__FAKE_PLATFORM__ || process.platform) === "win32", { O_CREAT: mr, O_NOFOLLOW: cr, O_TRUNC: pr, O_WRONLY: Er } = I.constants, wr = Number(process.env.__FAKE_FS_O_FILENAME__) || I.constants.UV_FS_O_FILEMAP || 0, $n = ur && !!wr, Xn = 512 * 1024, qn = wr | pr | mr | Er, fr = !ur && typeof cr == "number" ? cr | pr | mr | Er : null, ds = fr !== null ? () => fr : $n ? (s) => s < Xn ? qn : "w" : () => "w";
2201
- var us = (s, t, e) => {
2202
- try {
2203
- return Kt.lchownSync(s, t, e);
2204
- } catch (i) {
2205
- if (i?.code !== "ENOENT") throw i;
2206
- }
2207
- }, pi = (s, t, e, i) => {
2208
- Kt.lchown(s, t, e, (r) => {
2209
- i(r && r?.code !== "ENOENT" ? r : null);
2210
- });
2211
- }, Qn = (s, t, e, i, r) => {
2212
- if (t.isDirectory()) ms(path.resolve(s, t.name), e, i, (n) => {
2213
- if (n) return r(n);
2214
- pi(path.resolve(s, t.name), e, i, r);
2215
- });
2216
- else pi(path.resolve(s, t.name), e, i, r);
2217
- }, ms = (s, t, e, i) => {
2218
- Kt.readdir(s, { withFileTypes: !0 }, (r, n) => {
2219
- if (r) {
2220
- if (r.code === "ENOENT") return i();
2221
- if (r.code !== "ENOTDIR" && r.code !== "ENOTSUP") return i(r);
2222
- }
2223
- if (r || !n.length) return pi(s, t, e, i);
2224
- let o = n.length, a = null, h = (l) => {
2225
- if (!a) {
2226
- if (l) return i(a = l);
2227
- if (--o === 0) return pi(s, t, e, i);
2228
- }
2229
- };
2230
- for (let l of n) Qn(s, l, t, e, h);
2231
- });
2232
- }, Jn = (s, t, e, i) => {
2233
- t.isDirectory() && ps(path.resolve(s, t.name), e, i), us(path.resolve(s, t.name), e, i);
2234
- }, ps = (s, t, e) => {
2235
- let i;
2236
- try {
2237
- i = Kt.readdirSync(s, { withFileTypes: !0 });
2238
- } catch (r) {
2239
- let n = r;
2240
- if (n?.code === "ENOENT") return;
2241
- if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return us(s, t, e);
2242
- throw n;
2243
- }
2244
- for (let r of i) Jn(s, r, t, e);
2245
- return us(s, t, e);
2246
- };
2247
- var we = class extends Error {
2248
- path;
2249
- code;
2250
- syscall = "chdir";
2251
- constructor(t, e) {
2252
- super(`${e}: Cannot cd into '${t}'`), this.path = t, this.code = e;
2253
- }
2254
- get name() {
2255
- return "CwdError";
2256
- }
2257
- };
2258
- var St = class extends Error {
2259
- path;
2260
- symlink;
2261
- syscall = "symlink";
2262
- code = "TAR_SYMLINK_ERROR";
2263
- constructor(t, e) {
2264
- super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"), this.symlink = t, this.path = e;
2265
- }
2266
- get name() {
2267
- return "SymlinkError";
2268
- }
2269
- };
2270
- var to = (s, t) => {
2271
- Kt.stat(s, (e, i) => {
2272
- (e || !i.isDirectory()) && (e = new we(s, e?.code || "ENOTDIR")), t(e);
2273
- });
2274
- }, Sr = (s, t, e) => {
2275
- s = f$1(s);
2276
- let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, a = t.gid, h = typeof o == "number" && typeof a == "number" && (o !== t.processUid || a !== t.processGid), l = t.preserve, c = t.unlink, d = f$1(t.cwd), S = (E, x) => {
2277
- E ? e(E) : x && h ? ms(x, o, a, (xe) => S(xe)) : n ? Kt.chmod(s, r, e) : e();
2278
- };
2279
- if (s === d) return to(s, S);
2280
- if (l) return jn.mkdir(s, {
2281
- mode: r,
2282
- recursive: !0
2283
- }).then((E) => S(null, E ?? void 0), S);
2284
- Es(d, f$1(path.relative(d, s)).split("/"), r, c, d, void 0, S);
2285
- }, Es = (s, t, e, i, r, n, o) => {
2286
- if (t.length === 0) return o(null, n);
2287
- let a = t.shift(), h = f$1(path.resolve(s + "/" + a));
2288
- Kt.mkdir(h, e, yr(h, t, e, i, r, n, o));
2289
- }, yr = (s, t, e, i, r, n, o) => (a) => {
2290
- a ? Kt.lstat(s, (h, l) => {
2291
- if (h) h.path = h.path && f$1(h.path), o(h);
2292
- else if (l.isDirectory()) Es(s, t, e, i, r, n, o);
2293
- else if (i) Kt.unlink(s, (c) => {
2294
- if (c) return o(c);
2295
- Kt.mkdir(s, e, yr(s, t, e, i, r, n, o));
2296
- });
2297
- else {
2298
- if (l.isSymbolicLink()) return o(new St(s, s + "/" + t.join("/")));
2299
- o(a);
2300
- }
2301
- }) : (n = n || s, Es(s, t, e, i, r, n, o));
2302
- }, eo = (s) => {
2303
- let t = !1, e;
2304
- try {
2305
- t = Kt.statSync(s).isDirectory();
2306
- } catch (i) {
2307
- e = i?.code;
2308
- } finally {
2309
- if (!t) throw new we(s, e ?? "ENOTDIR");
2310
- }
2311
- }, Rr = (s, t) => {
2312
- s = f$1(s);
2313
- let e = t.umask ?? 18, i = t.mode | 448, r = (i & e) !== 0, n = t.uid, o = t.gid, a = typeof n == "number" && typeof o == "number" && (n !== t.processUid || o !== t.processGid), h = t.preserve, l = t.unlink, c = f$1(t.cwd), d = (E) => {
2314
- E && a && ps(E, n, o), r && Kt.chmodSync(s, i);
2315
- };
2316
- if (s === c) return eo(c), d();
2317
- if (h) return d(Kt.mkdirSync(s, {
2318
- mode: i,
2319
- recursive: !0
2320
- }) ?? void 0);
2321
- let T = f$1(path.relative(c, s)).split("/"), N;
2322
- for (let E = T.shift(), x = c; E && (x += "/" + E); E = T.shift()) {
2323
- x = f$1(path.resolve(x));
2324
- try {
2325
- Kt.mkdirSync(x, i), N = N || x;
2326
- } catch {
2327
- let xe = Kt.lstatSync(x);
2328
- if (xe.isDirectory()) continue;
2329
- if (l) {
2330
- Kt.unlinkSync(x), Kt.mkdirSync(x, i), N = N || x;
2331
- continue;
2332
- } else if (xe.isSymbolicLink()) return new St(x, x + "/" + T.join("/"));
2333
- }
2334
- }
2335
- return d(N);
2336
- };
2337
- var ws = Object.create(null), gr = 1e4, Vt = /* @__PURE__ */ new Set(), br = (s) => {
2338
- Vt.has(s) ? Vt.delete(s) : ws[s] = s.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"), Vt.add(s);
2339
- let t = ws[s], e = Vt.size - gr;
2340
- if (e > gr / 10) {
2341
- for (let i of Vt) if (Vt.delete(i), delete ws[i], --e <= 0) break;
2342
- }
2343
- return t;
2344
- };
2345
- var so = (process.env.TESTING_TAR_FAKE_PLATFORM || process.platform) === "win32", ro = (s) => s.split("/").slice(0, -1).reduce((e, i) => {
2346
- let r = e.at(-1);
2347
- return r !== void 0 && (i = join(r, i)), e.push(i || "/"), e;
2348
- }, []), Si = class {
2349
- #t = /* @__PURE__ */ new Map();
2350
- #i = /* @__PURE__ */ new Map();
2351
- #s = /* @__PURE__ */ new Set();
2352
- reserve(t, e) {
2353
- t = so ? ["win32 parallelization disabled"] : t.map((r) => mt(join(br(r))));
2354
- let i = new Set(t.map((r) => ro(r)).reduce((r, n) => r.concat(n)));
2355
- this.#i.set(e, {
2356
- dirs: i,
2357
- paths: t
2358
- });
2359
- for (let r of t) {
2360
- let n = this.#t.get(r);
2361
- n ? n.push(e) : this.#t.set(r, [e]);
2362
- }
2363
- for (let r of i) {
2364
- let n = this.#t.get(r);
2365
- if (!n) this.#t.set(r, [new Set([e])]);
2366
- else {
2367
- let o = n.at(-1);
2368
- o instanceof Set ? o.add(e) : n.push(new Set([e]));
2369
- }
2370
- }
2371
- return this.#r(e);
2372
- }
2373
- #n(t) {
2374
- let e = this.#i.get(t);
2375
- if (!e) throw new Error("function does not have any path reservations");
2376
- return {
2377
- paths: e.paths.map((i) => this.#t.get(i)),
2378
- dirs: [...e.dirs].map((i) => this.#t.get(i))
2379
- };
2380
- }
2381
- check(t) {
2382
- let { paths: e, dirs: i } = this.#n(t);
2383
- return e.every((r) => r && r[0] === t) && i.every((r) => r && r[0] instanceof Set && r[0].has(t));
2384
- }
2385
- #r(t) {
2386
- return this.#s.has(t) || !this.check(t) ? !1 : (this.#s.add(t), t(() => this.#e(t)), !0);
2387
- }
2388
- #e(t) {
2389
- if (!this.#s.has(t)) return !1;
2390
- let e = this.#i.get(t);
2391
- if (!e) throw new Error("invalid reservation");
2392
- let { paths: i, dirs: r } = e, n = /* @__PURE__ */ new Set();
2393
- for (let o of i) {
2394
- let a = this.#t.get(o);
2395
- if (!a || a?.[0] !== t) continue;
2396
- let h = a[1];
2397
- if (!h) {
2398
- this.#t.delete(o);
2399
- continue;
2400
- }
2401
- if (a.shift(), typeof h == "function") n.add(h);
2402
- else for (let l of h) n.add(l);
2403
- }
2404
- for (let o of r) {
2405
- let a = this.#t.get(o), h = a?.[0];
2406
- if (!(!a || !(h instanceof Set))) if (h.size === 1 && a.length === 1) {
2407
- this.#t.delete(o);
2408
- continue;
2409
- } else if (h.size === 1) {
2410
- a.shift();
2411
- let l = a[0];
2412
- typeof l == "function" && n.add(l);
2413
- } else h.delete(t);
2414
- }
2415
- return this.#s.delete(t), n.forEach((o) => this.#r(o)), !0;
2416
- }
2417
- };
2418
- var Or = () => process.umask();
2419
- var Tr = Symbol("onEntry"), gs = Symbol("checkFs"), xr = Symbol("checkFs2"), bs = Symbol("isReusable"), P$1 = Symbol("makeFs"), _s = Symbol("file"), Os = Symbol("directory"), Ri = Symbol("link"), Lr = Symbol("symlink"), Nr = Symbol("hardlink"), ye = Symbol("ensureNoSymlink"), Dr = Symbol("unsupported"), Ar = Symbol("checkPath"), Ss = Symbol("stripAbsolutePath"), yt = Symbol("mkdir"), O$1 = Symbol("onError"), yi = Symbol("pending"), Ir = Symbol("pend"), $t = Symbol("unpend"), ys = Symbol("ended"), Rs = Symbol("maybeClose"), Ts = Symbol("skip"), Re = Symbol("doChown"), ge = Symbol("uid"), be = Symbol("gid"), _e = Symbol("checkedCwd"), Oe = (process.env.TESTING_TAR_FAKE_PLATFORM || process.platform) === "win32", ho = 1024, ao = (s, t) => {
2420
- if (!Oe) return Kt.unlink(s, t);
2421
- let e = s + ".DELETE." + randomBytes(16).toString("hex");
2422
- Kt.rename(s, e, (i) => {
2423
- if (i) return t(i);
2424
- Kt.unlink(e, t);
2425
- });
2426
- }, lo = (s) => {
2427
- if (!Oe) return Kt.unlinkSync(s);
2428
- let t = s + ".DELETE." + randomBytes(16).toString("hex");
2429
- Kt.renameSync(s, t), Kt.unlinkSync(t);
2430
- }, Fr = (s, t, e) => s !== void 0 && s === s >>> 0 ? s : t !== void 0 && t === t >>> 0 ? t : e, Xt = class extends st {
2431
- [ys] = !1;
2432
- [_e] = !1;
2433
- [yi] = 0;
2434
- reservations = new Si();
2435
- transform;
2436
- writable = !0;
2437
- readable = !1;
2438
- uid;
2439
- gid;
2440
- setOwner;
2441
- preserveOwner;
2442
- processGid;
2443
- processUid;
2444
- maxDepth;
2445
- forceChown;
2446
- win32;
2447
- newer;
2448
- keep;
2449
- noMtime;
2450
- preservePaths;
2451
- unlink;
2452
- cwd;
2453
- strip;
2454
- processUmask;
2455
- umask;
2456
- dmode;
2457
- fmode;
2458
- chmod;
2459
- constructor(t = {}) {
2460
- if (t.ondone = () => {
2461
- this[ys] = !0, this[Rs]();
2462
- }, super(t), this.transform = t.transform, this.chmod = !!t.chmod, typeof t.uid == "number" || typeof t.gid == "number") {
2463
- if (typeof t.uid != "number" || typeof t.gid != "number") throw new TypeError("cannot set owner without number uid and gid");
2464
- if (t.preserveOwner) throw new TypeError("cannot preserve owner in archive and also set owner explicitly");
2465
- this.uid = t.uid, this.gid = t.gid, this.setOwner = !0;
2466
- } else this.uid = void 0, this.gid = void 0, this.setOwner = !1;
2467
- this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? !!(process.getuid && process.getuid() === 0) : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : ho, this.forceChown = t.forceChown === !0, this.win32 = !!t.win32 || Oe, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f$1(path.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : Or() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Tr](e));
2468
- }
2469
- warn(t, e, i = {}) {
2470
- return (t === "TAR_BAD_ARCHIVE" || t === "TAR_ABORT") && (i.recoverable = !1), super.warn(t, e, i);
2471
- }
2472
- [Rs]() {
2473
- this[ys] && this[yi] === 0 && (this.emit("prefinish"), this.emit("finish"), this.emit("end"));
2474
- }
2475
- [Ss](t, e) {
2476
- let i = t[e], { type: r } = t;
2477
- if (!i || this.preservePaths) return !0;
2478
- let [n, o] = le(i), a = o.replaceAll(/\\/g, "/").split("/");
2479
- if (a.includes("..") || Oe && /^[a-z]:\.\.$/i.test(a[0] ?? "")) {
2480
- if (e === "path" || r === "Link") return this.warn("TAR_ENTRY_ERROR", `${e} contains '..'`, {
2481
- entry: t,
2482
- [e]: i
2483
- }), !1;
2484
- let h = path.posix.dirname(t.path), l = path.posix.normalize(path.posix.join(h, a.join("/")));
2485
- if (l.startsWith("../") || l === "..") return this.warn("TAR_ENTRY_ERROR", `${e} escapes extraction directory`, {
2486
- entry: t,
2487
- [e]: i
2488
- }), !1;
2489
- }
2490
- return n && (t[e] = String(o), this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute ${e}`, {
2491
- entry: t,
2492
- [e]: i
2493
- })), !0;
2494
- }
2495
- [Ar](t) {
2496
- let e = f$1(t.path), i = e.split("/");
2497
- if (this.strip) {
2498
- if (i.length < this.strip) return !1;
2499
- if (t.type === "Link") {
2500
- let r = f$1(String(t.linkpath)).split("/");
2501
- if (r.length >= this.strip) t.linkpath = r.slice(this.strip).join("/");
2502
- else return !1;
2503
- }
2504
- i.splice(0, this.strip), t.path = i.join("/");
2505
- }
2506
- if (isFinite(this.maxDepth) && i.length > this.maxDepth) return this.warn("TAR_ENTRY_ERROR", "path excessively deep", {
2507
- entry: t,
2508
- path: e,
2509
- depth: i.length,
2510
- maxDepth: this.maxDepth
2511
- }), !1;
2512
- if (!this[Ss](t, "path") || !this[Ss](t, "linkpath")) return !1;
2513
- if (t.absolute = path.isAbsolute(t.path) ? f$1(path.resolve(t.path)) : f$1(path.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", {
2514
- entry: t,
2515
- path: f$1(t.path),
2516
- resolvedPath: t.absolute,
2517
- cwd: this.cwd
2518
- }), !1;
2519
- if (t.absolute === this.cwd && t.type !== "Directory" && t.type !== "GNUDumpDir") return !1;
2520
- if (this.win32) {
2521
- let { root: r } = path.win32.parse(String(t.absolute));
2522
- t.absolute = r + Ji(String(t.absolute).slice(r.length));
2523
- let { root: n } = path.win32.parse(t.path);
2524
- t.path = n + Ji(t.path.slice(n.length));
2525
- }
2526
- return !0;
2527
- }
2528
- [Tr](t) {
2529
- if (!this[Ar](t)) return t.resume();
2530
- switch (no.equal(typeof t.absolute, "string"), t.type) {
2531
- case "Directory":
2532
- case "GNUDumpDir": t.mode && (t.mode = t.mode | 448);
2533
- case "File":
2534
- case "OldFile":
2535
- case "ContiguousFile":
2536
- case "Link":
2537
- case "SymbolicLink": return this[gs](t);
2538
- default: return this[Dr](t);
2539
- }
2540
- }
2541
- [O$1](t, e) {
2542
- t.name === "CwdError" ? this.emit("error", t) : (this.warn("TAR_ENTRY_ERROR", t, { entry: e }), this[$t](), e.resume());
2543
- }
2544
- [yt](t, e, i) {
2545
- Sr(f$1(t), {
2546
- uid: this.uid,
2547
- gid: this.gid,
2548
- processUid: this.processUid,
2549
- processGid: this.processGid,
2550
- umask: this.processUmask,
2551
- preserve: this.preservePaths,
2552
- unlink: this.unlink,
2553
- cwd: this.cwd,
2554
- mode: e
2555
- }, i);
2556
- }
2557
- [Re](t) {
2558
- return this.forceChown || this.preserveOwner && (typeof t.uid == "number" && t.uid !== this.processUid || typeof t.gid == "number" && t.gid !== this.processGid) || typeof this.uid == "number" && this.uid !== this.processUid || typeof this.gid == "number" && this.gid !== this.processGid;
2559
- }
2560
- [ge](t) {
2561
- return Fr(this.uid, t.uid, this.processUid);
2562
- }
2563
- [be](t) {
2564
- return Fr(this.gid, t.gid, this.processGid);
2565
- }
2566
- [_s](t, e) {
2567
- let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = new tt(String(t.absolute), {
2568
- flags: ds(t.size),
2569
- mode: i,
2570
- autoClose: !1
2571
- });
2572
- r.on("error", (h) => {
2573
- r.fd && Kt.close(r.fd, () => {}), r.write = () => !0, this[O$1](h, t), e();
2574
- });
2575
- let n = 1, o = (h) => {
2576
- if (h) {
2577
- r.fd && Kt.close(r.fd, () => {}), this[O$1](h, t), e();
2578
- return;
2579
- }
2580
- --n === 0 && r.fd !== void 0 && Kt.close(r.fd, (l) => {
2581
- l ? this[O$1](l, t) : this[$t](), e();
2582
- });
2583
- };
2584
- r.on("finish", () => {
2585
- let h = String(t.absolute), l = r.fd;
2586
- if (typeof l == "number" && t.mtime && !this.noMtime) {
2587
- n++;
2588
- let c = t.atime || /* @__PURE__ */ new Date(), d = t.mtime;
2589
- Kt.futimes(l, c, d, (S) => S ? Kt.utimes(h, c, d, (T) => o(T && S)) : o());
2590
- }
2591
- if (typeof l == "number" && this[Re](t)) {
2592
- n++;
2593
- let c = this[ge](t), d = this[be](t);
2594
- typeof c == "number" && typeof d == "number" && Kt.fchown(l, c, d, (S) => S ? Kt.chown(h, c, d, (T) => o(T && S)) : o());
2595
- }
2596
- o();
2597
- });
2598
- let a = this.transform && this.transform(t) || t;
2599
- a !== t && (a.on("error", (h) => {
2600
- this[O$1](h, t), e();
2601
- }), t.pipe(a)), a.pipe(r);
2602
- }
2603
- [Os](t, e) {
2604
- let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode;
2605
- this[yt](String(t.absolute), i, (r) => {
2606
- if (r) {
2607
- this[O$1](r, t), e();
2608
- return;
2609
- }
2610
- let n = 1, o = () => {
2611
- --n === 0 && (e(), this[$t](), t.resume());
2612
- };
2613
- t.mtime && !this.noMtime && (n++, Kt.utimes(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime, o)), this[Re](t) && (n++, Kt.chown(String(t.absolute), Number(this[ge](t)), Number(this[be](t)), o)), o();
2614
- });
2615
- }
2616
- [Dr](t) {
2617
- t.unsupported = !0, this.warn("TAR_ENTRY_UNSUPPORTED", `unsupported entry type: ${t.type}`, { entry: t }), t.resume();
2618
- }
2619
- [Lr](t, e) {
2620
- let i = f$1(path.relative(this.cwd, path.resolve(path.dirname(String(t.absolute)), String(t.linkpath)))).split("/");
2621
- this[ye](t, this.cwd, i, () => this[Ri](t, String(t.linkpath), "symlink", e), (r) => {
2622
- this[O$1](r, t), e();
2623
- });
2624
- }
2625
- [Nr](t, e) {
2626
- let i = f$1(path.resolve(this.cwd, String(t.linkpath))), r = f$1(String(t.linkpath)).split("/");
2627
- this[ye](t, this.cwd, r, () => this[Ri](t, i, "link", e), (n) => {
2628
- this[O$1](n, t), e();
2629
- });
2630
- }
2631
- [ye](t, e, i, r, n) {
2632
- let o = i.shift();
2633
- if (this.preservePaths || o === void 0) return r();
2634
- let a = path.resolve(e, o);
2635
- Kt.lstat(a, (h, l) => {
2636
- if (h) return r();
2637
- if (l?.isSymbolicLink()) return n(new St(a, path.resolve(a, i.join("/"))));
2638
- this[ye](t, a, i, r, n);
2639
- });
2640
- }
2641
- [Ir]() {
2642
- this[yi]++;
2643
- }
2644
- [$t]() {
2645
- this[yi]--, this[Rs]();
2646
- }
2647
- [Ts](t) {
2648
- this[$t](), t.resume();
2649
- }
2650
- [bs](t, e) {
2651
- return t.type === "File" && !this.unlink && e.isFile() && e.nlink <= 1 && !Oe;
2652
- }
2653
- [gs](t) {
2654
- this[Ir]();
2655
- let e = [t.path];
2656
- t.linkpath && e.push(t.linkpath), this.reservations.reserve(e, (i) => this[xr](t, i));
2657
- }
2658
- [xr](t, e) {
2659
- let i = (a) => {
2660
- e(a);
2661
- }, r = () => {
2662
- this[yt](this.cwd, this.dmode, (a) => {
2663
- if (a) {
2664
- this[O$1](a, t), i();
2665
- return;
2666
- }
2667
- this[_e] = !0, n();
2668
- });
2669
- }, n = () => {
2670
- if (t.absolute !== this.cwd) {
2671
- let a = f$1(path.dirname(String(t.absolute)));
2672
- if (a !== this.cwd) return this[yt](a, this.dmode, (h) => {
2673
- if (h) {
2674
- this[O$1](h, t), i();
2675
- return;
2676
- }
2677
- o();
2678
- });
2679
- }
2680
- o();
2681
- }, o = () => {
2682
- Kt.lstat(String(t.absolute), (a, h) => {
2683
- if (h && (this.keep || this.newer && h.mtime > (t.mtime ?? h.mtime))) {
2684
- this[Ts](t), i();
2685
- return;
2686
- }
2687
- if (a || this[bs](t, h)) return this[P$1](null, t, i);
2688
- if (h.isDirectory()) {
2689
- if (t.type === "Directory") {
2690
- let l = this.chmod && t.mode && (h.mode & 4095) !== t.mode, c = (d) => this[P$1](d ?? null, t, i);
2691
- return l ? Kt.chmod(String(t.absolute), Number(t.mode), c) : c();
2692
- }
2693
- if (t.absolute !== this.cwd) return Kt.rmdir(String(t.absolute), (l) => this[P$1](l ?? null, t, i));
2694
- }
2695
- if (t.absolute === this.cwd) return this[P$1](null, t, i);
2696
- ao(String(t.absolute), (l) => this[P$1](l ?? null, t, i));
2697
- });
2698
- };
2699
- this[_e] ? n() : r();
2700
- }
2701
- [P$1](t, e, i) {
2702
- if (t) {
2703
- this[O$1](t, e), i();
2704
- return;
2705
- }
2706
- switch (e.type) {
2707
- case "File":
2708
- case "OldFile":
2709
- case "ContiguousFile": return this[_s](e, i);
2710
- case "Link": return this[Nr](e, i);
2711
- case "SymbolicLink": return this[Lr](e, i);
2712
- case "Directory":
2713
- case "GNUDumpDir": return this[Os](e, i);
2714
- }
2715
- }
2716
- [Ri](t, e, i, r) {
2717
- Kt[i](e, String(t.absolute), (n) => {
2718
- n ? this[O$1](n, t) : (this[$t](), t.resume()), r();
2719
- });
2720
- }
2721
- }, Se = (s) => {
2722
- try {
2723
- return [null, s()];
2724
- } catch (t) {
2725
- return [t, null];
2726
- }
2727
- }, Te = class extends Xt {
2728
- sync = !0;
2729
- [P$1](t, e) {
2730
- return super[P$1](t, e, () => {});
2731
- }
2732
- [gs](t) {
2733
- if (!this[_e]) {
2734
- let n = this[yt](this.cwd, this.dmode);
2735
- if (n) return this[O$1](n, t);
2736
- this[_e] = !0;
2737
- }
2738
- if (t.absolute !== this.cwd) {
2739
- let n = f$1(path.dirname(String(t.absolute)));
2740
- if (n !== this.cwd) {
2741
- let o = this[yt](n, this.dmode);
2742
- if (o) return this[O$1](o, t);
2743
- }
2744
- }
2745
- let [e, i] = Se(() => Kt.lstatSync(String(t.absolute)));
2746
- if (i && (this.keep || this.newer && i.mtime > (t.mtime ?? i.mtime))) return this[Ts](t);
2747
- if (e || this[bs](t, i)) return this[P$1](null, t);
2748
- if (i.isDirectory()) {
2749
- if (t.type === "Directory") {
2750
- let [a] = this.chmod && t.mode && (i.mode & 4095) !== t.mode ? Se(() => {
2751
- Kt.chmodSync(String(t.absolute), Number(t.mode));
2752
- }) : [];
2753
- return this[P$1](a, t);
2754
- }
2755
- let [n] = Se(() => Kt.rmdirSync(String(t.absolute)));
2756
- this[P$1](n, t);
2757
- }
2758
- let [r] = t.absolute === this.cwd ? [] : Se(() => lo(String(t.absolute)));
2759
- this[P$1](r, t);
2760
- }
2761
- [_s](t, e) {
2762
- let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = (a) => {
2763
- let h;
2764
- try {
2765
- Kt.closeSync(n);
2766
- } catch (l) {
2767
- h = l;
2768
- }
2769
- (a || h) && this[O$1](a || h, t), e();
2770
- }, n;
2771
- try {
2772
- n = Kt.openSync(String(t.absolute), ds(t.size), i);
2773
- } catch (a) {
2774
- return r(a);
2775
- }
2776
- let o = this.transform && this.transform(t) || t;
2777
- o !== t && (o.on("error", (a) => this[O$1](a, t)), t.pipe(o)), o.on("data", (a) => {
2778
- try {
2779
- Kt.writeSync(n, a, 0, a.length);
2780
- } catch (h) {
2781
- r(h);
2782
- }
2783
- }), o.on("end", () => {
2784
- let a = null;
2785
- if (t.mtime && !this.noMtime) {
2786
- let h = t.atime || /* @__PURE__ */ new Date(), l = t.mtime;
2787
- try {
2788
- Kt.futimesSync(n, h, l);
2789
- } catch (c) {
2790
- try {
2791
- Kt.utimesSync(String(t.absolute), h, l);
2792
- } catch {
2793
- a = c;
2794
- }
2795
- }
2796
- }
2797
- if (this[Re](t)) {
2798
- let h = this[ge](t), l = this[be](t);
2799
- try {
2800
- Kt.fchownSync(n, Number(h), Number(l));
2801
- } catch (c) {
2802
- try {
2803
- Kt.chownSync(String(t.absolute), Number(h), Number(l));
2804
- } catch {
2805
- a = a || c;
2806
- }
2807
- }
2808
- }
2809
- r(a);
2810
- });
2811
- }
2812
- [Os](t, e) {
2813
- let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode, r = this[yt](String(t.absolute), i);
2814
- if (r) {
2815
- this[O$1](r, t), e();
2816
- return;
2817
- }
2818
- if (t.mtime && !this.noMtime) try {
2819
- Kt.utimesSync(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime);
2820
- } catch {}
2821
- if (this[Re](t)) try {
2822
- Kt.chownSync(String(t.absolute), Number(this[ge](t)), Number(this[be](t)));
2823
- } catch {}
2824
- e(), t.resume();
2825
- }
2826
- [yt](t, e) {
2827
- try {
2828
- return Rr(f$1(t), {
2829
- uid: this.uid,
2830
- gid: this.gid,
2831
- processUid: this.processUid,
2832
- processGid: this.processGid,
2833
- umask: this.processUmask,
2834
- preserve: this.preservePaths,
2835
- unlink: this.unlink,
2836
- cwd: this.cwd,
2837
- mode: e
2838
- });
2839
- } catch (i) {
2840
- return i;
2841
- }
2842
- }
2843
- [ye](t, e, i, r, n) {
2844
- if (this.preservePaths || i.length === 0) return r();
2845
- let o = e;
2846
- for (let a of i) {
2847
- o = path.resolve(o, a);
2848
- let [h, l] = Se(() => Kt.lstatSync(o));
2849
- if (h) return r();
2850
- if (l.isSymbolicLink()) return n(new St(o, path.resolve(e, i.join("/"))));
2851
- }
2852
- r();
2853
- }
2854
- [Ri](t, e, i, r) {
2855
- let n = `${i}Sync`;
2856
- try {
2857
- Kt[n](e, String(t.absolute)), r(), t.resume();
2858
- } catch (o) {
2859
- return this[O$1](o, t);
2860
- }
2861
- }
2862
- }, co = (s) => {
2863
- let t = new Te(s), e = s.file, i = Kt.statSync(e);
2864
- new Me(e, {
2865
- readSize: s.maxReadSize || 16 * 1024 * 1024,
2866
- size: i.size
2867
- }).pipe(t);
2868
- }, fo = (s, t) => {
2869
- let e = new Xt(s), i = s.maxReadSize || 16 * 1024 * 1024, r = s.file;
2870
- return new Promise((o, a) => {
2871
- e.on("error", a), e.on("close", o), Kt.stat(r, (h, l) => {
2872
- if (h) a(h);
2873
- else {
2874
- let c = new _t(r, {
2875
- readSize: i,
2876
- size: l.size
2877
- });
2878
- c.on("error", a), c.pipe(e);
2879
- }
2880
- });
2881
- });
2882
- };
2883
- K(co, fo, (s) => new Te(s), (s) => new Xt(s), (s, t) => {
2884
- t?.length && Xi(s, t);
2885
- });
2886
- var mo = (s, t) => {
2887
- let e = new kt(s), i = !0, r, n;
2888
- try {
2889
- try {
2890
- r = Kt.openSync(s.file, "r+");
2891
- } catch (h) {
2892
- if (h?.code === "ENOENT") r = Kt.openSync(s.file, "w+");
2893
- else throw h;
2894
- }
2895
- let o = Kt.fstatSync(r), a = Buffer.alloc(512);
2896
- t: for (n = 0; n < o.size; n += 512) {
2897
- for (let c = 0, d = 0; c < 512; c += d) {
2898
- if (d = Kt.readSync(r, a, c, a.length - c, n + c), n === 0 && a[0] === 31 && a[1] === 139) throw new Error("cannot append to compressed archives");
2899
- if (!d) break t;
2900
- }
2901
- let h = new C$1(a);
2902
- if (!h.cksumValid) break;
2903
- let l = 512 * Math.ceil((h.size || 0) / 512);
2904
- if (n + l + 512 > o.size) break;
2905
- n += l, s.mtimeCache && h.mtime && s.mtimeCache.set(String(h.path), h.mtime);
2906
- }
2907
- i = !1, po(s, e, n, r, t);
2908
- } finally {
2909
- if (i) try {
2910
- Kt.closeSync(r);
2911
- } catch {}
2912
- }
2913
- }, po = (s, t, e, i, r) => {
2914
- let n = new Wt(s.file, {
2915
- fd: i,
2916
- start: e
2917
- });
2918
- t.pipe(n), wo(t, r);
2919
- }, Eo = (s, t) => {
2920
- t = Array.from(t);
2921
- let e = new wt(s), i = (n, o, a) => {
2922
- let h = (T, N) => {
2923
- T ? Kt.close(n, (E) => a(T)) : a(null, N);
2924
- }, l = 0;
2925
- if (o === 0) return h(null, 0);
2926
- let c = 0, d = Buffer.alloc(512), S = (T, N) => {
2927
- if (T || N === void 0) return h(T);
2928
- if (c += N, c < 512 && N) return Kt.read(n, d, c, d.length - c, l + c, S);
2929
- if (l === 0 && d[0] === 31 && d[1] === 139) return h(/* @__PURE__ */ new Error("cannot append to compressed archives"));
2930
- if (c < 512) return h(null, l);
2931
- let E = new C$1(d);
2932
- if (!E.cksumValid) return h(null, l);
2933
- let x = 512 * Math.ceil((E.size ?? 0) / 512);
2934
- if (l + x + 512 > o || (l += x + 512, l >= o)) return h(null, l);
2935
- s.mtimeCache && E.mtime && s.mtimeCache.set(String(E.path), E.mtime), c = 0, Kt.read(n, d, 0, 512, l, S);
2936
- };
2937
- Kt.read(n, d, 0, 512, l, S);
2938
- };
2939
- return new Promise((n, o) => {
2940
- e.on("error", o);
2941
- let a = "r+", h = (l, c) => {
2942
- if (l && l.code === "ENOENT" && a === "r+") return a = "w+", Kt.open(s.file, a, h);
2943
- if (l || !c) return o(l);
2944
- Kt.fstat(c, (d, S) => {
2945
- if (d) return Kt.close(c, () => o(d));
2946
- i(c, S.size, (T, N) => {
2947
- if (T) return o(T);
2948
- let E = new tt(s.file, {
2949
- fd: c,
2950
- start: N
2951
- });
2952
- e.pipe(E), E.on("error", o), E.on("close", n), So(e, t);
2953
- });
2954
- });
2955
- };
2956
- Kt.open(s.file, a, h);
2957
- });
2958
- }, wo = (s, t) => {
2959
- t.forEach((e) => {
2960
- e.charAt(0) === "@" ? Ft({
2961
- file: path.resolve(s.cwd, e.slice(1)),
2962
- sync: !0,
2963
- noResume: !0,
2964
- onReadEntry: (i) => s.add(i)
2965
- }) : s.add(e);
2966
- }), s.end();
2967
- }, So = async (s, t) => {
2968
- for (let e of t) e.charAt(0) === "@" ? await Ft({
2969
- file: path.resolve(String(s.cwd), e.slice(1)),
2970
- noResume: !0,
2971
- onReadEntry: (i) => s.add(i)
2972
- }) : s.add(e);
2973
- s.end();
2974
- }, vt = K(mo, Eo, () => {
2975
- throw new TypeError("file is required");
2976
- }, () => {
2977
- throw new TypeError("file is required");
2978
- }, (s, t) => {
2979
- if (!vs(s)) throw new TypeError("file is required");
2980
- if (s.gzip || s.brotli || s.zstd || s.file.endsWith(".br") || s.file.endsWith(".tbr")) throw new TypeError("cannot append to compressed archives");
2981
- if (!t?.length) throw new TypeError("no paths specified to add/replace");
2982
- });
2983
- K(vt.syncFile, vt.asyncFile, vt.syncNoFile, vt.asyncNoFile, (s, t = []) => {
2984
- vt.validate?.(s, t), Ro(s);
2985
- });
2986
- var Ro = (s) => {
2987
- let t = s.filter;
2988
- s.mtimeCache || (s.mtimeCache = /* @__PURE__ */ new Map()), s.filter = t ? (e, i) => t(e, i) && !((s.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)) : (e, i) => !((s.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0));
2989
- };
2990
- //#endregion
2991
- //#region src/builtins/system-backup/system-backup.service.ts
2992
- /**
2993
- * Thrown when an archive build (or a backup run driving one) is
2994
- * stopped via its `AbortSignal`. Callers use `instanceof` to tell a
2995
- * deliberate operator cancel from a real failure — a cancelled run is
2996
- * an outcome, not an error to alert on. (D342)
2997
- */
2998
- var BackupCancelledError = class extends Error {
2999
- constructor(message = "backup run cancelled") {
3000
- super(message);
3001
- this.name = "BackupCancelledError";
3002
- }
3003
- };
3004
- /**
3005
- * Thrown when an archive would carry a live database and its owner could not
3006
- * produce a verified snapshot of it (D693). Nothing was built: a run that
3007
- * "succeeded" without the database — or with a torn copy of it — would push
3008
- * the oldest good archive out of every destination's retention.
3009
- */
3010
- var BackupSnapshotRefusedError = class extends Error {
3011
- constructor(reason) {
3012
- super(`settings database snapshot failed — no archive built, nothing uploaded, retention untouched: ${reason}`);
3013
- this.name = "BackupSnapshotRefusedError";
3014
- }
3015
- };
3016
- /**
3017
- * Settle with `pending`, or reject with {@link BackupCancelledError} as soon as
3018
- * `signal` fires. A pending call abandoned by the cancel still settles later:
3019
- * `onAbandoned` runs then, to clean up what it produced.
3020
- */
3021
- function raceAbort(pending, signal, onAbandoned) {
3022
- if (signal === void 0) return pending;
3023
- return new Promise((resolve, reject) => {
3024
- let abandoned = false;
3025
- const onAbort = () => {
3026
- abandoned = true;
3027
- reject(new BackupCancelledError());
3028
- };
3029
- if (signal.aborted) onAbort();
3030
- else signal.addEventListener("abort", onAbort, { once: true });
3031
- pending.then((value) => {
3032
- signal.removeEventListener("abort", onAbort);
3033
- if (abandoned) onAbandoned();
3034
- else resolve(value);
3035
- }, (err) => {
3036
- signal.removeEventListener("abort", onAbort);
3037
- if (abandoned) onAbandoned();
3038
- else reject(err);
3039
- });
3040
- });
3041
- }
3042
- /** Throw `BackupCancelledError` when the signal has fired. */
3043
- function throwIfCancelled(signal) {
3044
- if (signal?.aborted) throw new BackupCancelledError();
3045
- }
3046
- /**
3047
- * Default set of paths considered part of a "system backup". Includes
3048
- * everything that isn't pure backend code — config, sqlite, addons
3049
- * (runtime overlay), addons-data (per-addon private dir), TLS certs,
3050
- * auto-update marker.
3051
- *
3052
- * Anything not listed is excluded by omission — recordings/, media/,
3053
- * models/, logs/, cache/ (too large or fully recreatable). Note this
3054
- * covers only TOP-LEVEL trees: bulk nested INSIDE a listed location
3055
- * is excluded via `DEFAULT_BACKUP_EXCLUDES` + the node_modules rule
3056
- * below, enforced in the walk and the tar filter alike.
3057
- */
3058
- var DEFAULT_BACKUP_LOCATIONS = [
3059
- "config.yaml",
3060
- "addons",
3061
- "addons-data",
3062
- "tls",
3063
- "auto-update.json"
3064
- ];
3065
- /**
3066
- * Subtrees never captured by a system backup even though they live
3067
- * under a `DEFAULT_BACKUP_LOCATIONS` entry. Paths are dataDir-relative
3068
- * prefixes. Two lessons from the live hub (2026-09-04, D-record
3069
- * "backup excludes"):
3070
- *
3071
- * - `addons-data/backup-orchestrator/staging` — the orchestrator's
3072
- * LEGACY staging dir (now `<dataDir>/backup-staging`, outside every
3073
- * location). Before Jul 28 every archive nested all previous
3074
- * archives (175M → 503M → 4.5G); leaked files from that era must
3075
- * never be re-swept into new backups.
3076
- * - `addons-data/recorder/exports` — operator-exported clips (8.4 GB
3077
- * on the hub). Media, not system state; a restore has no use for it.
3078
- */
3079
- var DEFAULT_BACKUP_EXCLUDES = ["addons-data/backup-orchestrator/staging", "addons-data/recorder/exports"];
3080
- /**
3081
- * Directory name excluded wherever it appears in the tree.
3082
- * `AddonInstaller` materialises runtime deps under
3083
- * `addons/@camstack/<addon>/node_modules` (~196 MB on the hub); only
3084
- * built `dist` + package.json + assets are restore-worthy — deps are
3085
- * reinstalled from npm on demand. node_modules is NEVER archived.
3086
- */
3087
- var EXCLUDED_DIR_NAME = "node_modules";
3088
- /**
3089
- * True when a dataDir-relative path must be omitted from archives,
3090
- * manifests and location stats. Accepts tar-style paths (`./` prefix,
3091
- * trailing `/`) and backslash separators.
3092
- */
3093
- function isExcludedFromBackup(relPath) {
3094
- const norm = normalizeArchivePath(relPath);
3095
- if (norm.length === 0) return false;
3096
- const segments = norm.split("/");
3097
- if (segments.includes(EXCLUDED_DIR_NAME)) return true;
3098
- if (segments.some((seg) => seg.endsWith(".backup-snapshot-partial"))) return true;
3099
- if (norm.endsWith(".backup-snapshot")) return true;
3100
- return DEFAULT_BACKUP_EXCLUDES.some((prefix) => norm === prefix || norm.startsWith(`${prefix}/`));
3101
- }
3102
- /** `./a/b/` and `a\\b` → `a/b`: the one spelling every archive-path comparison uses. */
3103
- function normalizeArchivePath(relPath) {
3104
- return relPath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
3105
- }
3106
- /** The files SQLite keeps beside a database. A live one is never archived. */
3107
- var SQLITE_SIDECAR_SUFFIXES = [
3108
- "-wal",
3109
- "-shm",
3110
- "-journal"
3111
- ];
3112
- var SQLITE_DATABASE_SUFFIXES = [
3113
- ".db",
3114
- ".sqlite",
3115
- ".sqlite3"
3116
- ];
3117
- /**
3118
- * The database a `-wal` / `-shm` / `-journal` belongs to, or null for any other
3119
- * path. The base must name a database (`.db` / `.sqlite` / `.sqlite3`): a
3120
- * `build-journal` is not a sidecar, and must not stop every backup as a "live
3121
- * database" that does not exist.
3122
- */
3123
- function databaseOfSidecar(relPath) {
3124
- for (const suffix of SQLITE_SIDECAR_SUFFIXES) {
3125
- if (!relPath.endsWith(suffix)) continue;
3126
- const db = relPath.slice(0, -suffix.length);
3127
- return SQLITE_DATABASE_SUFFIXES.some((dbSuffix) => db.endsWith(dbSuffix)) ? db : null;
3128
- }
3129
- return null;
3130
- }
3131
- /** A SQLite database file, or a sidecar of one. */
3132
- function isSqlitePath(relPath) {
3133
- const db = databaseOfSidecar(relPath) ?? relPath;
3134
- return SQLITE_DATABASE_SUFFIXES.some((suffix) => db.endsWith(suffix));
3135
- }
3136
- /** Path of the manifest file embedded inside every archive. */
3137
- var ARCHIVE_MANIFEST_NAME = ".camstack-backup-manifest.json";
3138
- var DEFAULT_STAT_CACHE_TTL_MS = 6e4;
3139
- /**
3140
- * System-level archive primitives. Construct one per server boot;
3141
- * methods are pure I/O.
3142
- */
3143
- var SystemBackupService = class {
3144
- dataDir;
3145
- logger;
3146
- statCacheTtlMs;
3147
- statCache = /* @__PURE__ */ new Map();
3148
- constructor(dataDir, logger, opts) {
3149
- this.dataDir = dataDir;
3150
- this.logger = logger;
3151
- this.statCacheTtlMs = opts?.statCacheTtlMs ?? DEFAULT_STAT_CACHE_TTL_MS;
3152
- }
3153
- /**
3154
- * Snapshot the current size + file count of each well-known
3155
- * location. Used by the admin UI to render an opt-in checklist
3156
- * before triggering a backup, and by `createArchive` to derive the
3157
- * embedded manifest.
3158
- *
3159
- * The walk is async (yields to the event loop per directory) and
3160
- * per-location results are cached + single-flighted: the service
3161
- * runs in-process in the hub, and a synchronous walk of the 70k+
3162
- * file `addons` location blocked the event loop long enough to kill
3163
- * WS keepalives cluster-wide.
3164
- */
3165
- statLocations(locations = DEFAULT_BACKUP_LOCATIONS) {
3166
- return Promise.all(locations.map((loc) => this.statLocationCached(loc)));
3167
- }
3168
- statLocationCached(loc) {
3169
- const now = Date.now();
3170
- const hit = this.statCache.get(loc);
3171
- if (hit && now - hit.at < this.statCacheTtlMs) return hit.value;
3172
- const value = this.statLocation(loc);
3173
- this.statCache.set(loc, {
3174
- at: now,
3175
- value
3176
- });
3177
- value.catch(() => this.statCache.delete(loc));
3178
- return value;
3179
- }
3180
- async statLocation(loc) {
3181
- const abs = path$1.isAbsolute(loc) ? loc : path$1.join(this.dataDir, loc);
3182
- if (!fs.existsSync(abs)) return {
3183
- name: loc,
3184
- sizeBytes: 0,
3185
- fileCount: 0,
3186
- present: false
3187
- };
3188
- const walked = await walkAbs(abs, abs, this.exclusionPredicate());
3189
- return {
3190
- name: loc,
3191
- sizeBytes: walked.reduce((acc, e) => acc + e.sizeBytes, 0),
3192
- fileCount: walked.filter((e) => e.kind === "file").length,
3193
- present: true
3194
- };
3195
- }
3196
- /**
3197
- * Create a tar.gz of the given locations. Uses the `tar` npm package
3198
- * (used by npm itself) instead of shelling out — gives us:
3199
- *
3200
- * - Symlink dereference (`follow: true`) so dev mode's
3201
- * `addons/<name> → packages/<name>` overlay archives content,
3202
- * not just link stubs.
3203
- * - Programmatic walk → we build a manifest of every entry while
3204
- * copying so the archive can self-describe.
3205
- *
3206
- * Locations that don't exist are silently skipped. Throws if zero
3207
- * locations would be included.
3208
- *
3209
- * Cancellation: `signal` aborts the build IN FLIGHT — the manifest
3210
- * walk checks it per filesystem node and the tar phase runs through
3211
- * `stream.pipeline(..., { signal })`, which destroys the pack and
3212
- * the file sink immediately. On abort the half-written archive is
3213
- * deleted here (never left for the caller to remember) and the call
3214
- * rejects with {@link BackupCancelledError}. (D342)
3215
- *
3216
- * Progress: `onArchiveBytes` receives the cumulative compressed
3217
- * bytes written to `archivePath` — the live "how large has staging
3218
- * grown" counter `backup.listRuns` exposes.
3219
- */
3220
- async createArchive(opts) {
3221
- throwIfCancelled(opts.signal);
3222
- const requested = opts.locations ?? DEFAULT_BACKUP_LOCATIONS;
3223
- const present = [];
3224
- for (const loc of requested) {
3225
- const abs = path$1.isAbsolute(loc) ? loc : path$1.join(this.dataDir, loc);
3226
- if (fs.existsSync(abs)) present.push(loc);
3227
- else this.logger.debug("createArchive: skipping missing location", { meta: { location: loc } });
3228
- }
3229
- if (present.length === 0) throw new Error(`createArchive: no locations from {${requested.join(", ")}} exist under ${this.dataDir}`);
3230
- fs.mkdirSync(path$1.dirname(opts.archivePath), { recursive: true });
3231
- const walked = [];
3232
- for (const loc of present) {
3233
- throwIfCancelled(opts.signal);
3234
- const abs = path$1.join(this.dataDir, loc);
3235
- const stat = await fsp.stat(abs);
3236
- if (stat.isDirectory()) for (const e of await walkAbs(abs, this.dataDir, this.exclusionPredicate(), opts.signal)) walked.push(e);
3237
- else if (!isExcludedFromBackup(path$1.relative(this.dataDir, abs))) walked.push(toArchiveEntry(abs, this.dataDir, stat));
3238
- }
3239
- const walkedPaths = new Set(walked.map((e) => e.path));
3240
- const owned = walked.some((e) => isSqlitePath(e.path)) ? await this.ownedDatabasesInScope(opts.owner, walkedPaths) : /* @__PURE__ */ new Set();
3241
- const unowned = /* @__PURE__ */ new Set();
3242
- for (const e of walked) {
3243
- const db = databaseOfSidecar(e.path);
3244
- if (db !== null && !owned.has(db)) unowned.add(db);
3245
- }
3246
- if (unowned.size > 0) {
3247
- const databases = [...unowned].sort();
3248
- this.logger.error("createArchive: a live SQLite database has no owner snapshot — no archive built", { meta: {
3249
- databases,
3250
- archivePath: opts.archivePath
3251
- } });
3252
- throw new BackupSnapshotRefusedError(`live SQLite database ${databases.join(", ")} has no owner that can snapshot it — a copy of its files would be torn; remove its stale -wal/-shm/-journal if nothing has it open, or leave its location out of the backup`);
3253
- }
3254
- const snapshot = owned.size > 0 && opts.owner ? await this.takeOwnerSnapshot(opts.owner, owned, opts.signal) : null;
3255
- try {
3256
- const liveFiles = /* @__PURE__ */ new Set();
3257
- for (const db of owned) {
3258
- liveFiles.add(db);
3259
- for (const suffix of SQLITE_SIDECAR_SUFFIXES) liveFiles.add(db + suffix);
3260
- }
3261
- const entries = walked.filter((e) => !liveFiles.has(e.path));
3262
- if (snapshot !== null) entries.push(snapshot.entry);
3263
- const manifest = {
3264
- archiveVersion: 1,
3265
- createdAt: Date.now(),
3266
- dataDir: this.dataDir,
3267
- locations: present,
3268
- entries,
3269
- totalBytes: entries.reduce((acc, e) => acc + e.sizeBytes, 0),
3270
- totalFiles: entries.filter((e) => e.kind === "file").length,
3271
- ...snapshot !== null ? { sqliteSnapshots: [snapshot.archived] } : {}
3272
- };
3273
- const carriedSnapshot = snapshot?.archived.snapshotPath ?? null;
3274
- return await this.writeArchive({
3275
- archivePath: opts.archivePath,
3276
- present,
3277
- manifest,
3278
- excluded: (rel) => {
3279
- if (rel === carriedSnapshot) return false;
3280
- return liveFiles.has(rel) || isExcludedFromBackup(rel);
3281
- },
3282
- ...opts.signal ? { signal: opts.signal } : {},
3283
- ...opts.onArchiveBytes ? { onArchiveBytes: opts.onArchiveBytes } : {}
3284
- });
3285
- } finally {
3286
- if (snapshot !== null) await this.removeSnapshot(snapshot.absPath);
3287
- }
3288
- }
3289
- /**
3290
- * Tar `present` (filtered by `excluded`) plus the staged manifest into
3291
- * `archivePath`.
3292
- */
3293
- async writeArchive(opts) {
3294
- const { present, manifest } = opts;
3295
- const manifestStagePath = `${opts.archivePath}.${process.pid}.manifest.json`;
3296
- fs.writeFileSync(manifestStagePath, JSON.stringify(manifest, null, 2), "utf-8");
3297
- this.logger.info("createArchive: tarring", { meta: {
3298
- archivePath: opts.archivePath,
3299
- locations: [...present],
3300
- totalFiles: manifest.totalFiles,
3301
- totalBytes: manifest.totalBytes
3302
- } });
3303
- try {
3304
- const stagedInDataDir = path$1.join(this.dataDir, ARCHIVE_MANIFEST_NAME);
3305
- fs.copyFileSync(manifestStagePath, stagedInDataDir);
3306
- const stagingRel = path$1.relative(this.dataDir, path$1.dirname(opts.archivePath));
3307
- const excludePrefix = stagingRel && !stagingRel.startsWith("..") && !path$1.isAbsolute(stagingRel) ? stagingRel : null;
3308
- try {
3309
- const pack = Kn({
3310
- gzip: true,
3311
- cwd: this.dataDir,
3312
- follow: true,
3313
- portable: true,
3314
- filter: (entryPath) => {
3315
- const norm = normalizeArchivePath(entryPath);
3316
- if (opts.excluded(norm)) return false;
3317
- if (!excludePrefix) return true;
3318
- return norm !== excludePrefix && !norm.startsWith(`${excludePrefix}/`);
3319
- }
3320
- }, [ARCHIVE_MANIFEST_NAME, ...present]);
3321
- const sink = fs.createWriteStream(opts.archivePath);
3322
- try {
3323
- await pipeline(pack, byteCountingPassthrough(opts.onArchiveBytes), sink, opts.signal ? { signal: opts.signal } : {});
3324
- } catch (err) {
3325
- try {
3326
- fs.rmSync(opts.archivePath, { force: true });
3327
- } catch {}
3328
- if (opts.signal?.aborted) throw new BackupCancelledError();
3329
- throw err;
3330
- }
3331
- } finally {
3332
- try {
3333
- fs.rmSync(stagedInDataDir, { force: true });
3334
- } catch {}
3335
- }
3336
- } finally {
3337
- try {
3338
- fs.rmSync(manifestStagePath, { force: true });
3339
- } catch {}
3340
- }
3341
- const sizeBytes = fs.statSync(opts.archivePath).size;
3342
- return {
3343
- archivePath: opts.archivePath,
3344
- includedLocations: [...present],
3345
- sizeBytes,
3346
- manifest
3347
- };
3348
- }
3349
- /**
3350
- * without extracting payload files. Streams the tar.gz, parses the
3351
- * one entry we care about, then aborts.
3352
- */
3353
- async readArchiveManifest(archivePath) {
3354
- if (!fs.existsSync(archivePath)) throw new Error(`readArchiveManifest: ${archivePath} does not exist`);
3355
- return new Promise((resolve, reject) => {
3356
- const chunks = [];
3357
- let found = false;
3358
- let resolved = false;
3359
- const parser = new st({ onentry: (entry) => {
3360
- if (entry.path === ".camstack-backup-manifest.json" && !found) {
3361
- found = true;
3362
- entry.on("data", (chunk) => chunks.push(chunk));
3363
- entry.on("end", () => {
3364
- try {
3365
- const json = Buffer.concat(chunks).toString("utf-8");
3366
- const parsed = JSON.parse(json);
3367
- resolved = true;
3368
- resolve(parsed);
3369
- } catch (err) {
3370
- resolved = true;
3371
- reject(err instanceof Error ? err : new Error(String(err)));
3372
- }
3373
- });
3374
- } else entry.resume();
3375
- } });
3376
- parser.on("end", () => {
3377
- if (!resolved) resolve(found ? null : null);
3378
- });
3379
- const gunzip = zlib.createGunzip();
3380
- gunzip.on("error", (err) => {
3381
- if (!resolved) {
3382
- resolved = true;
3383
- reject(err);
3384
- }
3385
- });
3386
- const reader = fs.createReadStream(archivePath);
3387
- reader.on("error", (err) => {
3388
- if (!resolved) {
3389
- resolved = true;
3390
- reject(err);
3391
- }
3392
- });
3393
- reader.pipe(gunzip).pipe(parser);
3394
- });
3395
- }
3396
- /**
3397
- * Schedule a restore for the next boot by writing a marker file.
3398
- * `locations` (optional) carries through to the launcher's boot-time
3399
- * restore (`server/backend/src/launcher.ts`, the only restore there is)
3400
- * so the operator's "restore only X and Y" choice survives the process
3401
- * restart.
3402
- */
3403
- scheduleRestoreMarker(opts) {
3404
- if (!fs.existsSync(opts.archivePath)) throw new Error(`scheduleRestoreMarker: ${opts.archivePath} missing`);
3405
- const markerPath = this.getRestoreMarkerPath();
3406
- const marker = {
3407
- archivePath: opts.archivePath,
3408
- requestedAt: Date.now(),
3409
- source: opts.source,
3410
- ...opts.locations ? { locations: [...opts.locations] } : {}
3411
- };
3412
- fs.mkdirSync(path$1.dirname(markerPath), { recursive: true });
3413
- fs.writeFileSync(markerPath, JSON.stringify(marker, null, 2), { mode: 384 });
3414
- return markerPath;
3415
- }
3416
- /** Read the pending-restore marker if one is present. */
3417
- readPendingMarker() {
3418
- const markerPath = this.getRestoreMarkerPath();
3419
- if (!fs.existsSync(markerPath)) return null;
3420
- try {
3421
- const raw = fs.readFileSync(markerPath, "utf-8");
3422
- const parsed = JSON.parse(raw);
3423
- if (typeof parsed === "object" && parsed != null && typeof parsed.archivePath === "string") return parsed;
3424
- } catch (err) {
3425
- this.logger.warn("readPendingMarker: malformed marker — ignoring", { meta: { error: err instanceof Error ? err.message : String(err) } });
3426
- }
3427
- return null;
3428
- }
3429
- /** Drop the marker after a successful boot-time restore. */
3430
- clearPendingMarker() {
3431
- const markerPath = this.getRestoreMarkerPath();
3432
- if (fs.existsSync(markerPath)) fs.rmSync(markerPath, { force: true });
3433
- }
3434
- /**
3435
- * The databases the owner declares, archive-relative, that this walk found.
3436
- * One outside this data root is not in scope. An owner that cannot answer
3437
- * stops the archive: without the answer, nothing says which file is live.
3438
- */
3439
- async ownedDatabasesInScope(owner, walked) {
3440
- if (owner === void 0) return /* @__PURE__ */ new Set();
3441
- let declared;
3442
- try {
3443
- declared = await owner.listDatabases();
3444
- } catch (err) {
3445
- const reason = err instanceof Error ? err.message : String(err);
3446
- this.logger.error("createArchive: the database owner did not say what it owns — no archive built", { meta: { error: reason } });
3447
- throw new BackupSnapshotRefusedError(`the database owner could not be asked: ${reason}`);
3448
- }
3449
- const inScope = /* @__PURE__ */ new Set();
3450
- for (const abs of declared) {
3451
- const rel = this.archiveRelative(abs);
3452
- if (rel !== null && walked.has(rel)) inScope.add(rel);
3453
- }
3454
- return inScope;
3455
- }
3456
- /**
3457
- * Ask the owner for its snapshot, and place it in this archive. The snapshot
3458
- * must sit on THIS data root — the call is pinned to this node, so a path
3459
- * elsewhere means it reached another host, and that file is not ours to
3460
- * read — beside an owned database in scope, and it must cover EVERY owned
3461
- * database in scope. Anything else is refused.
3462
- *
3463
- * Only ever DELETED here: `<owned db>.backup-snapshot` under this data root,
3464
- * a name this process derives itself. A path the owner ANSWERS is never
3465
- * deleted on its word — answering the live database as the snapshot would
3466
- * otherwise delete the live database. A file at any other path is left to
3467
- * the owner's own sweep.
3468
- *
3469
- * A cancel is honoured while the owner is still copying; the copy it may
3470
- * finish afterwards is removed when that call settles.
3471
- */
3472
- async takeOwnerSnapshot(owner, owned, signal) {
3473
- const removeOwnedSnapshots = async () => {
3474
- for (const db of owned) await this.removeSnapshot(path$1.join(this.dataDir, db + DATABASE_SNAPSHOT_SUFFIX));
3475
- };
3476
- let result;
3477
- try {
3478
- result = await raceAbort(owner.writeSnapshot(), signal, () => {
3479
- this.logger.info("createArchive: run cancelled while the owner copied — its copy is removed when it lands", { meta: { databases: [...owned] } });
3480
- return removeOwnedSnapshots();
3481
- });
3482
- } catch (err) {
3483
- if (err instanceof BackupCancelledError) throw err;
3484
- const reason = err instanceof Error ? err.message : String(err);
3485
- this.logger.error("createArchive: the owner could not snapshot its live database — no archive built", { meta: {
3486
- databases: [...owned],
3487
- error: reason
3488
- } });
3489
- await removeOwnedSnapshots();
3490
- throw new BackupSnapshotRefusedError(reason);
3491
- }
3492
- try {
3493
- const livePath = this.archiveRelative(result.livePath);
3494
- const snapshotPath = this.archiveRelative(result.snapshotPath);
3495
- if (livePath === null || snapshotPath === null) {
3496
- this.logger.warn("createArchive: the owner answered a snapshot outside this data root — not touched, left to its sweep", { meta: {
3497
- snapshot: result.snapshotPath,
3498
- dataDir: this.dataDir
3499
- } });
3500
- throw new BackupSnapshotRefusedError(`snapshot ${result.snapshotPath} is not under this archive's data root ${this.dataDir}`);
3501
- }
3502
- if (snapshotPath !== livePath + ".backup-snapshot") throw new BackupSnapshotRefusedError(`snapshot ${snapshotPath} does not sit beside the database ${livePath} it copies`);
3503
- const uncovered = [...owned].filter((db) => db !== livePath);
3504
- if (!owned.has(livePath) || uncovered.length > 0) throw new BackupSnapshotRefusedError(`snapshot copies ${livePath}, but the owned database(s) in this archive are ${[...owned].join(", ")}`);
3505
- const absPath = path$1.join(this.dataDir, snapshotPath);
3506
- const stat = await fsp.stat(absPath);
3507
- this.logger.info("createArchive: carrying the owner snapshot in place of the live database", { meta: {
3508
- database: livePath,
3509
- snapshot: snapshotPath,
3510
- sizeBytes: stat.size,
3511
- tables: result.tables.length,
3512
- copyMs: result.copyMs,
3513
- verifyMs: result.verifyMs
3514
- } });
3515
- return {
3516
- absPath,
3517
- archived: {
3518
- ...result,
3519
- livePath,
3520
- snapshotPath
3521
- },
3522
- entry: toArchiveEntry(absPath, this.dataDir, stat)
3523
- };
3524
- } catch (err) {
3525
- await removeOwnedSnapshots();
3526
- throw err;
3527
- }
3528
- }
3529
- async removeSnapshot(absPath) {
3530
- try {
3531
- await fsp.rm(absPath, { force: true });
3532
- } catch (err) {
3533
- this.logger.warn("createArchive: owner snapshot could not be removed", { meta: {
3534
- snapshot: absPath,
3535
- error: err instanceof Error ? err.message : String(err)
3536
- } });
3537
- }
3538
- }
3539
- /** `abs` relative to the data root, or null when it lies outside it. */
3540
- archiveRelative(abs) {
3541
- const rel = path$1.relative(path$1.resolve(this.dataDir), path$1.resolve(abs));
3542
- if (rel.length === 0 || rel.startsWith("..") || path$1.isAbsolute(rel)) return null;
3543
- return normalizeArchivePath(rel);
3544
- }
3545
- getRestoreMarkerPath() {
3546
- return path$1.join(this.dataDir, ".pending-restore.json");
3547
- }
3548
- /**
3549
- * Absolute-path form of {@link isExcludedFromBackup}, anchored on
3550
- * this service's dataDir. Shared by the manifest walk and the location
3551
- * stats so both agree with the tar filter about what a backup contains.
3552
- */
3553
- exclusionPredicate() {
3554
- return (abs) => isExcludedFromBackup(path$1.relative(this.dataDir, abs));
3555
- }
3556
- };
3557
- /**
3558
- * Recursively walk a directory and produce one `ArchiveEntry` per
3559
- * filesystem node. `dataDir` is used to compute the archive-relative
3560
- * path. Symlinks are dereferenced (matches the `follow: true` flag we
3561
- * pass to tar.create).
3562
- */
3563
- async function walkAbs(absRoot, dataDir, shouldSkip, signal) {
3564
- const out = [];
3565
- await walkRec(absRoot, dataDir, out, shouldSkip, signal);
3566
- return out;
3567
- }
3568
- async function walkRec(abs, dataDir, out, shouldSkip, signal) {
3569
- throwIfCancelled(signal);
3570
- if (shouldSkip?.(abs)) return;
3571
- let stat;
3572
- try {
3573
- stat = await fsp.stat(abs);
3574
- } catch {
3575
- return;
3576
- }
3577
- out.push(toArchiveEntry(abs, dataDir, stat));
3578
- if (stat.isDirectory()) {
3579
- let children;
3580
- try {
3581
- children = await fsp.readdir(abs);
3582
- } catch {
3583
- return;
3584
- }
3585
- for (const child of children) await walkRec(path$1.join(abs, child), dataDir, out, shouldSkip, signal);
3586
- }
3587
- }
3588
- /**
3589
- * Pass-through transform that reports the CUMULATIVE bytes flowed so
3590
- * far. Sits between the tar pack and the file sink so the caller's
3591
- * progress counter tracks the compressed archive as it grows on disk.
3592
- */
3593
- function byteCountingPassthrough(onBytes) {
3594
- let total = 0;
3595
- return new Transform({ transform(chunk, _encoding, callback) {
3596
- if (Buffer.isBuffer(chunk)) total += chunk.byteLength;
3597
- onBytes?.(total);
3598
- callback(null, chunk);
3599
- } });
3600
- }
3601
- function toArchiveEntry(abs, dataDir, stat) {
3602
- const rel = path$1.relative(dataDir, abs).replace(/\\/g, "/");
3603
- const kind = stat.isDirectory() ? "dir" : stat.isSymbolicLink() ? "symlink" : "file";
3604
- return {
3605
- path: rel || path$1.basename(abs),
3606
- kind,
3607
- sizeBytes: kind === "file" ? stat.size : 0,
3608
- mtime: stat.mtimeMs
3609
- };
3610
- }
3611
- //#endregion
3612
7
  //#region ../../node_modules/croner/dist/croner.js
3613
8
  function T(s) {
3614
9
  return Date.UTC(s.y, s.m - 1, s.d, s.h, s.i, s.s);
@@ -4678,6 +1073,131 @@ async function downloadArchiveToCache(input) {
4678
1073
  }
4679
1074
  }
4680
1075
  //#endregion
1076
+ //#region src/builtins/backup-orchestrator/encryption-key-store.ts
1077
+ /**
1078
+ * @durable class=config owner=backup-orchestrator
1079
+ * write="`setupEncryption` inserts one row per generated key and retires the
1080
+ * previous active row; `disableEncryption` retires the active row"
1081
+ * retention="none — one small row per key ever generated; a retired row
1082
+ * names the key older archives need"
1083
+ */
1084
+ var BACKUP_ENCRYPTION_KEYS_COLLECTION = "backup_encryption_keys";
1085
+ var COLUMNS = [
1086
+ {
1087
+ name: "key_id",
1088
+ type: "TEXT",
1089
+ primaryKey: true
1090
+ },
1091
+ {
1092
+ name: "public_key",
1093
+ type: "TEXT",
1094
+ notNull: true
1095
+ },
1096
+ {
1097
+ name: "created_at",
1098
+ type: "INTEGER",
1099
+ notNull: true
1100
+ },
1101
+ {
1102
+ name: "retired_at",
1103
+ type: "INTEGER"
1104
+ }
1105
+ ];
1106
+ var BackupEncryptionKeyStore = class {
1107
+ store;
1108
+ now;
1109
+ declared = false;
1110
+ constructor(store, now = Date.now) {
1111
+ this.store = store;
1112
+ this.now = now;
1113
+ }
1114
+ async ensureDeclared() {
1115
+ if (this.declared) return;
1116
+ await this.store.declareCollection({
1117
+ collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
1118
+ columns: COLUMNS
1119
+ });
1120
+ this.declared = true;
1121
+ }
1122
+ /** Every key, newest first. */
1123
+ async list() {
1124
+ await this.ensureDeclared();
1125
+ const rows = await this.store.query({
1126
+ collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
1127
+ filter: { orderBy: {
1128
+ field: "created_at",
1129
+ direction: "desc"
1130
+ } }
1131
+ });
1132
+ const out = [];
1133
+ for (const row of rows) {
1134
+ const record = toRecord(row.data);
1135
+ if (record !== null) out.push(record);
1136
+ }
1137
+ return out;
1138
+ }
1139
+ /** The key new archives are encrypted to; `null` = encryption off. */
1140
+ async active() {
1141
+ return (await this.list()).find((k) => k.retiredAt === null) ?? null;
1142
+ }
1143
+ /** Make `publicKey` the active key; the previous one is retired, kept listed. */
1144
+ async activate(input) {
1145
+ const parsed = parseBackupPublicKey(input.publicKey);
1146
+ const t = this.now();
1147
+ await this.retireActive(t);
1148
+ const record = {
1149
+ keyId: parsed.keyId,
1150
+ publicKey: input.publicKey.trim(),
1151
+ createdAt: t,
1152
+ retiredAt: null
1153
+ };
1154
+ await this.write(record);
1155
+ return record;
1156
+ }
1157
+ /** Encryption off: the active key is retired. Archives already made keep needing it. */
1158
+ async disable() {
1159
+ await this.retireActive(this.now());
1160
+ }
1161
+ async retireActive(at) {
1162
+ for (const key of await this.list()) if (key.retiredAt === null) await this.write({
1163
+ ...key,
1164
+ retiredAt: at
1165
+ });
1166
+ }
1167
+ async write(record) {
1168
+ await this.ensureDeclared();
1169
+ await this.store.deleteWhere({
1170
+ collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
1171
+ filter: { where: { key_id: record.keyId } }
1172
+ });
1173
+ await this.store.insert({
1174
+ collection: BACKUP_ENCRYPTION_KEYS_COLLECTION,
1175
+ record: {
1176
+ id: record.keyId,
1177
+ data: {
1178
+ key_id: record.keyId,
1179
+ public_key: record.publicKey,
1180
+ created_at: record.createdAt,
1181
+ retired_at: record.retiredAt
1182
+ }
1183
+ }
1184
+ });
1185
+ }
1186
+ };
1187
+ function toRecord(row) {
1188
+ const keyId = row["key_id"];
1189
+ const publicKey = row["public_key"];
1190
+ const createdAt = row["created_at"];
1191
+ if (typeof keyId !== "string" || typeof publicKey !== "string") return null;
1192
+ const retired = row["retired_at"];
1193
+ return {
1194
+ keyId,
1195
+ publicKey,
1196
+ createdAt: typeof createdAt === "number" ? createdAt : Number(createdAt ?? 0),
1197
+ retiredAt: typeof retired === "number" ? retired : null
1198
+ };
1199
+ }
1200
+ //#endregion
4681
1201
  //#region src/builtins/backup-orchestrator/manifest-store.ts
4682
1202
  /** File path (relative to the location root) where the index lives. */
4683
1203
  var MANIFESTS_FILENAME = "manifests.json";
@@ -4748,7 +1268,8 @@ function normalizeManifest(raw) {
4748
1268
  createdAt: Number(cand["createdAt"]),
4749
1269
  sizeBytes: Number(cand["sizeBytes"]),
4750
1270
  ...typeof cand["label"] === "string" ? { label: cand["label"] } : {},
4751
- manifest
1271
+ manifest,
1272
+ ...encryptionOf(cand["encryption"])
4752
1273
  };
4753
1274
  archives.push(entry);
4754
1275
  }
@@ -4761,6 +1282,32 @@ var EMPTY_MANIFEST = {
4761
1282
  version: 1,
4762
1283
  archives: []
4763
1284
  };
1285
+ function encryptionOf(raw) {
1286
+ if (typeof raw !== "object" || raw === null) return {};
1287
+ const scheme = Reflect.get(raw, "scheme");
1288
+ const keyId = Reflect.get(raw, "keyId");
1289
+ if (typeof scheme !== "string" || typeof keyId !== "string") return {};
1290
+ return { encryption: {
1291
+ scheme,
1292
+ keyId
1293
+ } };
1294
+ }
1295
+ /**
1296
+ * What the destination's clear-text index may say about an encrypted archive:
1297
+ * the outline a restore needs (locations, sizes, the snapshot promise) — not
1298
+ * the list of files, which stays inside the ciphertext.
1299
+ */
1300
+ function outlineOfManifest(manifest) {
1301
+ return {
1302
+ archiveVersion: manifest.archiveVersion,
1303
+ createdAt: manifest.createdAt,
1304
+ dataDir: manifest.dataDir,
1305
+ locations: [...manifest.locations],
1306
+ entries: [],
1307
+ totalBytes: manifest.totalBytes,
1308
+ totalFiles: manifest.totalFiles
1309
+ };
1310
+ }
4764
1311
  /**
4765
1312
  * Build a `ManifestArchiveEntry` from the raw inputs collected during
4766
1313
  * a successful upload. Pure transform — no I/O — kept here so the
@@ -4773,7 +1320,8 @@ function buildArchiveEntry(input) {
4773
1320
  createdAt: input.createdAt,
4774
1321
  sizeBytes: input.sizeBytes,
4775
1322
  ...input.label !== void 0 ? { label: input.label } : {},
4776
- manifest: input.manifest
1323
+ manifest: input.encryption !== void 0 ? outlineOfManifest(input.manifest) : input.manifest,
1324
+ ...input.encryption !== void 0 ? { encryption: input.encryption } : {}
4777
1325
  };
4778
1326
  }
4779
1327
  /**
@@ -5466,6 +2014,9 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5466
2014
  systemBackup = null;
5467
2015
  policies = null;
5468
2016
  schedules = null;
2017
+ /** Backup encryption keys — PUBLIC keys only (see encryption-key-store.ts). */
2018
+ encryptionKeys = null;
2019
+ warnedNoEncryptionStore = false;
5469
2020
  dataDir = "";
5470
2021
  /**
5471
2022
  * Transient build buffer for archive fan-out. The tar is built here
@@ -5521,6 +2072,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5521
2072
  this.ctx.logger.error("backup-orchestrator: schedule table init failed", { meta: { error: err instanceof Error ? err.message : String(err) } });
5522
2073
  this.schedules = null;
5523
2074
  }
2075
+ const settingsStore = this.ctx.kernel.capabilityRegistry?.getSingleton("settings-store");
2076
+ this.encryptionKeys = settingsStore ? new BackupEncryptionKeyStore(settingsStore) : null;
5524
2077
  const provider = {
5525
2078
  listDestinations: () => this.listDestinations(),
5526
2079
  list: () => this.aggregatedList(),
@@ -5530,6 +2083,10 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5530
2083
  cancel: (input) => this.cancelRun(input),
5531
2084
  getEntries: (input) => this.getEntries(input),
5532
2085
  restore: (input) => this.scheduleRestore(input),
2086
+ getEncryption: () => this.getEncryption(),
2087
+ setupEncryption: () => this.setupEncryption(),
2088
+ disableEncryption: () => this.disableEncryption(),
2089
+ checkBackupKey: (input) => this.checkBackupKey(input),
5533
2090
  delete: (input) => this.deleteArchive(input),
5534
2091
  listArchives: (input) => this.listArchives(input),
5535
2092
  upsertDestinationPolicy: (input) => this.upsertDestinationPolicy(input),
@@ -5753,7 +2310,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5753
2310
  createdAt: a.createdAt,
5754
2311
  sizeBytes: a.sizeBytes,
5755
2312
  ...a.label !== void 0 ? { label: a.label } : {},
5756
- locations: [...a.manifest.locations]
2313
+ locations: [...a.manifest.locations],
2314
+ ...a.encryption !== void 0 ? { encryption: a.encryption } : {}
5757
2315
  };
5758
2316
  out.push(entry);
5759
2317
  }
@@ -5881,8 +2439,9 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5881
2439
  }
5882
2440
  progress.setDestinations(targets.map((t) => t.id));
5883
2441
  const policies = await this.loadPoliciesIndexed(targets.map((t) => t.id));
2442
+ const encryptTo = await this.activeEncryptionKey();
5884
2443
  const archiveId = randomUUID();
5885
- const archiveFilename = `${archiveId}.tar.gz`;
2444
+ const archiveFilename = encryptTo === null ? `${archiveId}.tar.gz` : `${archiveId}.tar.gz${ENCRYPTED_BACKUP_SUFFIX}`;
5886
2445
  const cachePath = await this.stagingPath(archiveFilename);
5887
2446
  let result;
5888
2447
  try {
@@ -5891,7 +2450,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5891
2450
  ...input.locations ? { locations: [...input.locations] } : {},
5892
2451
  signal,
5893
2452
  onArchiveBytes: (bytes) => progress.setStagedBytes(bytes),
5894
- owner: this.databaseOwner()
2453
+ owner: this.databaseOwner(),
2454
+ ...encryptTo !== null ? { encryptTo: encryptTo.publicKey } : {}
5895
2455
  });
5896
2456
  } catch (err) {
5897
2457
  if (err instanceof BackupSnapshotRefusedError) for (const dest of targets) {
@@ -5925,6 +2485,7 @@ var BackupOrchestratorAddon = class extends BaseAddon {
5925
2485
  retentionCount: input.retentionCount ?? policy.retentionCount,
5926
2486
  createdAt,
5927
2487
  label: formatArchiveLabel(dest.id, createdAt, input.label),
2488
+ ...result.encryption !== void 0 ? { encryption: result.encryption } : {},
5928
2489
  signal,
5929
2490
  onUploadedBytes: (bytes) => progress.setUploadedBytes(bytes)
5930
2491
  });
@@ -6046,7 +2607,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
6046
2607
  createdAt: input.createdAt,
6047
2608
  sizeBytes: input.sizeBytes,
6048
2609
  label: input.label,
6049
- manifest: input.archiveManifest
2610
+ manifest: input.archiveManifest,
2611
+ ...input.encryption !== void 0 ? { encryption: input.encryption } : {}
6050
2612
  });
6051
2613
  await this.manifestLock.run(input.locationId, async () => {
6052
2614
  const { keep, drop } = applyRetention([...(await readLocationManifest(this.storageApi(), input.locationId)).archives, entry], input.retentionCount);
@@ -6075,7 +2637,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
6075
2637
  createdAt: input.createdAt,
6076
2638
  sizeBytes: input.sizeBytes,
6077
2639
  label: input.label,
6078
- locations: [...input.archiveManifest.locations]
2640
+ locations: [...input.archiveManifest.locations],
2641
+ ...input.encryption !== void 0 ? { encryption: input.encryption } : {}
6079
2642
  };
6080
2643
  }
6081
2644
  /**
@@ -6101,7 +2664,8 @@ var BackupOrchestratorAddon = class extends BaseAddon {
6101
2664
  createdAt: a.createdAt,
6102
2665
  sizeBytes: a.sizeBytes,
6103
2666
  ...a.label !== void 0 ? { label: a.label } : {},
6104
- locations: [...a.manifest.locations]
2667
+ locations: [...a.manifest.locations],
2668
+ ...a.encryption !== void 0 ? { encryption: a.encryption } : {}
6105
2669
  }));
6106
2670
  }
6107
2671
  /**
@@ -6209,15 +2773,26 @@ var BackupOrchestratorAddon = class extends BaseAddon {
6209
2773
  if (!this.systemBackup) throw new Error("orchestrator not initialized");
6210
2774
  const entry = (await readLocationManifest(this.storageApi(), input.destinationId)).archives.find((a) => a.id === input.backupId);
6211
2775
  if (!entry) throw new Error(`backup restore: backup "${input.backupId}" not found at location "${input.destinationId}"`);
2776
+ precheckRestoreKey(entry.encryption?.keyId, input.backupSecretKey);
2777
+ const downloaded = await this.stagingPath(`restore-${input.backupId}.download`);
6212
2778
  const cachePath = await this.stagingPath(`restore-${input.backupId}.tar.gz`);
6213
2779
  await downloadArchiveToCache({
6214
2780
  api: this.ctx.api.storage,
6215
2781
  locationId: input.destinationId,
6216
2782
  filename: entry.filename,
6217
- cachePath,
2783
+ cachePath: downloaded,
6218
2784
  chunkBytes: UPLOAD_CHUNK_BYTES,
6219
2785
  logger: this.ctx.logger
6220
2786
  });
2787
+ const prepared = await prepareRestoreArchive({
2788
+ downloaded,
2789
+ target: cachePath,
2790
+ ...input.backupSecretKey !== void 0 ? { secretKey: input.backupSecretKey } : {}
2791
+ });
2792
+ if (prepared.encrypted) this.ctx.logger.info("backup restore: encrypted archive decrypted into staging", { meta: {
2793
+ backupId: input.backupId,
2794
+ keyId: prepared.keyId
2795
+ } });
6221
2796
  this.systemBackup.scheduleRestoreMarker({
6222
2797
  archivePath: cachePath,
6223
2798
  source: input.backupId,
@@ -6237,6 +2812,98 @@ var BackupOrchestratorAddon = class extends BaseAddon {
6237
2812
  }
6238
2813
  });
6239
2814
  }
2815
+ requireEncryptionKeys() {
2816
+ if (this.encryptionKeys === null) throw new Error("backup encryption: no settings-store — the setting cannot be read or saved");
2817
+ return this.encryptionKeys;
2818
+ }
2819
+ /**
2820
+ * The key a run encrypts to; `null` = encryption off. THROWS when the
2821
+ * setting cannot be read — a run must fail rather than ship a plain archive
2822
+ * an operator asked to be encrypted.
2823
+ */
2824
+ async activeEncryptionKey() {
2825
+ const store = this.encryptionKeys;
2826
+ if (store === null) {
2827
+ if (!this.warnedNoEncryptionStore) {
2828
+ this.warnedNoEncryptionStore = true;
2829
+ this.ctx.logger.warn("backup encryption unavailable on this node (no settings-store) — archives are plain");
2830
+ }
2831
+ return null;
2832
+ }
2833
+ try {
2834
+ const active = await store.active();
2835
+ return active === null ? null : {
2836
+ keyId: active.keyId,
2837
+ publicKey: active.publicKey
2838
+ };
2839
+ } catch (err) {
2840
+ const message = err instanceof Error ? err.message : String(err);
2841
+ throw new Error(`backup encryption setting unreadable — no archive built, so none leaves unencrypted: ${message}`, { cause: err });
2842
+ }
2843
+ }
2844
+ async getEncryption() {
2845
+ const keys = await this.requireEncryptionKeys().list();
2846
+ const active = keys.find((k) => k.retiredAt === null) ?? null;
2847
+ return {
2848
+ enabled: active !== null,
2849
+ active: active === null ? null : {
2850
+ keyId: active.keyId,
2851
+ publicKey: active.publicKey,
2852
+ createdAt: active.createdAt
2853
+ },
2854
+ keys: keys.map((k) => ({
2855
+ keyId: k.keyId,
2856
+ createdAt: k.createdAt,
2857
+ retiredAt: k.retiredAt
2858
+ }))
2859
+ };
2860
+ }
2861
+ async setupEncryption() {
2862
+ const store = this.requireEncryptionKeys();
2863
+ const previous = await store.active();
2864
+ const pair = generateBackupKeyPair();
2865
+ const record = await store.activate({ publicKey: pair.publicKey });
2866
+ this.ctx.logger.warn("backup encryption key generated — new archives are encrypted to it", { meta: {
2867
+ keyId: record.keyId,
2868
+ replacedKeyId: previous?.keyId ?? null
2869
+ } });
2870
+ return {
2871
+ keyId: record.keyId,
2872
+ secretKey: pair.secretKey,
2873
+ publicKey: record.publicKey,
2874
+ createdAt: record.createdAt,
2875
+ replacedKeyId: previous?.keyId ?? null
2876
+ };
2877
+ }
2878
+ async disableEncryption() {
2879
+ const store = this.requireEncryptionKeys();
2880
+ const previous = await store.active();
2881
+ await store.disable();
2882
+ if (previous !== null) this.ctx.logger.warn("backup encryption turned OFF — new archives are plain", { meta: { disabledKeyId: previous.keyId } });
2883
+ return { disabledKeyId: previous?.keyId ?? null };
2884
+ }
2885
+ async checkBackupKey(input) {
2886
+ let keyId;
2887
+ try {
2888
+ keyId = parseBackupSecretKey(input.backupSecretKey).keyId;
2889
+ } catch (err) {
2890
+ if (!(err instanceof BackupKeyFormatError)) throw err;
2891
+ return {
2892
+ valid: false,
2893
+ keyId: null,
2894
+ known: false,
2895
+ active: false,
2896
+ error: err.message
2897
+ };
2898
+ }
2899
+ const match = (await this.requireEncryptionKeys().list()).find((k) => k.keyId === keyId);
2900
+ return {
2901
+ valid: true,
2902
+ keyId,
2903
+ known: match !== void 0,
2904
+ active: match !== void 0 && match.retiredAt === null
2905
+ };
2906
+ }
6240
2907
  /**
6241
2908
  * Resolve a target destination set — see {@link selectBackupTargets} for the
6242
2909
  * rule. Caller-provided list wins over the per-destination policy flag;