home-hosted 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +319 -628
- package/dist/chunks/archive-DP-XQR8X.js +352 -0
- package/dist/chunks/archive-DP-XQR8X.js.map +1 -0
- package/dist/chunks/atomic-C1PfJpE7.js +26 -0
- package/dist/chunks/atomic-C1PfJpE7.js.map +1 -0
- package/dist/chunks/backup-CZcVca2a.js +822 -0
- package/dist/chunks/backup-CZcVca2a.js.map +1 -0
- package/dist/chunks/backups-CFRaWe_m.js +4691 -0
- package/dist/chunks/backups-CFRaWe_m.js.map +1 -0
- package/dist/chunks/config-text-DifCHhnz.js +50 -0
- package/dist/chunks/config-text-DifCHhnz.js.map +1 -0
- package/dist/chunks/contracts-CMBD1TF9.js +2230 -0
- package/dist/chunks/contracts-CMBD1TF9.js.map +1 -0
- package/dist/chunks/daemon-log-BVj8cDEo.js +241 -0
- package/dist/chunks/daemon-log-BVj8cDEo.js.map +1 -0
- package/dist/chunks/daemon-qKVECISl.js +247 -0
- package/dist/chunks/daemon-qKVECISl.js.map +1 -0
- package/dist/chunks/docker-Cy9Lyvda.js +437 -0
- package/dist/chunks/docker-Cy9Lyvda.js.map +1 -0
- package/dist/chunks/down-pKbGCW9d.js +383 -0
- package/dist/chunks/down-pKbGCW9d.js.map +1 -0
- package/dist/chunks/init-BZ7hK9Vf.js +276 -0
- package/dist/chunks/init-BZ7hK9Vf.js.map +1 -0
- package/dist/chunks/last-stop-C-BXz_XI.js +53 -0
- package/dist/chunks/last-stop-C-BXz_XI.js.map +1 -0
- package/dist/chunks/layout-DwTtmund.js +24 -0
- package/dist/chunks/layout-DwTtmund.js.map +1 -0
- package/dist/chunks/lazy-Ce5zEAq1.js +66 -0
- package/dist/chunks/lazy-Ce5zEAq1.js.map +1 -0
- package/dist/chunks/log-buffer-Dy9HHDMD.js +414 -0
- package/dist/chunks/log-buffer-Dy9HHDMD.js.map +1 -0
- package/dist/chunks/logger-B5U4GD3j.js +13 -0
- package/dist/chunks/logger-B5U4GD3j.js.map +1 -0
- package/dist/chunks/logs---TI_bxM.js +267 -0
- package/dist/chunks/logs---TI_bxM.js.map +1 -0
- package/dist/chunks/migrate-Cfoq-Vgh.js +155 -0
- package/dist/chunks/migrate-Cfoq-Vgh.js.map +1 -0
- package/dist/chunks/nanny-B-Eu0sFW.js +132 -0
- package/dist/chunks/nanny-B-Eu0sFW.js.map +1 -0
- package/dist/chunks/nanny-BtWfy0QH.js +1167 -0
- package/dist/chunks/nanny-BtWfy0QH.js.map +1 -0
- package/dist/chunks/nanny-ChMtq1Zl.js +39 -0
- package/dist/chunks/nanny-ChMtq1Zl.js.map +1 -0
- package/dist/chunks/nanny-sweep-DErnlPY1.js +105 -0
- package/dist/chunks/nanny-sweep-DErnlPY1.js.map +1 -0
- package/dist/chunks/nearest-6KgQEDUe.js +41 -0
- package/dist/chunks/nearest-6KgQEDUe.js.map +1 -0
- package/dist/chunks/parse-DhmG26fI.js +383 -0
- package/dist/chunks/parse-DhmG26fI.js.map +1 -0
- package/dist/chunks/paths-CGlGDrOU.js +206 -0
- package/dist/chunks/paths-CGlGDrOU.js.map +1 -0
- package/dist/chunks/port-B8WBTRMk.js +333 -0
- package/dist/chunks/port-B8WBTRMk.js.map +1 -0
- package/dist/chunks/restart-Des4DrAN.js +92 -0
- package/dist/chunks/restart-Des4DrAN.js.map +1 -0
- package/dist/chunks/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/chunks/schema-B240VXcV.js +103 -0
- package/dist/chunks/schema-B240VXcV.js.map +1 -0
- package/dist/chunks/secrets-BieELnZh.js +562 -0
- package/dist/chunks/secrets-BieELnZh.js.map +1 -0
- package/dist/chunks/server-Bge2r2qQ.js +169 -0
- package/dist/chunks/server-Bge2r2qQ.js.map +1 -0
- package/dist/chunks/server-ids-DRuNLVCV.js +32 -0
- package/dist/chunks/server-ids-DRuNLVCV.js.map +1 -0
- package/dist/chunks/set-password-D5vZqqSX.js +43 -0
- package/dist/chunks/set-password-D5vZqqSX.js.map +1 -0
- package/dist/chunks/set-token-obPiEJYk.js +78 -0
- package/dist/chunks/set-token-obPiEJYk.js.map +1 -0
- package/dist/chunks/settings-xu-XTfWg.js +423 -0
- package/dist/chunks/settings-xu-XTfWg.js.map +1 -0
- package/dist/chunks/setup-temp-CAN4_bA-.js +150 -0
- package/dist/chunks/setup-temp-CAN4_bA-.js.map +1 -0
- package/dist/chunks/shape-DnTKzjQ2.js +24 -0
- package/dist/chunks/shape-DnTKzjQ2.js.map +1 -0
- package/dist/chunks/src-BtWMFmzZ.js +12338 -0
- package/dist/chunks/src-BtWMFmzZ.js.map +1 -0
- package/dist/chunks/status-DT1EsA-B.js +123 -0
- package/dist/chunks/status-DT1EsA-B.js.map +1 -0
- package/dist/chunks/ui-D562aqw5.js +325 -0
- package/dist/chunks/ui-D562aqw5.js.map +1 -0
- package/dist/chunks/ui-dir-CsU3uLNV.js +39 -0
- package/dist/chunks/ui-dir-CsU3uLNV.js.map +1 -0
- package/dist/chunks/ui-release-DKzVvlLd.js +312 -0
- package/dist/chunks/ui-release-DKzVvlLd.js.map +1 -0
- package/dist/chunks/ui-revert-EkBBwRTt.js +27 -0
- package/dist/chunks/ui-revert-EkBBwRTt.js.map +1 -0
- package/dist/chunks/ui-switch-BnZTdMDd.js +150 -0
- package/dist/chunks/ui-switch-BnZTdMDd.js.map +1 -0
- package/dist/chunks/ui-update-_xryLYxw.js +272 -0
- package/dist/chunks/ui-update-_xryLYxw.js.map +1 -0
- package/dist/chunks/up-Pdz-l6IH.js +210 -0
- package/dist/chunks/up-Pdz-l6IH.js.map +1 -0
- package/dist/chunks/usage-DFrCVXpT.js +111 -0
- package/dist/chunks/usage-DFrCVXpT.js.map +1 -0
- package/dist/chunks/workspaces-DYcfvKV_.js +229 -0
- package/dist/chunks/workspaces-DYcfvKV_.js.map +1 -0
- package/dist/chunks/wsl-temperature-BiCI4iK6.js +322 -0
- package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +1 -0
- package/dist/cli.js +441 -25418
- package/dist/cli.js.map +1 -1
- package/dist/client.js +144 -0
- package/dist/client.js.map +1 -0
- package/dist/types/api/acme.d.ts +24 -0
- package/dist/types/api/auth/$.routes.d.ts +103 -0
- package/dist/types/api/backups.d.ts +184 -0
- package/dist/types/api/control.d.ts +470 -0
- package/dist/types/api/ddns.d.ts +432 -0
- package/dist/types/api/events.d.ts +22 -0
- package/dist/types/api/health.d.ts +28 -0
- package/dist/types/api/logs.d.ts +95 -0
- package/dist/types/api/metrics.d.ts +21 -0
- package/dist/types/api/notifications.d.ts +141 -0
- package/dist/types/api/proxy.d.ts +1128 -0
- package/dist/types/api/servers/$.routes.d.ts +1318 -0
- package/dist/types/api/settings.d.ts +642 -0
- package/dist/types/api/state.d.ts +498 -0
- package/dist/types/api/static.d.ts +11 -0
- package/dist/types/api/tls.d.ts +112 -0
- package/dist/types/api/workspaces/$.routes.d.ts +797 -0
- package/dist/types/api/wsl-temperature.d.ts +113 -0
- package/dist/types/app.d.ts +6095 -0
- package/dist/types/cli/args.d.ts +75 -0
- package/dist/types/cli/backup-offline.d.ts +23 -0
- package/dist/types/cli/backup.d.ts +86 -0
- package/dist/types/cli/down.d.ts +80 -0
- package/dist/types/cli/init.d.ts +60 -0
- package/dist/types/cli/io.d.ts +65 -0
- package/dist/types/cli/logs.d.ts +76 -0
- package/dist/types/cli/migrate.d.ts +33 -0
- package/dist/types/cli/nanny.d.ts +19 -0
- package/dist/types/cli/nearest.d.ts +10 -0
- package/dist/types/cli/restart.d.ts +41 -0
- package/dist/types/cli/server.d.ts +68 -0
- package/dist/types/cli/set-password.d.ts +14 -0
- package/dist/types/cli/set-token.d.ts +21 -0
- package/dist/types/cli/setup-temp.d.ts +65 -0
- package/dist/types/cli/status.d.ts +14 -0
- package/dist/types/cli/ui-revert.d.ts +3 -0
- package/dist/types/cli/ui-switch.d.ts +27 -0
- package/dist/types/cli/ui-update.d.ts +72 -0
- package/dist/types/cli/up.d.ts +96 -0
- package/dist/types/cli/usage.d.ts +23 -0
- package/dist/types/cli.d.ts +12 -0
- package/dist/types/client.d.ts +11891 -0
- package/dist/types/config/layout.d.ts +11 -0
- package/dist/types/config/migrations.d.ts +69 -0
- package/dist/types/config/parse.d.ts +54 -0
- package/dist/types/config/patch.d.ts +20 -0
- package/dist/types/config/schema.d.ts +318 -0
- package/dist/types/config/secret-parts.d.ts +48 -0
- package/dist/types/config/secrets.d.ts +208 -0
- package/dist/types/config/seed.d.ts +30 -0
- package/dist/types/config/server-ids.d.ts +14 -0
- package/dist/types/config/settings.d.ts +120 -0
- package/dist/types/config/store.d.ts +145 -0
- package/dist/types/config/workspaces.d.ts +99 -0
- package/dist/types/helpers/action-result.d.ts +46 -0
- package/dist/types/helpers/atomic.d.ts +9 -0
- package/dist/types/helpers/backoff.d.ts +7 -0
- package/dist/types/helpers/bind.d.ts +16 -0
- package/dist/types/helpers/config-text.d.ts +23 -0
- package/dist/types/helpers/cookies.d.ts +19 -0
- package/dist/types/helpers/copy-tree.d.ts +20 -0
- package/dist/types/helpers/daemon-log.d.ts +45 -0
- package/dist/types/helpers/daemon.d.ts +135 -0
- package/dist/types/helpers/deferred.d.ts +7 -0
- package/dist/types/helpers/env-file.d.ts +20 -0
- package/dist/types/helpers/error.d.ts +26 -0
- package/dist/types/helpers/event-stream.d.ts +21 -0
- package/dist/types/helpers/factory.d.ts +6 -0
- package/dist/types/helpers/last-stop.d.ts +20 -0
- package/dist/types/helpers/logger.d.ts +7 -0
- package/dist/types/helpers/open.d.ts +2 -0
- package/dist/types/helpers/openapi.d.ts +34 -0
- package/dist/types/helpers/paths.d.ts +112 -0
- package/dist/types/helpers/restore-lock.d.ts +32 -0
- package/dist/types/helpers/runtime.d.ts +18 -0
- package/dist/types/helpers/secret-compare.d.ts +13 -0
- package/dist/types/helpers/shell.d.ts +19 -0
- package/dist/types/helpers/sse.d.ts +23 -0
- package/dist/types/helpers/template.d.ts +8 -0
- package/dist/types/helpers/ui-dir.d.ts +11 -0
- package/dist/types/helpers/utf8-chunks.d.ts +15 -0
- package/dist/types/helpers/validate.d.ts +7 -0
- package/dist/types/helpers/validator.d.ts +12 -0
- package/dist/types/helpers/version.d.ts +10 -0
- package/dist/types/helpers/workspace.d.ts +25 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/middleware/auth.d.ts +53 -0
- package/dist/types/middleware/host.d.ts +29 -0
- package/dist/types/middleware/loopback.d.ts +18 -0
- package/dist/types/openapi-reference.d.ts +22 -0
- package/dist/types/openapi.d.ts +34 -0
- package/dist/types/providers/archive.d.ts +54 -0
- package/dist/types/providers/backup-hook.d.ts +34 -0
- package/dist/types/providers/ddns/cloudflare.d.ts +2 -0
- package/dist/types/providers/ddns/desec.d.ts +2 -0
- package/dist/types/providers/ddns/digitalocean.d.ts +2 -0
- package/dist/types/providers/ddns/duckdns.d.ts +2 -0
- package/dist/types/providers/ddns/dyndns2.d.ts +15 -0
- package/dist/types/providers/ddns/dynu.d.ts +2 -0
- package/dist/types/providers/ddns/freedns.d.ts +2 -0
- package/dist/types/providers/ddns/gandi.d.ts +2 -0
- package/dist/types/providers/ddns/godaddy.d.ts +2 -0
- package/dist/types/providers/ddns/henet.d.ts +3 -0
- package/dist/types/providers/ddns/index.d.ts +12 -0
- package/dist/types/providers/ddns/ip.d.ts +27 -0
- package/dist/types/providers/ddns/namecheap-api.d.ts +13 -0
- package/dist/types/providers/ddns/namecheap.d.ts +6 -0
- package/dist/types/providers/ddns/noip.d.ts +2 -0
- package/dist/types/providers/ddns/porkbun.d.ts +2 -0
- package/dist/types/providers/ddns/spaceship.d.ts +7 -0
- package/dist/types/providers/ddns/types.d.ts +98 -0
- package/dist/types/providers/ddns/zone.d.ts +11 -0
- package/dist/types/providers/docker.d.ts +117 -0
- package/dist/types/providers/entry-state.d.ts +15 -0
- package/dist/types/providers/health-check.d.ts +27 -0
- package/dist/types/providers/host.d.ts +147 -0
- package/dist/types/providers/identity.d.ts +54 -0
- package/dist/types/providers/log-tail.d.ts +56 -0
- package/dist/types/providers/nanny-sweep.d.ts +54 -0
- package/dist/types/providers/nanny.d.ts +104 -0
- package/dist/types/providers/port.d.ts +142 -0
- package/dist/types/providers/proc.d.ts +125 -0
- package/dist/types/providers/process.d.ts +78 -0
- package/dist/types/providers/proxy/caddy.d.ts +2 -0
- package/dist/types/providers/proxy/index.d.ts +7 -0
- package/dist/types/providers/proxy/types.d.ts +54 -0
- package/dist/types/providers/server-vars.d.ts +4 -0
- package/dist/types/providers/telegram.d.ts +74 -0
- package/dist/types/providers/ui-release.d.ts +113 -0
- package/dist/types/providers/webhook.d.ts +64 -0
- package/dist/types/providers/wsl-temperature.d.ts +65 -0
- package/dist/types/services/acme-challenge.d.ts +44 -0
- package/dist/types/services/auth.d.ts +177 -0
- package/dist/types/services/backups.d.ts +476 -0
- package/dist/types/services/config-watch.d.ts +40 -0
- package/dist/types/services/control-server.d.ts +58 -0
- package/dist/types/services/ddns.d.ts +72 -0
- package/dist/types/services/dependencies.d.ts +21 -0
- package/dist/types/services/events.d.ts +17 -0
- package/dist/types/services/exposure.d.ts +86 -0
- package/dist/types/services/history.d.ts +37 -0
- package/dist/types/services/host-monitor.d.ts +33 -0
- package/dist/types/services/init.d.ts +71 -0
- package/dist/types/services/log-buffer.d.ts +39 -0
- package/dist/types/services/log-files.d.ts +77 -0
- package/dist/types/services/log-relay.d.ts +35 -0
- package/dist/types/services/nanny.d.ts +14 -0
- package/dist/types/services/notifications.d.ts +124 -0
- package/dist/types/services/panel.d.ts +213 -0
- package/dist/types/services/proxy-certificates/certificates.d.ts +116 -0
- package/dist/types/services/proxy-config.d.ts +83 -0
- package/dist/types/services/proxy.d.ts +431 -0
- package/dist/types/services/state.d.ts +38 -0
- package/dist/types/services/supervisor/compose.d.ts +17 -0
- package/dist/types/services/supervisor/entry.d.ts +149 -0
- package/dist/types/services/supervisor/health.d.ts +56 -0
- package/dist/types/services/supervisor/output.d.ts +126 -0
- package/dist/types/services/supervisor/pending-load.d.ts +6 -0
- package/dist/types/services/supervisor/persistent.d.ts +58 -0
- package/dist/types/services/supervisor/port-preflight.d.ts +45 -0
- package/dist/types/services/supervisor/records.d.ts +118 -0
- package/dist/types/services/supervisor/spawn.d.ts +15 -0
- package/dist/types/services/supervisor/view.d.ts +4 -0
- package/dist/types/services/supervisor.d.ts +145 -0
- package/dist/types/services/tls.d.ts +48 -0
- package/dist/types/services/ui-update.d.ts +44 -0
- package/dist/types/services/ui.d.ts +50 -0
- package/dist/types/shared/action-outcome.d.ts +25 -0
- package/dist/types/shared/api-client.d.ts +351 -0
- package/dist/types/shared/backup-scope.d.ts +167 -0
- package/dist/types/shared/clone.d.ts +14 -0
- package/dist/types/shared/contracts.d.ts +4175 -0
- package/dist/types/shared/cpu-scale.d.ts +25 -0
- package/dist/types/shared/ddns-form.d.ts +75 -0
- package/dist/types/shared/endpoint.d.ts +8 -0
- package/dist/types/shared/error-message.d.ts +8 -0
- package/dist/types/shared/fields.d.ts +21 -0
- package/dist/types/shared/form-repair.d.ts +6 -0
- package/dist/types/shared/generated.d.ts +26 -0
- package/dist/types/shared/host-readings.d.ts +185 -0
- package/dist/types/shared/lazy.d.ts +4 -0
- package/dist/types/shared/live-frames.d.ts +22 -0
- package/dist/types/shared/live-series.d.ts +21 -0
- package/dist/types/shared/live-store.d.ts +72 -0
- package/dist/types/shared/patch-diff.d.ts +105 -0
- package/dist/types/shared/probe-latency.d.ts +25 -0
- package/dist/types/shared/proxy-form.d.ts +184 -0
- package/dist/types/shared/server-attention.d.ts +37 -0
- package/dist/types/shared/server-form.d.ts +121 -0
- package/dist/types/shared/server-key.d.ts +13 -0
- package/dist/types/shared/server-readings.d.ts +55 -0
- package/dist/types/shared/server-url.d.ts +43 -0
- package/dist/types/shared/shape.d.ts +17 -0
- package/dist/types/shared/stream-access.d.ts +20 -0
- package/dist/types/shared/ui-format.d.ts +89 -0
- package/docs/API.md +209 -0
- package/docs/BACKUPS.md +117 -0
- package/docs/CLI.md +95 -0
- package/docs/DDNS.md +11 -1
- package/docs/NOTIFICATIONS.md +7 -1
- package/docs/REVERSE_PROXY.md +9 -3
- package/docs/SECURITY.md +93 -0
- package/docs/SERVERS.md +141 -34
- package/docs/UI_CREATION.md +91 -291
- package/docs/demo/blank-host-restore.sh +4 -3
- package/package.json +22 -14
- package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +1 -0
- package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +1 -0
- package/uis/stock/dist/assets/LogViewer-DIliXy62.js +1 -0
- package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +1 -0
- package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +39 -0
- package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +1 -0
- package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +2 -0
- package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +1 -0
- package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +2 -0
- package/uis/stock/dist/assets/de-BRITeb0H.js +1 -0
- package/uis/stock/dist/assets/es-B2zIEssV.js +1 -0
- package/uis/stock/dist/assets/fr-s0ZOBEqh.js +1 -0
- package/uis/stock/dist/assets/index-C1MehbKy.css +2 -0
- package/uis/stock/dist/assets/index-CnBN54wF.js +15 -0
- package/uis/stock/dist/assets/ja-CU7MR85V.js +1 -0
- package/uis/stock/dist/assets/ko-tL5Me6d-.js +1 -0
- package/uis/stock/dist/assets/ru-92yrvkNJ.js +1 -0
- package/uis/stock/dist/assets/vi-CzvY16k2.js +1 -0
- package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +1 -0
- package/uis/stock/dist/index.html +3 -2
- package/uis/stock/dist/ui.json +3 -3
- package/docs/RESTORE_DEMO.md +0 -306
- package/uis/stock/dist/assets/de-0YLueNal.js +0 -1
- package/uis/stock/dist/assets/es-FCHhRmn2.js +0 -1
- package/uis/stock/dist/assets/fr-C69Z8o0z.js +0 -1
- package/uis/stock/dist/assets/index-Cok5msAO.css +0 -2
- package/uis/stock/dist/assets/index-KdyqrVv8.js +0 -53
- package/uis/stock/dist/assets/ja-Chz9YOqR.js +0 -1
- package/uis/stock/dist/assets/ko-CtXZ2x1l.js +0 -1
- package/uis/stock/dist/assets/ru-D_jE64xN.js +0 -1
- package/uis/stock/dist/assets/vi-sxSffss7.js +0 -1
- package/uis/stock/dist/assets/zh-CN-ChTpf29X.js +0 -1
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { Buffer } from "node:buffer";
|
|
5
|
+
import { DetailedError } from "@namesmt/utils";
|
|
6
|
+
import { performance } from "node:perf_hooks";
|
|
7
|
+
import { setImmediate } from "node:timers/promises";
|
|
8
|
+
import { Readable, Writable } from "node:stream";
|
|
9
|
+
import { finished } from "node:stream/promises";
|
|
10
|
+
import { BlobReader, ZipReader, ZipWriter, configure } from "@zip.js/zip.js";
|
|
11
|
+
//#region src/helpers/copy-tree.ts
|
|
12
|
+
/** How long a tree operation may hold the event loop before the panel gets a turn. */
|
|
13
|
+
var SLICE_MS = 10;
|
|
14
|
+
/**
|
|
15
|
+
* A checkpoint that yields to the event loop once `SLICE_MS` of synchronous work has passed.
|
|
16
|
+
*
|
|
17
|
+
* Sync calls in slices, not `fs.promises`: every async call is a thread-pool round trip, which made a
|
|
18
|
+
* tree of small files 10-20x slower to copy and walk than the sync calls it replaced.
|
|
19
|
+
*/
|
|
20
|
+
function eventLoopSlicer() {
|
|
21
|
+
let since = performance.now();
|
|
22
|
+
return async () => {
|
|
23
|
+
if (performance.now() - since < SLICE_MS) return;
|
|
24
|
+
await setImmediate();
|
|
25
|
+
since = performance.now();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* `fs.cpSync(source, target, { recursive: true, force: true, filter })`, yielding between entries.
|
|
30
|
+
*
|
|
31
|
+
* Every non-directory entry is still copied by `cpSync`, so links, modes and special files behave as
|
|
32
|
+
* they did; only the directory recursion is here, in cp's order — a directory this call creates gets
|
|
33
|
+
* its source mode after its contents are written.
|
|
34
|
+
*
|
|
35
|
+
* The two roots are dereferenced: a declared `data -> /mnt/disk/data` *is* the data, so it is copied
|
|
36
|
+
* as its target rather than as a link (which the archive walk then drops as outside the tree, leaving
|
|
37
|
+
* an empty capture), and a restore writes into the directory a linked target names instead of
|
|
38
|
+
* refusing it as a non-directory. Links *below* the roots are untouched.
|
|
39
|
+
*/
|
|
40
|
+
async function copyTree(source, target, filter) {
|
|
41
|
+
const slice = eventLoopSlicer();
|
|
42
|
+
const visit = async (from, to) => {
|
|
43
|
+
if (!filter(from, to)) return;
|
|
44
|
+
await slice();
|
|
45
|
+
const stats = fs.lstatSync(from);
|
|
46
|
+
if (!stats.isDirectory()) {
|
|
47
|
+
fs.cpSync(from, to, {
|
|
48
|
+
recursive: true,
|
|
49
|
+
force: true
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const existing = fs.lstatSync(to, { throwIfNoEntry: false });
|
|
54
|
+
if (existing !== void 0 && !existing.isDirectory()) throw new DetailedError(`cannot overwrite non-directory ${to} with directory ${from}`, { code: "ERR_FS_CP_DIR_TO_NON_DIR" });
|
|
55
|
+
if (existing === void 0) fs.mkdirSync(to);
|
|
56
|
+
for (const name of fs.readdirSync(from)) await visit(path.join(from, name), path.join(to, name));
|
|
57
|
+
if (existing === void 0) fs.chmodSync(to, stats.mode);
|
|
58
|
+
};
|
|
59
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
60
|
+
await visit(realpathOr(source), realpathOr(target));
|
|
61
|
+
}
|
|
62
|
+
/** The path a link names, or the path itself when it does not resolve (absent, dangling). */
|
|
63
|
+
function realpathOr(target) {
|
|
64
|
+
try {
|
|
65
|
+
return fs.realpathSync(target);
|
|
66
|
+
} catch {
|
|
67
|
+
return target;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/providers/archive.ts
|
|
72
|
+
/**
|
|
73
|
+
* Backups are ordinary zip files: the same container whether or not they are
|
|
74
|
+
* password-protected, openable by any archive manager (including the one built
|
|
75
|
+
* into Windows and macOS), and produced without a native binary — zip.js is pure
|
|
76
|
+
* JavaScript.
|
|
77
|
+
*
|
|
78
|
+
* A password means WinZip AES-256 (`encryptionStrength: 3`, AE-2): strong, and
|
|
79
|
+
* still standard, unlike the legacy ZipCrypto encryption.
|
|
80
|
+
*/
|
|
81
|
+
configure({ useWebWorkers: false });
|
|
82
|
+
var ZIPS = [
|
|
83
|
+
[
|
|
84
|
+
80,
|
|
85
|
+
75,
|
|
86
|
+
3,
|
|
87
|
+
4
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
80,
|
|
91
|
+
75,
|
|
92
|
+
5,
|
|
93
|
+
6
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
80,
|
|
97
|
+
75,
|
|
98
|
+
7,
|
|
99
|
+
8
|
|
100
|
+
]
|
|
101
|
+
];
|
|
102
|
+
/** Recognised by content, never by the file's name. */
|
|
103
|
+
function isZipArchive(file) {
|
|
104
|
+
let fd = null;
|
|
105
|
+
try {
|
|
106
|
+
fd = fs.openSync(file, "r");
|
|
107
|
+
const head = Buffer.alloc(4);
|
|
108
|
+
return fs.readSync(fd, head, 0, 4, 0) === 4 && ZIPS.some((magic) => magic.every((byte, index) => head[index] === byte));
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
} finally {
|
|
112
|
+
if (fd !== null) fs.closeSync(fd);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The central directory is not encrypted, so this works without a password. */
|
|
116
|
+
async function listZip(file) {
|
|
117
|
+
const reader = await open(file);
|
|
118
|
+
try {
|
|
119
|
+
return (await reader.getEntries()).map((entry) => ({
|
|
120
|
+
name: entry.filename,
|
|
121
|
+
directory: entry.directory === true,
|
|
122
|
+
encrypted: entry.encrypted === true,
|
|
123
|
+
symlink: entry.symlink === true,
|
|
124
|
+
size: entry.uncompressedSize ?? 0,
|
|
125
|
+
...entry.unixMode === void 0 ? {} : { mode: entry.unixMode }
|
|
126
|
+
}));
|
|
127
|
+
} finally {
|
|
128
|
+
await reader.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* True when the archive rejected the password we used.
|
|
133
|
+
*
|
|
134
|
+
* Matched on the wording zip.js raises for a bad password, not on the word alone: the message is
|
|
135
|
+
* `Invalid password`, while a *file it cannot open* produces `ENOENT: … stat '/tmp/…/my-password-
|
|
136
|
+
* backup.zip'` — which carries the word because the caller named the archive that. A substring test
|
|
137
|
+
* read that as a wrong password and told the person to re-enter one, when the archive was simply
|
|
138
|
+
* not there. (Caught by CI, where Node's fs message names the path; the local run said
|
|
139
|
+
* `Unable to open file as blob`, so the same call looked fine.)
|
|
140
|
+
*/
|
|
141
|
+
function isInvalidPassword(error) {
|
|
142
|
+
return error instanceof Error && /invalid password/i.test(error.message);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Writes the contents of `sourceDir` into `destination`, preserving the tree and each
|
|
146
|
+
* entry's permission bits.
|
|
147
|
+
*
|
|
148
|
+
* The mode is captured because the tree is somebody's data directory: a `0600` key, a `0700`
|
|
149
|
+
* directory and a `0755` script are all routine there, and a backup that restores them as `0644`
|
|
150
|
+
* changes who can read the data it was taken to protect. What a symlink may bring in is bounded by
|
|
151
|
+
* the tree itself (`walk`): the target has to be inside it, so a declared path cannot capture bytes
|
|
152
|
+
* from outside itself. Streams from disk to disk: nothing is buffered whole.
|
|
153
|
+
*/
|
|
154
|
+
async function createZip(sourceDir, destination, options = {}) {
|
|
155
|
+
const partial = path.join(path.dirname(destination), `.${path.basename(destination)}.partial`);
|
|
156
|
+
const output = fs.createWriteStream(partial, { mode: 384 });
|
|
157
|
+
const flushed = finished(output);
|
|
158
|
+
const writer = Writable.toWeb(output);
|
|
159
|
+
const zip = new ZipWriter(writer, {
|
|
160
|
+
...options.password === void 0 ? {} : {
|
|
161
|
+
password: options.password,
|
|
162
|
+
encryptionStrength: 3
|
|
163
|
+
},
|
|
164
|
+
level: 6,
|
|
165
|
+
keepOrder: true
|
|
166
|
+
});
|
|
167
|
+
try {
|
|
168
|
+
for (const item of await walk(sourceDir)) {
|
|
169
|
+
const mode = item.mode === null ? {} : { unixMode: item.mode };
|
|
170
|
+
if (item.directory) await zip.add(item.name, null, {
|
|
171
|
+
directory: true,
|
|
172
|
+
...mode
|
|
173
|
+
});
|
|
174
|
+
else if (item.size === 0) await zip.add(item.name, null, {
|
|
175
|
+
directory: false,
|
|
176
|
+
...mode
|
|
177
|
+
});
|
|
178
|
+
else await zip.add(item.name, Readable.toWeb(fs.createReadStream(item.absolute)), mode);
|
|
179
|
+
}
|
|
180
|
+
await zip.close();
|
|
181
|
+
await flushed;
|
|
182
|
+
await fs.promises.rename(partial, destination);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
await writer.abort(error).catch(() => {});
|
|
185
|
+
await flushed.catch(() => {});
|
|
186
|
+
await fs.promises.rm(partial, { force: true }).catch(() => {});
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Extracts the given entries (already validated by the caller) into
|
|
192
|
+
* `destination`. Symbolic links are never recreated — an archive is not allowed
|
|
193
|
+
* to make the filesystem point somewhere else.
|
|
194
|
+
*
|
|
195
|
+
* An entry's permission bits are applied after it lands. The file is created under a restrictive
|
|
196
|
+
* mode first, so a `0600` secret never exists world-readable between two calls, and a mode the
|
|
197
|
+
* current umask would widen is set with an explicit `chmod` rather than left to the create.
|
|
198
|
+
*/
|
|
199
|
+
async function extractZip(file, destination, options) {
|
|
200
|
+
const reader = await open(file, options.password);
|
|
201
|
+
const skipped = [];
|
|
202
|
+
/** Directory modes, applied after their contents: a `0700` dir cannot be written into. */
|
|
203
|
+
const pendingDirModes = [];
|
|
204
|
+
try {
|
|
205
|
+
const entries = new Map((await reader.getEntries()).map((entry) => [entry.filename, entry]));
|
|
206
|
+
for (const name of options.names) {
|
|
207
|
+
const entry = entries.get(name);
|
|
208
|
+
if (entry === void 0) {
|
|
209
|
+
skipped.push(name);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const target = path.join(destination, name);
|
|
213
|
+
if (entry.directory) {
|
|
214
|
+
fs.mkdirSync(target, { recursive: true });
|
|
215
|
+
const mode = permissionBits(entry.unixMode);
|
|
216
|
+
if (mode !== null) pendingDirModes.push({
|
|
217
|
+
target,
|
|
218
|
+
mode
|
|
219
|
+
});
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (entry.symlink) {
|
|
223
|
+
skipped.push(name);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
227
|
+
await entry.getData(Writable.toWeb(fs.createWriteStream(target, { mode: 384 })), writeOptions(entry, options.password));
|
|
228
|
+
const mode = permissionBits(entry.unixMode);
|
|
229
|
+
if (mode !== null) try {
|
|
230
|
+
fs.chmodSync(target, mode);
|
|
231
|
+
} catch {}
|
|
232
|
+
}
|
|
233
|
+
} finally {
|
|
234
|
+
await reader.close();
|
|
235
|
+
for (const { target, mode } of pendingDirModes.sort((left, right) => right.target.length - left.target.length)) try {
|
|
236
|
+
fs.chmodSync(target, mode);
|
|
237
|
+
} catch {}
|
|
238
|
+
pendingDirModes.length = 0;
|
|
239
|
+
}
|
|
240
|
+
return { skipped };
|
|
241
|
+
}
|
|
242
|
+
function writeOptions(entry, password) {
|
|
243
|
+
return entry.encrypted && password !== void 0 ? { password } : {};
|
|
244
|
+
}
|
|
245
|
+
async function open(file, password) {
|
|
246
|
+
const blob = await fs.openAsBlob(file, { type: "application/zip" });
|
|
247
|
+
return password === void 0 ? new ZipReader(new BlobReader(blob)) : new ZipReader(new BlobReader(blob), { password });
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The `st_mode` an entry should carry, or `null` where the platform does not report one.
|
|
251
|
+
*
|
|
252
|
+
* Only the permission bits and the file type are kept: the archive records a mode, not an owner,
|
|
253
|
+
* because a restore runs as whoever restores it and a foreign uid would be a worse lie than the
|
|
254
|
+
* restoring user's own.
|
|
255
|
+
*/
|
|
256
|
+
function archiveMode(stats) {
|
|
257
|
+
const bits = stats.mode & 511;
|
|
258
|
+
if (process.platform === "win32" || bits === 0) return null;
|
|
259
|
+
return (stats.isDirectory() ? 16384 : 32768) | bits;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The permission bits an extracted entry should be given, or `null` when the archive carries none.
|
|
263
|
+
*
|
|
264
|
+
* Zip stores the type in the same field, so the file type is dropped: the entry is written as the
|
|
265
|
+
* ordinary file or directory this call is creating, never as a fifo or a device node an archive
|
|
266
|
+
* could name. The setuid/setgid/sticky bits are dropped too — an archive from another host does not
|
|
267
|
+
* get to install a privileged binary here.
|
|
268
|
+
*/
|
|
269
|
+
function permissionBits(unixMode) {
|
|
270
|
+
if (unixMode === void 0 || unixMode === 0) return null;
|
|
271
|
+
const bits = unixMode & 511;
|
|
272
|
+
return bits === 0 ? null : bits;
|
|
273
|
+
}
|
|
274
|
+
/** True when `child` is `parent` itself or lives underneath it, after resolving both. */
|
|
275
|
+
function isUnderResolved(parent, child) {
|
|
276
|
+
const relative = path.relative(parent, child);
|
|
277
|
+
return relative === "" || !path.isAbsolute(relative) && !relative.startsWith("..");
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Sorted, deterministic walk with directory loops broken and the declared tree respected.
|
|
281
|
+
*
|
|
282
|
+
* Every read is best-effort: a directory that vanishes mid-walk (a rotated log, a
|
|
283
|
+
* build directory being cleaned, a container being torn down) must leave it out of
|
|
284
|
+
* the archive rather than reject `createZip` and turn a backup into a failure.
|
|
285
|
+
*
|
|
286
|
+
* A link that resolves **outside** `root` is left out rather than followed. `root` is a copy of the
|
|
287
|
+
* declared path, so a link inside it points back at the live tree — following one captured bytes
|
|
288
|
+
* from outside the path the person declared (a `media -> /mnt/nas` symlink pulled the whole share
|
|
289
|
+
* into the archive), and it captured the *live* copy of anything the copy had already frozen. A
|
|
290
|
+
* restore never recreates links anyway, so the link itself has nothing to restore; its content, if
|
|
291
|
+
* it is wanted, is declared as its own path.
|
|
292
|
+
*/
|
|
293
|
+
async function walk(root) {
|
|
294
|
+
const files = [];
|
|
295
|
+
const seen = /* @__PURE__ */ new Set();
|
|
296
|
+
const slice = eventLoopSlicer();
|
|
297
|
+
let realRoot;
|
|
298
|
+
try {
|
|
299
|
+
realRoot = fs.realpathSync(root);
|
|
300
|
+
} catch {
|
|
301
|
+
return files;
|
|
302
|
+
}
|
|
303
|
+
const readDir = (absolute) => {
|
|
304
|
+
try {
|
|
305
|
+
return fs.readdirSync(absolute).sort();
|
|
306
|
+
} catch {
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
const visit = async (absolute, name) => {
|
|
311
|
+
await slice();
|
|
312
|
+
let stats;
|
|
313
|
+
try {
|
|
314
|
+
stats = fs.statSync(absolute);
|
|
315
|
+
} catch {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
let real;
|
|
319
|
+
try {
|
|
320
|
+
real = fs.realpathSync(absolute);
|
|
321
|
+
} catch {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!isUnderResolved(realRoot, real)) return;
|
|
325
|
+
if (stats.isDirectory()) {
|
|
326
|
+
if (seen.has(real)) return;
|
|
327
|
+
seen.add(real);
|
|
328
|
+
files.push({
|
|
329
|
+
name: `${name}/`,
|
|
330
|
+
absolute,
|
|
331
|
+
directory: true,
|
|
332
|
+
size: 0,
|
|
333
|
+
mode: archiveMode(stats)
|
|
334
|
+
});
|
|
335
|
+
for (const child of readDir(absolute)) await visit(path.join(absolute, child), `${name}/${child}`);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (stats.isFile()) files.push({
|
|
339
|
+
name,
|
|
340
|
+
absolute,
|
|
341
|
+
directory: false,
|
|
342
|
+
size: stats.size,
|
|
343
|
+
mode: archiveMode(stats)
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
for (const child of readDir(root)) await visit(path.join(root, child), child);
|
|
347
|
+
return files;
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
export { listZip as a, isZipArchive as i, extractZip as n, copyTree as o, isInvalidPassword as r, createZip as t };
|
|
351
|
+
|
|
352
|
+
//# sourceMappingURL=archive-DP-XQR8X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive-DP-XQR8X.js","names":[],"sources":["../../src/helpers/copy-tree.ts","../../src/providers/archive.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { performance } from 'node:perf_hooks'\nimport { setImmediate } from 'node:timers/promises'\nimport { DetailedError } from '@namesmt/utils'\n\n/** How long a tree operation may hold the event loop before the panel gets a turn. */\nconst SLICE_MS = 10\n\n/**\n * A checkpoint that yields to the event loop once `SLICE_MS` of synchronous work has passed.\n *\n * Sync calls in slices, not `fs.promises`: every async call is a thread-pool round trip, which made a\n * tree of small files 10-20x slower to copy and walk than the sync calls it replaced.\n */\nexport function eventLoopSlicer(): () => Promise<void> {\n let since = performance.now()\n return async () => {\n if (performance.now() - since < SLICE_MS)\n return\n await setImmediate()\n since = performance.now()\n }\n}\n\n/**\n * `fs.cpSync(source, target, { recursive: true, force: true, filter })`, yielding between entries.\n *\n * Every non-directory entry is still copied by `cpSync`, so links, modes and special files behave as\n * they did; only the directory recursion is here, in cp's order — a directory this call creates gets\n * its source mode after its contents are written.\n *\n * The two roots are dereferenced: a declared `data -> /mnt/disk/data` *is* the data, so it is copied\n * as its target rather than as a link (which the archive walk then drops as outside the tree, leaving\n * an empty capture), and a restore writes into the directory a linked target names instead of\n * refusing it as a non-directory. Links *below* the roots are untouched.\n */\nexport async function copyTree(source: string, target: string, filter: (source: string, target: string) => boolean): Promise<void> {\n const slice = eventLoopSlicer()\n const visit = async (from: string, to: string): Promise<void> => {\n if (!filter(from, to))\n return\n await slice()\n const stats = fs.lstatSync(from)\n if (!stats.isDirectory()) {\n // `recursive` as before: a link to a directory is still copied as the link.\n fs.cpSync(from, to, { recursive: true, force: true })\n return\n }\n const existing = fs.lstatSync(to, { throwIfNoEntry: false })\n if (existing !== undefined && !existing.isDirectory())\n throw new DetailedError(`cannot overwrite non-directory ${to} with directory ${from}`, { code: 'ERR_FS_CP_DIR_TO_NON_DIR' })\n if (existing === undefined)\n fs.mkdirSync(to)\n for (const name of fs.readdirSync(from))\n await visit(path.join(from, name), path.join(to, name))\n if (existing === undefined)\n fs.chmodSync(to, stats.mode)\n }\n fs.mkdirSync(path.dirname(target), { recursive: true })\n await visit(realpathOr(source), realpathOr(target))\n}\n\n/** The path a link names, or the path itself when it does not resolve (absent, dangling). */\nfunction realpathOr(target: string): string {\n try {\n return fs.realpathSync(target)\n }\n catch {\n return target\n }\n}\n","import type { FileEntry } from '@zip.js/zip.js'\nimport { Buffer } from 'node:buffer'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { Readable, Writable } from 'node:stream'\nimport { finished } from 'node:stream/promises'\nimport { BlobReader, configure, ZipReader, ZipWriter } from '@zip.js/zip.js'\nimport { eventLoopSlicer } from '#src/helpers/copy-tree'\n\n/**\n * `Readable.toWeb` is typed against `node:stream/web`, while zip.js declares the\n * global `ReadableStream` — the same objects under two declarations, and which\n * one wins depends on the tsconfig (the SPA's adds lib.dom). These aliases take\n * the type zip.js expects, whichever it is where this file is compiled.\n */\ntype ZipInput = Parameters<ZipWriter<unknown>['add']>[1]\ntype ZipOutput = ConstructorParameters<typeof ZipWriter>[0] & { abort: (reason?: unknown) => Promise<void> }\ntype ZipDataOutput = Parameters<FileEntry['getData']>[0]\n\n/**\n * Backups are ordinary zip files: the same container whether or not they are\n * password-protected, openable by any archive manager (including the one built\n * into Windows and macOS), and produced without a native binary — zip.js is pure\n * JavaScript.\n *\n * A password means WinZip AES-256 (`encryptionStrength: 3`, AE-2): strong, and\n * still standard, unlike the legacy ZipCrypto encryption.\n */\n\n// Deterministic, in-process codecs: a bundled CLI has no worker file to load.\nconfigure({ useWebWorkers: false })\n\nconst ZIPS = [\n [0x50, 0x4B, 0x03, 0x04],\n [0x50, 0x4B, 0x05, 0x06],\n [0x50, 0x4B, 0x07, 0x08],\n]\n\n/** Recognised by content, never by the file's name. */\nexport function isZipArchive(file: string): boolean {\n let fd: number | null = null\n try {\n fd = fs.openSync(file, 'r')\n const head = Buffer.alloc(4)\n const read = fs.readSync(fd, head, 0, 4, 0)\n return read === 4 && ZIPS.some(magic => magic.every((byte, index) => head[index] === byte))\n }\n catch {\n return false\n }\n finally {\n if (fd !== null)\n fs.closeSync(fd)\n }\n}\n\nexport interface ArchiveEntry {\n /** Forward-slash path inside the archive; directories end with `/`. */\n name: string\n directory: boolean\n encrypted: boolean\n symlink: boolean\n /** Uncompressed size, for callers that cap what they will extract. */\n size: number\n /** The Unix mode the entry carries, when the archive recorded one. */\n mode?: number\n}\n\n/** The central directory is not encrypted, so this works without a password. */\nexport async function listZip(file: string): Promise<ArchiveEntry[]> {\n const reader = await open(file)\n try {\n const entries = await reader.getEntries()\n return entries.map(entry => ({\n name: entry.filename,\n directory: entry.directory === true,\n encrypted: entry.encrypted === true,\n symlink: entry.symlink === true,\n size: entry.uncompressedSize ?? 0,\n ...(entry.unixMode === undefined ? {} : { mode: entry.unixMode }),\n }))\n }\n finally {\n await reader.close()\n }\n}\n\n/**\n * True when the archive rejected the password we used.\n *\n * Matched on the wording zip.js raises for a bad password, not on the word alone: the message is\n * `Invalid password`, while a *file it cannot open* produces `ENOENT: … stat '/tmp/…/my-password-\n * backup.zip'` — which carries the word because the caller named the archive that. A substring test\n * read that as a wrong password and told the person to re-enter one, when the archive was simply\n * not there. (Caught by CI, where Node's fs message names the path; the local run said\n * `Unable to open file as blob`, so the same call looked fine.)\n */\nexport function isInvalidPassword(error: unknown): boolean {\n return error instanceof Error && /invalid password/i.test(error.message)\n}\n\n/**\n * Writes the contents of `sourceDir` into `destination`, preserving the tree and each\n * entry's permission bits.\n *\n * The mode is captured because the tree is somebody's data directory: a `0600` key, a `0700`\n * directory and a `0755` script are all routine there, and a backup that restores them as `0644`\n * changes who can read the data it was taken to protect. What a symlink may bring in is bounded by\n * the tree itself (`walk`): the target has to be inside it, so a declared path cannot capture bytes\n * from outside itself. Streams from disk to disk: nothing is buffered whole.\n */\nexport async function createZip(sourceDir: string, destination: string, options: { password?: string } = {}): Promise<void> {\n // Written beside the destination and renamed on success, so an interrupted run never leaves a\n // `.zip` that reads as a finished archive.\n const partial = path.join(path.dirname(destination), `.${path.basename(destination)}.partial`)\n const output = fs.createWriteStream(partial, { mode: 0o600 })\n // Attached up front: the fd closes as part of the web stream ending, so a\n // listener added afterwards would wait forever.\n const flushed = finished(output)\n const writer = Writable.toWeb(output) as unknown as ZipOutput\n const zip = new ZipWriter(writer, {\n ...(options.password === undefined ? {} : { password: options.password, encryptionStrength: 3 as const }),\n level: 6,\n keepOrder: true,\n })\n\n try {\n for (const item of await walk(sourceDir)) {\n const mode = item.mode === null ? {} : { unixMode: item.mode }\n if (item.directory)\n await zip.add(item.name, null, { directory: true, ...mode })\n else if (item.size === 0)\n // An empty file carries no content to protect, and leaving it as a plain\n // AE-2 entry makes older tools (p7zip 16.02) report a CRC failure on it.\n await zip.add(item.name, null, { directory: false, ...mode })\n else\n await zip.add(item.name, Readable.toWeb(fs.createReadStream(item.absolute)) as unknown as ZipInput, mode)\n }\n await zip.close()\n await flushed\n await fs.promises.rename(partial, destination)\n }\n catch (error) {\n await writer.abort(error).catch(() => {})\n // The file stream also fails here (a full disk, a directory in the way), and\n // an unobserved rejection would take the whole control plane down.\n await flushed.catch(() => {})\n await fs.promises.rm(partial, { force: true }).catch(() => {})\n throw error\n }\n}\n\n/**\n * Extracts the given entries (already validated by the caller) into\n * `destination`. Symbolic links are never recreated — an archive is not allowed\n * to make the filesystem point somewhere else.\n *\n * An entry's permission bits are applied after it lands. The file is created under a restrictive\n * mode first, so a `0600` secret never exists world-readable between two calls, and a mode the\n * current umask would widen is set with an explicit `chmod` rather than left to the create.\n */\nexport async function extractZip(\n file: string,\n destination: string,\n options: { names: string[], password?: string },\n): Promise<{ skipped: string[] }> {\n const reader = await open(file, options.password)\n const skipped: string[] = []\n /** Directory modes, applied after their contents: a `0700` dir cannot be written into. */\n const pendingDirModes: Array<{ target: string, mode: number }> = []\n\n try {\n const entries = new Map((await reader.getEntries()).map(entry => [entry.filename, entry]))\n\n for (const name of options.names) {\n const entry = entries.get(name)\n if (entry === undefined) {\n skipped.push(name)\n continue\n }\n\n const target = path.join(destination, name)\n if (entry.directory) {\n fs.mkdirSync(target, { recursive: true })\n // A directory's mode is applied after the files under it are written, otherwise it would\n // close itself to the writes that have not happened yet. `mkdir` gives it the umask's\n // mode; this is the one the archive carried.\n const mode = permissionBits(entry.unixMode)\n if (mode !== null)\n pendingDirModes.push({ target, mode })\n continue\n }\n if (entry.symlink) {\n skipped.push(name)\n continue\n }\n\n fs.mkdirSync(path.dirname(target), { recursive: true })\n await entry.getData(Writable.toWeb(fs.createWriteStream(target, { mode: 0o600 })) as unknown as ZipDataOutput, writeOptions(entry, options.password))\n const mode = permissionBits(entry.unixMode)\n if (mode !== null) {\n try {\n fs.chmodSync(target, mode)\n }\n catch {\n // A filesystem without POSIX modes (a mounted FAT drive, a Windows share) keeps the file\n // it wrote — refusing the whole restore over metadata would lose the data to save the bit.\n }\n }\n }\n }\n finally {\n await reader.close()\n // Deepest first, so a `0700` parent cannot lock out a child that has not been chmodded yet.\n for (const { target, mode } of pendingDirModes.sort((left, right) => right.target.length - left.target.length)) {\n try {\n fs.chmodSync(target, mode)\n }\n catch {}\n }\n pendingDirModes.length = 0\n }\n\n return { skipped }\n}\n\nfunction writeOptions(entry: FileEntry, password: string | undefined): { password?: string } {\n return entry.encrypted && password !== undefined ? { password } : {}\n}\n\nasync function open(file: string, password?: string): Promise<ZipReader<unknown>> {\n // A lazily-read Blob keeps a multi-gigabyte archive out of memory: zip.js only\n // pulls the byte ranges it needs.\n const blob = await fs.openAsBlob(file, { type: 'application/zip' })\n return password === undefined\n ? new ZipReader(new BlobReader(blob))\n : new ZipReader(new BlobReader(blob), { password })\n}\n\ninterface WalkedFile {\n name: string\n absolute: string\n directory: boolean\n size: number\n /** The permission bits to write into the archive, or `null` where the platform has none. */\n mode: number | null\n}\n\n/**\n * The `st_mode` an entry should carry, or `null` where the platform does not report one.\n *\n * Only the permission bits and the file type are kept: the archive records a mode, not an owner,\n * because a restore runs as whoever restores it and a foreign uid would be a worse lie than the\n * restoring user's own.\n */\nfunction archiveMode(stats: fs.Stats): number | null {\n const bits = stats.mode & 0o777\n if (process.platform === 'win32' || bits === 0)\n return null\n return (stats.isDirectory() ? 0o040000 : 0o100000) | bits\n}\n\n/**\n * The permission bits an extracted entry should be given, or `null` when the archive carries none.\n *\n * Zip stores the type in the same field, so the file type is dropped: the entry is written as the\n * ordinary file or directory this call is creating, never as a fifo or a device node an archive\n * could name. The setuid/setgid/sticky bits are dropped too — an archive from another host does not\n * get to install a privileged binary here.\n */\nfunction permissionBits(unixMode: number | undefined): number | null {\n if (unixMode === undefined || unixMode === 0)\n return null\n const bits = unixMode & 0o777\n return bits === 0 ? null : bits\n}\n\n/** True when `child` is `parent` itself or lives underneath it, after resolving both. */\nfunction isUnderResolved(parent: string, child: string): boolean {\n const relative = path.relative(parent, child)\n return relative === '' || (!path.isAbsolute(relative) && !relative.startsWith('..'))\n}\n\n/**\n * Sorted, deterministic walk with directory loops broken and the declared tree respected.\n *\n * Every read is best-effort: a directory that vanishes mid-walk (a rotated log, a\n * build directory being cleaned, a container being torn down) must leave it out of\n * the archive rather than reject `createZip` and turn a backup into a failure.\n *\n * A link that resolves **outside** `root` is left out rather than followed. `root` is a copy of the\n * declared path, so a link inside it points back at the live tree — following one captured bytes\n * from outside the path the person declared (a `media -> /mnt/nas` symlink pulled the whole share\n * into the archive), and it captured the *live* copy of anything the copy had already frozen. A\n * restore never recreates links anyway, so the link itself has nothing to restore; its content, if\n * it is wanted, is declared as its own path.\n */\nasync function walk(root: string): Promise<WalkedFile[]> {\n const files: WalkedFile[] = []\n const seen = new Set<string>()\n const slice = eventLoopSlicer()\n let realRoot: string\n try {\n realRoot = fs.realpathSync(root)\n }\n catch {\n return files\n }\n\n const readDir = (absolute: string): string[] => {\n try {\n return fs.readdirSync(absolute).sort()\n }\n catch {\n return []\n }\n }\n\n const visit = async (absolute: string, name: string): Promise<void> => {\n await slice()\n let stats: fs.Stats\n try {\n stats = fs.statSync(absolute)\n }\n catch {\n return\n }\n\n let real: string\n try {\n real = fs.realpathSync(absolute)\n }\n catch {\n // A link whose target went away; there is nothing to capture.\n return\n }\n if (!isUnderResolved(realRoot, real))\n return\n\n if (stats.isDirectory()) {\n if (seen.has(real))\n return\n seen.add(real)\n files.push({ name: `${name}/`, absolute, directory: true, size: 0, mode: archiveMode(stats) })\n for (const child of readDir(absolute))\n await visit(path.join(absolute, child), `${name}/${child}`)\n return\n }\n\n if (stats.isFile())\n files.push({ name, absolute, directory: false, size: stats.size, mode: archiveMode(stats) })\n }\n\n for (const child of readDir(root))\n await visit(path.join(root, child), child)\n\n return files\n}\n"],"mappings":";;;;;;;;;;;;AAOA,IAAM,WAAW;;;;;;;AAQjB,SAAgB,kBAAuC;CACrD,IAAI,QAAQ,YAAY,IAAI;CAC5B,OAAO,YAAY;EACjB,IAAI,YAAY,IAAI,IAAI,QAAQ,UAC9B;EACF,MAAM,aAAa;EACnB,QAAQ,YAAY,IAAI;CAC1B;AACF;;;;;;;;;;;;;AAcA,eAAsB,SAAS,QAAgB,QAAgB,QAAoE;CACjI,MAAM,QAAQ,gBAAgB;CAC9B,MAAM,QAAQ,OAAO,MAAc,OAA8B;EAC/D,IAAI,CAAC,OAAO,MAAM,EAAE,GAClB;EACF,MAAM,MAAM;EACZ,MAAM,QAAQ,GAAG,UAAU,IAAI;EAC/B,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,KAAK,MAAM,KAAK,GAAG,KAAK;CAE3C,OAAO;AACT"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { i as ensureStateDir } from "./paths-CGlGDrOU.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { randomBytes } from "node:crypto";
|
|
6
|
+
//#region src/helpers/atomic.ts
|
|
7
|
+
/**
|
|
8
|
+
* Write via a temp file in the same directory, then rename: readers never see a
|
|
9
|
+
* half-written file, and a crash cannot truncate the previous config.
|
|
10
|
+
*/
|
|
11
|
+
function writeFileAtomic(file, content, options = {}) {
|
|
12
|
+
ensureStateDir(path.dirname(file));
|
|
13
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
14
|
+
try {
|
|
15
|
+
fs.writeFileSync(tmp, content, options.mode === void 0 ? void 0 : { mode: options.mode });
|
|
16
|
+
if (options.mode !== void 0) fs.chmodSync(tmp, options.mode);
|
|
17
|
+
fs.renameSync(tmp, file);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
fs.rmSync(tmp, { force: true });
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { writeFileAtomic as t };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=atomic-C1PfJpE7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic-C1PfJpE7.js","names":[],"sources":["../../src/helpers/atomic.ts"],"sourcesContent":["import { randomBytes } from 'node:crypto'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { ensureStateDir } from '#src/helpers/paths'\n\nexport interface WriteFileOptions {\n /** Applied to the temp file before the rename, so secrets never exist world-readable. */\n mode?: number\n}\n\n/**\n * Write via a temp file in the same directory, then rename: readers never see a\n * half-written file, and a crash cannot truncate the previous config.\n */\nexport function writeFileAtomic(file: string, content: string, options: WriteFileOptions = {}): void {\n ensureStateDir(path.dirname(file))\n // Unique per call, not just per process: two writes to the same file in one\n // process would otherwise share a temp name and the second rename would fail.\n const tmp = `${file}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`\n try {\n fs.writeFileSync(tmp, content, options.mode === undefined ? undefined : { mode: options.mode })\n if (options.mode !== undefined)\n fs.chmodSync(tmp, options.mode)\n fs.renameSync(tmp, file)\n }\n catch (error) {\n // The temp name is unique per call, so a failed write would otherwise litter the\n // directory with a file nothing will ever reuse.\n fs.rmSync(tmp, { force: true })\n throw error\n }\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,gBAAgB,MAAc,SAAiB,UAA4B,CAAC,GAAS;CACnG,eAAe,KAAK,QAAQ,IAAI,CAAC;CAGjC,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,IAAI,GAAG,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE;CACrE,IAAI;EACF,GAAG,cAAc,KAAK,SAAS,QAAQ,SAAS,KAAA,IAAY,KAAA,IAAY,EAAE,MAAM,QAAQ,KAAK,CAAC;EAC9F,IAAI,QAAQ,SAAS,KAAA,GACnB,GAAG,UAAU,KAAK,QAAQ,IAAI;EAChC,GAAG,WAAW,KAAK,IAAI;CACzB,SACO,OAAO;EAGZ,GAAG,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;EAC9B,MAAM;CACR;AACF"}
|