@ai-ecoverse/slicc-kernel 1.26.4 → 1.26.6

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/dist/node.js CHANGED
@@ -6709,8 +6709,10 @@ var VfsNodes = class {
6709
6709
  for (const [p, node] of this.byPath) if (within3(p, path)) await node.serial(() => node.flush());
6710
6710
  }
6711
6711
  async unlinking(path) {
6712
- const node = this.byPath.get(path);
6713
- if (node) await node.serial(async () => void await Promise.all([node.keep(), node.limit()]));
6712
+ for (const [held, node] of [...this.byPath]) {
6713
+ if (!within3(held, path)) continue;
6714
+ await node.serial(async () => void await Promise.all([node.keep(), node.limit()]));
6715
+ }
6714
6716
  }
6715
6717
  revoke(prefix) {
6716
6718
  for (const [path, node] of this.byPath) {
@@ -6720,10 +6722,11 @@ var VfsNodes = class {
6720
6722
  }
6721
6723
  }
6722
6724
  unlinked(path) {
6723
- const node = this.byPath.get(path);
6724
- if (!node) return;
6725
- node.orphaned = true;
6726
- this.byPath.delete(path);
6725
+ for (const [held, node] of [...this.byPath]) {
6726
+ if (!within3(held, path)) continue;
6727
+ node.orphaned = true;
6728
+ this.byPath.delete(held);
6729
+ }
6727
6730
  }
6728
6731
  renamed(from, to) {
6729
6732
  if (from === to) return;
@@ -6797,6 +6800,23 @@ async function refuseReadonly(fs, path, flags, opts = {}) {
6797
6800
  const st = own ?? await stat(await targetDir(fs, path));
6798
6801
  if (st?.readonly) throw new KernelError("EROFS");
6799
6802
  }
6803
+ function keepingOpen(fs, nodes) {
6804
+ return {
6805
+ ...fs,
6806
+ async rm(path, options) {
6807
+ const at = fs.resolvePath("/", path);
6808
+ await nodes.unlinking(at);
6809
+ await fs.rm(path, options);
6810
+ nodes.unlinked(at);
6811
+ },
6812
+ async rename(from, to) {
6813
+ const [a, b] = [fs.resolvePath("/", from), fs.resolvePath("/", to)];
6814
+ await nodes.unlinking(b);
6815
+ await fs.rename(from, to);
6816
+ nodes.renamed(a, b);
6817
+ }
6818
+ };
6819
+ }
6800
6820
  function vfsFile(fs, opts, nodes) {
6801
6821
  const access = opts.flags & O_ACCMODE;
6802
6822
  const readable = access !== O_WRONLY;
@@ -6992,8 +7012,8 @@ var WasmProcess = class {
6992
7012
  this.options = options;
6993
7013
  this.inherited = options.ignored ?? 0;
6994
7014
  this.children = new ChildTable(fds, options.spawner, options.forker);
6995
- this.nodes = new VfsNodes(options.fs);
6996
- options.openFiles?.add(this.nodes);
7015
+ this.nodes = options.nodes ?? new VfsNodes(options.fs);
7016
+ if (!options.nodes) options.openFiles?.add(this.nodes);
6997
7017
  this.children.onChildState = () => this.signal(SIG.CHLD);
6998
7018
  this.children.onReap = options.onReap;
6999
7019
  }
@@ -7496,7 +7516,7 @@ var WasmProcess = class {
7496
7516
  this.asyncOps.close();
7497
7517
  for (const pid of this.children.pids()) this.options.onReap?.(pid);
7498
7518
  await this.fds.closeAll();
7499
- this.options.openFiles?.delete(this.nodes);
7519
+ if (!this.options.nodes) this.options.openFiles?.delete(this.nodes);
7500
7520
  await this.options.http?.closeAll();
7501
7521
  }
7502
7522
  };
@@ -7546,6 +7566,7 @@ function spawnWasmProcess(opts) {
7546
7566
  kill: opts.kill,
7547
7567
  processes: opts.processes,
7548
7568
  openFiles: opts.openFiles,
7569
+ ...opts.nodes ? { nodes: opts.nodes } : {},
7549
7570
  mounts: opts.mounts,
7550
7571
  ...opts.mount ? { mount: opts.mount } : {},
7551
7572
  ...opts.umount ? { umount: opts.umount } : {},
@@ -9019,6 +9040,7 @@ var ENV_REFERENCE = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
9019
9040
  var WASM_MAGIC = [0, 97, 115, 109];
9020
9041
  var SHEBANG_MAX = 256;
9021
9042
  var NOT_FOUND = 127;
9043
+ var INIT_PID = 1;
9022
9044
  var SHARED_DIRS = ["/tmp", "/home"];
9023
9045
  var encoder3 = new TextEncoder();
9024
9046
  function baseName(path) {
@@ -9113,6 +9135,7 @@ var Launcher = class {
9113
9135
  fstabRetries;
9114
9136
  inserted = /* @__PURE__ */ new Map();
9115
9137
  openFiles = /* @__PURE__ */ new Set();
9138
+ nodes;
9116
9139
  held = /* @__PURE__ */ new Set();
9117
9140
  processMounts;
9118
9141
  booting = new AbortController();
@@ -9146,7 +9169,10 @@ var Launcher = class {
9146
9169
  ca: this.ca
9147
9170
  });
9148
9171
  enableCdp(this.net, this.cdp);
9149
- this.fs = withCommandDirs(this.base, async () => new Set((await this.commands()).keys()));
9172
+ const fs = withCommandDirs(this.base, async () => new Set((await this.commands()).keys()));
9173
+ this.nodes = new VfsNodes(fs);
9174
+ this.openFiles.add(this.nodes);
9175
+ this.fs = keepingOpen(fs, this.nodes);
9150
9176
  this.watchers.watch([this.modulesDir, this.pnpmHome], { recursive: true }, () => {
9151
9177
  this.catalog = void 0;
9152
9178
  });
@@ -9319,6 +9345,7 @@ var Launcher = class {
9319
9345
  kill: (target, sig) => this.kill(target, sig),
9320
9346
  processes: () => ({ boot: this.boot, processes: this.list() }),
9321
9347
  openFiles: this.openFiles,
9348
+ nodes: this.nodes,
9322
9349
  held: this.held,
9323
9350
  statfs: (path) => this.mounts.statfs(path),
9324
9351
  mounts: () => this.mounts.list(),
@@ -9374,7 +9401,7 @@ var Launcher = class {
9374
9401
  };
9375
9402
  const shown = (pid) => {
9376
9403
  const member = pid === void 0 ? void 0 : members.get(pid);
9377
- return member ? rootOf(member).pid : pid ?? 0;
9404
+ return member ? rootOf(member).pid : INIT_PID;
9378
9405
  };
9379
9406
  const listed = [];
9380
9407
  for (const member of members.values()) {