@machinen/runtime 0.1.0 → 0.1.1
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/API.md +162 -906
- package/dist/index.js +82 -53
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1152,7 +1152,8 @@ function connectOnceWithTimeout(udsPath, timeoutMs) {
|
|
|
1152
1152
|
import { execFileSync as execFileSync9 } from "child_process";
|
|
1153
1153
|
import {
|
|
1154
1154
|
closeSync as closeSync7,
|
|
1155
|
-
existsSync as
|
|
1155
|
+
existsSync as existsSync17,
|
|
1156
|
+
mkdirSync as mkdirSync12,
|
|
1156
1157
|
mkdtempSync as mkdtempSync8,
|
|
1157
1158
|
openSync as openSync7,
|
|
1158
1159
|
readFileSync as readFileSync11,
|
|
@@ -1162,7 +1163,7 @@ import {
|
|
|
1162
1163
|
writeSync as writeSync6
|
|
1163
1164
|
} from "fs";
|
|
1164
1165
|
import { homedir as homedir8, tmpdir as tmpdir8 } from "os";
|
|
1165
|
-
import { join as join16, resolve as resolve9 } from "path";
|
|
1166
|
+
import { dirname as dirname9, join as join16, resolve as resolve9 } from "path";
|
|
1166
1167
|
import debugLib16 from "debug";
|
|
1167
1168
|
|
|
1168
1169
|
// src/phase-timer.ts
|
|
@@ -1889,7 +1890,7 @@ import { execFileSync as execFileSync8 } from "child_process";
|
|
|
1889
1890
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
1890
1891
|
import {
|
|
1891
1892
|
closeSync as closeSync6,
|
|
1892
|
-
existsSync as
|
|
1893
|
+
existsSync as existsSync16,
|
|
1893
1894
|
openSync as openSync6,
|
|
1894
1895
|
readdirSync as readdirSync7,
|
|
1895
1896
|
readFileSync as readFileSync10,
|
|
@@ -2184,7 +2185,7 @@ import { randomBytes as randomBytes3 } from "crypto";
|
|
|
2184
2185
|
import { once } from "events";
|
|
2185
2186
|
import {
|
|
2186
2187
|
closeSync as closeSync5,
|
|
2187
|
-
existsSync as
|
|
2188
|
+
existsSync as existsSync15,
|
|
2188
2189
|
mkdtempSync as mkdtempSync6,
|
|
2189
2190
|
openSync as openSync5,
|
|
2190
2191
|
rmSync as rmSync9,
|
|
@@ -3776,7 +3777,7 @@ function prebakeRootfsImageFromTree(args) {
|
|
|
3776
3777
|
|
|
3777
3778
|
// src/vm/bundle.ts
|
|
3778
3779
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
3779
|
-
import { existsSync as
|
|
3780
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync5, rmSync as rmSync8, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
3780
3781
|
import { tmpdir as tmpdir4 } from "os";
|
|
3781
3782
|
import { join as join11, resolve as resolve4 } from "path";
|
|
3782
3783
|
|
|
@@ -3784,6 +3785,7 @@ import { join as join11, resolve as resolve4 } from "path";
|
|
|
3784
3785
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
3785
3786
|
import {
|
|
3786
3787
|
cpSync,
|
|
3788
|
+
existsSync as existsSync9,
|
|
3787
3789
|
lstatSync,
|
|
3788
3790
|
mkdirSync as mkdirSync7,
|
|
3789
3791
|
mkdtempSync as mkdtempSync3,
|
|
@@ -3794,10 +3796,12 @@ import {
|
|
|
3794
3796
|
statSync as statSync5,
|
|
3795
3797
|
writeFileSync as writeFileSync5
|
|
3796
3798
|
} from "fs";
|
|
3797
|
-
import {
|
|
3799
|
+
import { createRequire as createRequire3 } from "module";
|
|
3800
|
+
import { arch as osArch2, platform as osPlatform5, tmpdir as tmpdir2 } from "os";
|
|
3798
3801
|
import { dirname as dirname7, join as join8 } from "path";
|
|
3799
3802
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3800
3803
|
import debugLib8 from "debug";
|
|
3804
|
+
var require_3 = createRequire3(import.meta.url);
|
|
3801
3805
|
var debug8 = debugLib8("machinen:mkinitramfs");
|
|
3802
3806
|
var DEFAULT_WORKSPACE_EXCLUDES = /* @__PURE__ */ new Set([
|
|
3803
3807
|
".git",
|
|
@@ -4225,17 +4229,41 @@ function appendFinalEntries(parts, opts) {
|
|
|
4225
4229
|
parts.push(newc("tmp", 17407));
|
|
4226
4230
|
parts.push(newc("TRAILER!!!", 0));
|
|
4227
4231
|
}
|
|
4228
|
-
|
|
4232
|
+
var cachedGuestPaths = null;
|
|
4233
|
+
function resolveGuestPaths() {
|
|
4234
|
+
if (cachedGuestPaths) {
|
|
4235
|
+
return cachedGuestPaths;
|
|
4236
|
+
}
|
|
4237
|
+
const pkgName = `@machinen/vmm-${osArch2()}-${osPlatform5()}`;
|
|
4238
|
+
try {
|
|
4239
|
+
const mod = require_3(pkgName);
|
|
4240
|
+
if (mod.initPath && mod.fuseAgentPath && mod.execAgentPath && existsSync9(mod.initPath)) {
|
|
4241
|
+
cachedGuestPaths = {
|
|
4242
|
+
initPath: mod.initPath,
|
|
4243
|
+
fuseAgentPath: mod.fuseAgentPath,
|
|
4244
|
+
execAgentPath: mod.execAgentPath
|
|
4245
|
+
};
|
|
4246
|
+
return cachedGuestPaths;
|
|
4247
|
+
}
|
|
4248
|
+
} catch {
|
|
4249
|
+
}
|
|
4229
4250
|
const here = dirname7(fileURLToPath2(import.meta.url));
|
|
4230
|
-
|
|
4251
|
+
const fixtures = join8(here, "..", "..", "microvm", "test-fixtures");
|
|
4252
|
+
cachedGuestPaths = {
|
|
4253
|
+
initPath: join8(fixtures, "init"),
|
|
4254
|
+
fuseAgentPath: join8(fixtures, "fuse-agent"),
|
|
4255
|
+
execAgentPath: join8(fixtures, "exec-agent")
|
|
4256
|
+
};
|
|
4257
|
+
return cachedGuestPaths;
|
|
4258
|
+
}
|
|
4259
|
+
function defaultInitPath() {
|
|
4260
|
+
return resolveGuestPaths().initPath;
|
|
4231
4261
|
}
|
|
4232
4262
|
function defaultFuseAgentPath() {
|
|
4233
|
-
|
|
4234
|
-
return join8(here, "..", "..", "microvm", "test-fixtures", "fuse-agent");
|
|
4263
|
+
return resolveGuestPaths().fuseAgentPath;
|
|
4235
4264
|
}
|
|
4236
4265
|
function defaultExecAgentPath() {
|
|
4237
|
-
|
|
4238
|
-
return join8(here, "..", "..", "microvm", "test-fixtures", "exec-agent");
|
|
4266
|
+
return resolveGuestPaths().execAgentPath;
|
|
4239
4267
|
}
|
|
4240
4268
|
function cli(argv) {
|
|
4241
4269
|
if (argv[0] === "--workspace") {
|
|
@@ -4342,7 +4370,7 @@ import { execFileSync as execFileSync6, spawnSync as spawnSync4 } from "child_pr
|
|
|
4342
4370
|
import { createHash as createHash2 } from "crypto";
|
|
4343
4371
|
import {
|
|
4344
4372
|
closeSync as closeSync3,
|
|
4345
|
-
existsSync as
|
|
4373
|
+
existsSync as existsSync10,
|
|
4346
4374
|
fsyncSync as fsyncSync3,
|
|
4347
4375
|
mkdirSync as mkdirSync8,
|
|
4348
4376
|
mkdtempSync as mkdtempSync4,
|
|
@@ -4358,7 +4386,7 @@ import {
|
|
|
4358
4386
|
writeSync as writeSync2,
|
|
4359
4387
|
lstatSync as lstatSync2
|
|
4360
4388
|
} from "fs";
|
|
4361
|
-
import { createRequire as
|
|
4389
|
+
import { createRequire as createRequire4 } from "module";
|
|
4362
4390
|
import { arch as arch2, homedir as homedir6, platform as platform4, tmpdir as tmpdir3 } from "os";
|
|
4363
4391
|
import { dirname as dirname8, join as join9, resolve as resolve2 } from "path";
|
|
4364
4392
|
import debugLib9 from "debug";
|
|
@@ -4370,7 +4398,7 @@ function okMarkerPath2(imgPath) {
|
|
|
4370
4398
|
return `${imgPath}.ok`;
|
|
4371
4399
|
}
|
|
4372
4400
|
function markMountDiskImageClean(imgPath) {
|
|
4373
|
-
if (!
|
|
4401
|
+
if (!existsSync10(imgPath)) {
|
|
4374
4402
|
return;
|
|
4375
4403
|
}
|
|
4376
4404
|
const okPath = okMarkerPath2(imgPath);
|
|
@@ -4398,7 +4426,7 @@ function markMountDiskImageClean(imgPath) {
|
|
|
4398
4426
|
}
|
|
4399
4427
|
function ensureMountDiskImage(hostAbs, opts = {}) {
|
|
4400
4428
|
const hostResolved = resolve2(hostAbs);
|
|
4401
|
-
if (!
|
|
4429
|
+
if (!existsSync10(hostResolved)) {
|
|
4402
4430
|
throw new BootError(
|
|
4403
4431
|
"BOOT_MOUNT_HOST_NOT_FOUND",
|
|
4404
4432
|
`ensureMountDiskImage: host directory not found at ${hostResolved}`
|
|
@@ -4417,9 +4445,9 @@ function ensureMountDiskImage(hostAbs, opts = {}) {
|
|
|
4417
4445
|
opts.onPhase?.("manifest-hash", Date.now() - hashT0);
|
|
4418
4446
|
const imgPath = join9(cacheDir, `${key}.sqfs`);
|
|
4419
4447
|
const okPath = okMarkerPath2(imgPath);
|
|
4420
|
-
if (!opts.force &&
|
|
4448
|
+
if (!opts.force && existsSync10(imgPath)) {
|
|
4421
4449
|
debug9("cache hit key=%s img=%s", key.slice(0, 12), imgPath);
|
|
4422
|
-
if (!
|
|
4450
|
+
if (!existsSync10(okPath)) {
|
|
4423
4451
|
debug9("cache hit but no clean marker \u2014 rematerialising img=%s", imgPath);
|
|
4424
4452
|
} else {
|
|
4425
4453
|
try {
|
|
@@ -4526,7 +4554,7 @@ function resolveMksquashfsEnvOverride() {
|
|
|
4526
4554
|
if (!envOverride) {
|
|
4527
4555
|
return void 0;
|
|
4528
4556
|
}
|
|
4529
|
-
if (
|
|
4557
|
+
if (existsSync10(envOverride)) {
|
|
4530
4558
|
debug9("resolved via MACHINEN_MKSQUASHFS=%s", envOverride);
|
|
4531
4559
|
return envOverride;
|
|
4532
4560
|
}
|
|
@@ -4535,13 +4563,13 @@ function resolveMksquashfsEnvOverride() {
|
|
|
4535
4563
|
`MACHINEN_MKSQUASHFS=${envOverride} is set but that file does not exist.`
|
|
4536
4564
|
);
|
|
4537
4565
|
}
|
|
4538
|
-
var
|
|
4566
|
+
var require_4 = createRequire4(import.meta.url);
|
|
4539
4567
|
function findBundledMksquashfs() {
|
|
4540
4568
|
const pkg = `@machinen/squashfs-tools-${arch2()}-${platform4()}`;
|
|
4541
4569
|
try {
|
|
4542
|
-
const pkgJson =
|
|
4570
|
+
const pkgJson = require_4.resolve(`${pkg}/package.json`);
|
|
4543
4571
|
const candidate = join9(dirname8(pkgJson), "bin", "mksquashfs");
|
|
4544
|
-
if (
|
|
4572
|
+
if (existsSync10(candidate)) {
|
|
4545
4573
|
return candidate;
|
|
4546
4574
|
}
|
|
4547
4575
|
} catch {
|
|
@@ -4559,7 +4587,7 @@ var KEG_ONLY_DIRS = [
|
|
|
4559
4587
|
function findKegOnlyMksquashfs() {
|
|
4560
4588
|
for (const dir of KEG_ONLY_DIRS) {
|
|
4561
4589
|
const candidate = join9(dir, "mksquashfs");
|
|
4562
|
-
if (
|
|
4590
|
+
if (existsSync10(candidate)) {
|
|
4563
4591
|
return candidate;
|
|
4564
4592
|
}
|
|
4565
4593
|
}
|
|
@@ -4669,13 +4697,13 @@ function randomSuffix() {
|
|
|
4669
4697
|
|
|
4670
4698
|
// src/vm/helpers.ts
|
|
4671
4699
|
import { randomBytes } from "crypto";
|
|
4672
|
-
import { closeSync as closeSync4, existsSync as
|
|
4673
|
-
import { createRequire as
|
|
4674
|
-
import { arch as
|
|
4700
|
+
import { closeSync as closeSync4, existsSync as existsSync11, openSync as openSync4, writeSync as writeSync3 } from "fs";
|
|
4701
|
+
import { createRequire as createRequire5 } from "module";
|
|
4702
|
+
import { arch as osArch3, platform as osPlatform6, totalmem as totalmem2 } from "os";
|
|
4675
4703
|
import { resolve as resolve3 } from "path";
|
|
4676
4704
|
import debugLib10 from "debug";
|
|
4677
4705
|
var debug10 = debugLib10("machinen:boot");
|
|
4678
|
-
var
|
|
4706
|
+
var require_5 = createRequire5(import.meta.url);
|
|
4679
4707
|
var SNAP_SCRATCH_BYTES = 8 * 1024 * 1024 * 1024;
|
|
4680
4708
|
function allocateSparseFile3(path, sizeBytes) {
|
|
4681
4709
|
const fd = openSync4(path, "w");
|
|
@@ -4712,7 +4740,7 @@ function resolveVmmBinary() {
|
|
|
4712
4740
|
const envOverride = process.env.MACHINEN_VMM;
|
|
4713
4741
|
if (envOverride) {
|
|
4714
4742
|
const abs = resolve3(envOverride);
|
|
4715
|
-
if (!
|
|
4743
|
+
if (!existsSync11(abs)) {
|
|
4716
4744
|
throw new BootError(
|
|
4717
4745
|
"BOOT_VMM_MISSING",
|
|
4718
4746
|
`MACHINEN_VMM is set to ${envOverride}, but that file does not exist.`
|
|
@@ -4720,11 +4748,11 @@ function resolveVmmBinary() {
|
|
|
4720
4748
|
}
|
|
4721
4749
|
return abs;
|
|
4722
4750
|
}
|
|
4723
|
-
const key = `${
|
|
4751
|
+
const key = `${osArch3()}-${osPlatform6()}`;
|
|
4724
4752
|
const pkgName = `@machinen/vmm-${key}`;
|
|
4725
4753
|
try {
|
|
4726
|
-
const mod =
|
|
4727
|
-
if (!mod.binary || !
|
|
4754
|
+
const mod = require_5(pkgName);
|
|
4755
|
+
if (!mod.binary || !existsSync11(mod.binary)) {
|
|
4728
4756
|
throw new BootError(
|
|
4729
4757
|
"BOOT_VMM_PACKAGE_BROKEN",
|
|
4730
4758
|
`${pkgName} is installed but its binary is missing at ${mod.binary}.`
|
|
@@ -4904,7 +4932,7 @@ async function setGuestHostname(vm, hostname) {
|
|
|
4904
4932
|
|
|
4905
4933
|
// src/vm/image-config.ts
|
|
4906
4934
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
4907
|
-
import { existsSync as
|
|
4935
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync9, readFileSync as readFileSync9, statSync as statSync7, writeFileSync as writeFileSync6 } from "fs";
|
|
4908
4936
|
import { homedir as homedir7 } from "os";
|
|
4909
4937
|
import { join as join10 } from "path";
|
|
4910
4938
|
function imageConfigCacheDir() {
|
|
@@ -4934,7 +4962,7 @@ function warmImageConfigCache(imagePath, config) {
|
|
|
4934
4962
|
}
|
|
4935
4963
|
function readImageConfig(imagePath) {
|
|
4936
4964
|
const cachePath = imageConfigCachePath(imagePath);
|
|
4937
|
-
if (cachePath &&
|
|
4965
|
+
if (cachePath && existsSync12(cachePath)) {
|
|
4938
4966
|
try {
|
|
4939
4967
|
const raw = readFileSync9(cachePath, "utf8");
|
|
4940
4968
|
const cached = JSON.parse(raw);
|
|
@@ -4969,7 +4997,7 @@ function resolveLiveMounts(mounts, cwd, udsDir) {
|
|
|
4969
4997
|
return mounts.map((m, i) => {
|
|
4970
4998
|
validateMountGuest(m.guest);
|
|
4971
4999
|
const hostAbs = resolve4(cwd ?? process.cwd(), m.host);
|
|
4972
|
-
if (!
|
|
5000
|
+
if (!existsSync13(hostAbs)) {
|
|
4973
5001
|
throw new BootError(
|
|
4974
5002
|
"BOOT_MOUNT_HOST_NOT_FOUND",
|
|
4975
5003
|
`liveMounts[${i}] host path not found: ${m.host}`
|
|
@@ -5052,7 +5080,7 @@ function synthesizeAndPackBundle(opts, mergedGuestEnv, liveMounts, packerOpts) {
|
|
|
5052
5080
|
let imageConfig;
|
|
5053
5081
|
if (opts.image) {
|
|
5054
5082
|
baseAbs = resolve4(opts.cwd ?? process.cwd(), opts.image);
|
|
5055
|
-
if (!
|
|
5083
|
+
if (!existsSync13(baseAbs)) {
|
|
5056
5084
|
cleanup();
|
|
5057
5085
|
throw new BootError("BOOT_IMAGE_NOT_FOUND", `image tarball not found: ${baseAbs}`);
|
|
5058
5086
|
}
|
|
@@ -5099,7 +5127,7 @@ function synthesizeAndPackBundle(opts, mergedGuestEnv, liveMounts, packerOpts) {
|
|
|
5099
5127
|
throw err;
|
|
5100
5128
|
}
|
|
5101
5129
|
const hostAbs = resolve4(opts.cwd ?? process.cwd(), opts.mount.host);
|
|
5102
|
-
if (!
|
|
5130
|
+
if (!existsSync13(hostAbs)) {
|
|
5103
5131
|
cleanup();
|
|
5104
5132
|
throw new BootError(
|
|
5105
5133
|
"BOOT_MOUNT_HOST_NOT_FOUND",
|
|
@@ -5150,13 +5178,13 @@ function synthesizeAndPackBundle(opts, mergedGuestEnv, liveMounts, packerOpts) {
|
|
|
5150
5178
|
if (opts._restoreMountDisk) {
|
|
5151
5179
|
try {
|
|
5152
5180
|
const r = opts._restoreMountDisk;
|
|
5153
|
-
if (!
|
|
5181
|
+
if (!existsSync13(r.lowerPath)) {
|
|
5154
5182
|
throw new BootError(
|
|
5155
5183
|
"BOOT_SNAPSHOT_NOT_FOUND",
|
|
5156
5184
|
`restore: bundle is missing mount-lower at ${r.lowerPath}`
|
|
5157
5185
|
);
|
|
5158
5186
|
}
|
|
5159
|
-
if (!
|
|
5187
|
+
if (!existsSync13(r.upperPath)) {
|
|
5160
5188
|
throw new BootError(
|
|
5161
5189
|
"BOOT_SNAPSHOT_NOT_FOUND",
|
|
5162
5190
|
`restore: bundle is missing mount-upper at ${r.upperPath}`
|
|
@@ -5204,7 +5232,7 @@ function synthesizeAndPackBundle(opts, mergedGuestEnv, liveMounts, packerOpts) {
|
|
|
5204
5232
|
|
|
5205
5233
|
// src/vm/snapshot.ts
|
|
5206
5234
|
import { spawn as nodeSpawn3 } from "child_process";
|
|
5207
|
-
import { existsSync as
|
|
5235
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync11, readdirSync as readdirSync6, statSync as statSync9, writeFileSync as writeFileSync8 } from "fs";
|
|
5208
5236
|
import { join as join12, resolve as resolve5 } from "path";
|
|
5209
5237
|
import debugLib11 from "debug";
|
|
5210
5238
|
var debugSnapshot = debugLib11("machinen:snapshot");
|
|
@@ -5266,7 +5294,7 @@ async function performSnapshot(ctx, opts) {
|
|
|
5266
5294
|
}
|
|
5267
5295
|
function prepareBundleDir(outDir) {
|
|
5268
5296
|
const snapDir = resolve5(outDir);
|
|
5269
|
-
if (
|
|
5297
|
+
if (existsSync14(snapDir)) {
|
|
5270
5298
|
if (!statSync9(snapDir).isDirectory()) {
|
|
5271
5299
|
throw new SnapshotError(
|
|
5272
5300
|
"SNAPSHOT_DUMP_FAILED",
|
|
@@ -5548,7 +5576,7 @@ async function boot(opts = {}) {
|
|
|
5548
5576
|
await validatePortForwardOpts(opts, portForward);
|
|
5549
5577
|
const binaryInput = opts.binary ?? resolveVmmBinary();
|
|
5550
5578
|
const binary = resolve6(opts.cwd ?? process.cwd(), binaryInput);
|
|
5551
|
-
if (!
|
|
5579
|
+
if (!existsSync15(binary)) {
|
|
5552
5580
|
throw new BootError("BOOT_VMM_MISSING", `VMM binary not found at ${binary}`);
|
|
5553
5581
|
}
|
|
5554
5582
|
if (opts.cmd && !opts.image) {
|
|
@@ -5956,7 +5984,7 @@ function prepareScratchDisk(opts, env) {
|
|
|
5956
5984
|
}
|
|
5957
5985
|
if (typeof opts.snapshot === "string") {
|
|
5958
5986
|
const bundleDisk = resolve6(opts.cwd ?? process.cwd(), opts.snapshot);
|
|
5959
|
-
if (!
|
|
5987
|
+
if (!existsSync15(bundleDisk)) {
|
|
5960
5988
|
throw new BootError("BOOT_SNAPSHOT_NOT_FOUND", `snapshot image not found: ${bundleDisk}`);
|
|
5961
5989
|
}
|
|
5962
5990
|
if (opts.cmd) {
|
|
@@ -5988,14 +6016,14 @@ function prepareScratchDisk(opts, env) {
|
|
|
5988
6016
|
function validateKernelDtb(opts, env) {
|
|
5989
6017
|
if (opts.kernel) {
|
|
5990
6018
|
const abs = resolve6(opts.cwd ?? process.cwd(), opts.kernel);
|
|
5991
|
-
if (!
|
|
6019
|
+
if (!existsSync15(abs)) {
|
|
5992
6020
|
throw new BootError("BOOT_KERNEL_NOT_FOUND", `kernel not found: ${abs}`);
|
|
5993
6021
|
}
|
|
5994
6022
|
env.MACHINEN_KERNEL = abs;
|
|
5995
6023
|
}
|
|
5996
6024
|
if (opts.dtb) {
|
|
5997
6025
|
const abs = resolve6(opts.cwd ?? process.cwd(), opts.dtb);
|
|
5998
|
-
if (!
|
|
6026
|
+
if (!existsSync15(abs)) {
|
|
5999
6027
|
throw new BootError("BOOT_DTB_NOT_FOUND", `dtb not found: ${abs}`);
|
|
6000
6028
|
}
|
|
6001
6029
|
env.MACHINEN_DTB = abs;
|
|
@@ -6071,7 +6099,7 @@ async function bringUpGvproxy(opts, binary, env, portForward) {
|
|
|
6071
6099
|
function materializeRootdisk(opts, env, phases) {
|
|
6072
6100
|
if (typeof opts.rootDisk === "string") {
|
|
6073
6101
|
const rootDiskAbs = resolve6(opts.cwd ?? process.cwd(), opts.rootDisk);
|
|
6074
|
-
if (!
|
|
6102
|
+
if (!existsSync15(rootDiskAbs)) {
|
|
6075
6103
|
throw new BootError("BOOT_IMAGE_NOT_FOUND", `rootDisk image not found: ${rootDiskAbs}`);
|
|
6076
6104
|
}
|
|
6077
6105
|
env.MACHINEN_ROOTDISK = rootDiskAbs;
|
|
@@ -6435,7 +6463,7 @@ async function restore(opts) {
|
|
|
6435
6463
|
const snapDir = resolve7(opts.snapDir);
|
|
6436
6464
|
const imgDir = join14(snapDir, "img");
|
|
6437
6465
|
const metaPath = join14(snapDir, "meta.json");
|
|
6438
|
-
if (!
|
|
6466
|
+
if (!existsSync16(imgDir) || !statSync10(imgDir).isDirectory()) {
|
|
6439
6467
|
throw new BootError("BOOT_SNAPSHOT_NOT_FOUND", `restore: ${imgDir} not found`);
|
|
6440
6468
|
}
|
|
6441
6469
|
const imgEntries = readdirSync7(imgDir);
|
|
@@ -6447,7 +6475,7 @@ async function restore(opts) {
|
|
|
6447
6475
|
}
|
|
6448
6476
|
phases.start("snapshot-meta-read");
|
|
6449
6477
|
let meta = { snappedAt: 0 };
|
|
6450
|
-
if (
|
|
6478
|
+
if (existsSync16(metaPath)) {
|
|
6451
6479
|
try {
|
|
6452
6480
|
meta = JSON.parse(readFileSync10(metaPath, "utf8"));
|
|
6453
6481
|
} catch {
|
|
@@ -6457,10 +6485,10 @@ async function restore(opts) {
|
|
|
6457
6485
|
let resolvedImage;
|
|
6458
6486
|
if (opts.image) {
|
|
6459
6487
|
resolvedImage = resolve7(opts.cwd ?? process.cwd(), opts.image);
|
|
6460
|
-
if (!
|
|
6488
|
+
if (!existsSync16(resolvedImage)) {
|
|
6461
6489
|
throw new BootError("BOOT_IMAGE_NOT_FOUND", `restore: image not found: ${resolvedImage}`);
|
|
6462
6490
|
}
|
|
6463
|
-
} else if (meta.sourceImage &&
|
|
6491
|
+
} else if (meta.sourceImage && existsSync16(meta.sourceImage)) {
|
|
6464
6492
|
resolvedImage = meta.sourceImage;
|
|
6465
6493
|
debugRestore("using meta.sourceImage path=%s", resolvedImage);
|
|
6466
6494
|
} else if (meta.sourceImage) {
|
|
@@ -6546,7 +6574,7 @@ async function restore(opts) {
|
|
|
6546
6574
|
if (meta.mountDisk) {
|
|
6547
6575
|
const lowerAbs = join14(snapDir, meta.mountDisk.lower);
|
|
6548
6576
|
const upperAbs = join14(snapDir, meta.mountDisk.upper);
|
|
6549
|
-
if (!
|
|
6577
|
+
if (!existsSync16(lowerAbs) || !existsSync16(upperAbs)) {
|
|
6550
6578
|
throw new BootError(
|
|
6551
6579
|
"BOOT_SNAPSHOT_NOT_FOUND",
|
|
6552
6580
|
`restore: bundle's mount overlay is missing one of:
|
|
@@ -6889,7 +6917,7 @@ function resolveBaseDtb(explicit, cwd = process.cwd()) {
|
|
|
6889
6917
|
function resolveBaseAsset(spec, explicit, cwd) {
|
|
6890
6918
|
if (explicit) {
|
|
6891
6919
|
const abs = resolve9(cwd, explicit);
|
|
6892
|
-
if (!
|
|
6920
|
+
if (!existsSync17(abs)) {
|
|
6893
6921
|
throw new ProvisionError(spec.missingCode, `${spec.kind} not found: ${abs}`);
|
|
6894
6922
|
}
|
|
6895
6923
|
return abs;
|
|
@@ -6897,7 +6925,7 @@ function resolveBaseAsset(spec, explicit, cwd) {
|
|
|
6897
6925
|
const assetsDir = process.env.MACHINEN_ASSETS_DIR;
|
|
6898
6926
|
if (assetsDir) {
|
|
6899
6927
|
const p = resolve9(assetsDir, spec.assetsDirName);
|
|
6900
|
-
if (!
|
|
6928
|
+
if (!existsSync17(p)) {
|
|
6901
6929
|
throw new ProvisionError(
|
|
6902
6930
|
"PROVISION_ASSETS_DIR_INVALID",
|
|
6903
6931
|
`MACHINEN_ASSETS_DIR=${assetsDir} does not contain ${spec.assetsDirName}`
|
|
@@ -6906,7 +6934,7 @@ function resolveBaseAsset(spec, explicit, cwd) {
|
|
|
6906
6934
|
return p;
|
|
6907
6935
|
}
|
|
6908
6936
|
const cached = join16(cliCachedBaseDir(), spec.cliCacheName);
|
|
6909
|
-
if (
|
|
6937
|
+
if (existsSync17(cached)) {
|
|
6910
6938
|
return cached;
|
|
6911
6939
|
}
|
|
6912
6940
|
throw new ProvisionError(
|
|
@@ -6928,6 +6956,7 @@ async function provision(opts) {
|
|
|
6928
6956
|
const kernelAbs = resolveBaseKernel(opts.kernel, cwd);
|
|
6929
6957
|
const dtbAbs = resolveBaseDtb(opts.dtb, cwd);
|
|
6930
6958
|
const outAbs = resolve9(cwd, opts.out);
|
|
6959
|
+
mkdirSync12(dirname9(outAbs), { recursive: true });
|
|
6931
6960
|
const t0 = Date.now();
|
|
6932
6961
|
const workDir = mkdtempSync8(join16(tmpdir8(), "machinen-provision-"));
|
|
6933
6962
|
const diskPath = join16(workDir, "scratch.img");
|