@ai-ecoverse/slicc-kernel 1.17.3 → 1.17.5

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
@@ -2107,7 +2107,8 @@ function statOf(attr, path, mount) {
2107
2107
  ctime: mtime,
2108
2108
  ino: attr.ino ?? inodeOf(path),
2109
2109
  dev: mount.dev,
2110
- ...readonly(mount) ? { readonly: true } : {}
2110
+ ...readonly(mount) ? { readonly: true } : {},
2111
+ ...mount.maxFile > 0 ? { maxFile: mount.maxFile } : {}
2111
2112
  };
2112
2113
  }
2113
2114
  function concat2(chunks2, total) {
@@ -2593,7 +2594,8 @@ function statJson(s) {
2593
2594
  ctimeMs: s.ctime.getTime(),
2594
2595
  ino: s.ino,
2595
2596
  ...s.dev !== void 0 ? { dev: s.dev } : {},
2596
- ...s.readonly ? { readonly: true } : {}
2597
+ ...s.readonly ? { readonly: true } : {},
2598
+ ...s.maxFile ? { maxFile: s.maxFile } : {}
2597
2599
  };
2598
2600
  }
2599
2601
  async function readdirStat(fs, dir) {
@@ -5351,7 +5353,29 @@ var VfsNode = class {
5351
5353
  const n = Math.max(0, Math.min(max, this.length - at));
5352
5354
  return bytes.slice(at, at + n);
5353
5355
  }
5356
+ cap;
5357
+ limit() {
5358
+ if (this.cap !== void 0) return this.cap;
5359
+ const stat = this.fs.stat?.bind(this.fs);
5360
+ if (!stat || this.orphaned) return Promise.resolve(void 0);
5361
+ const parent = this.path.slice(0, this.path.lastIndexOf("/")) || "/";
5362
+ this.cap ??= stat(this.path).catch(() => stat(parent)).then(
5363
+ (st) => st.maxFile,
5364
+ () => void 0
5365
+ );
5366
+ return this.cap;
5367
+ }
5368
+ async fits(end) {
5369
+ const max = await this.limit();
5370
+ if (max !== void 0 && end > max) throw new KernelError("EFBIG");
5371
+ }
5372
+ renamedTo(path) {
5373
+ this.path = path;
5374
+ this.cap = void 0;
5375
+ }
5354
5376
  async pwrite(bytes, at) {
5377
+ if (bytes.length === 0) return 0;
5378
+ await this.fits(at + bytes.length);
5355
5379
  await this.load();
5356
5380
  const buf = this.ensure(at + bytes.length);
5357
5381
  if (at > this.length) buf.fill(0, this.length, at);
@@ -5361,6 +5385,7 @@ var VfsNode = class {
5361
5385
  return bytes.length;
5362
5386
  }
5363
5387
  async truncate(size) {
5388
+ await this.fits(size);
5364
5389
  await this.load();
5365
5390
  const buf = this.ensure(size);
5366
5391
  if (size > this.length) buf.fill(0, this.length, size);
@@ -5437,7 +5462,7 @@ var VfsNodes = class {
5437
5462
  }
5438
5463
  async unlinking(path) {
5439
5464
  const node = this.byPath.get(path);
5440
- if (node) await node.serial(() => node.load());
5465
+ if (node) await node.serial(async () => void await Promise.all([node.load(), node.limit()]));
5441
5466
  }
5442
5467
  revoke(prefix) {
5443
5468
  for (const [path, node] of this.byPath) {
@@ -5464,7 +5489,7 @@ var VfsNodes = class {
5464
5489
  }
5465
5490
  for (const node of moved2) {
5466
5491
  this.byPath.delete(node.path);
5467
- node.path = to + node.path.slice(from.length);
5492
+ node.renamedTo(to + node.path.slice(from.length));
5468
5493
  this.byPath.set(node.path, node);
5469
5494
  }
5470
5495
  }
@@ -6167,6 +6192,7 @@ var WasmProcess = class {
6167
6192
  if (this.exited) return;
6168
6193
  this.exited = true;
6169
6194
  this.clearAlarm();
6195
+ this.interrupt.abort();
6170
6196
  this.options.locks?.release(this.pid);
6171
6197
  this.asyncOps.close();
6172
6198
  for (const pid of this.children.pids()) this.options.onReap?.(pid);
@@ -8002,6 +8028,10 @@ var Launcher = class {
8002
8028
  for (const nodes of this.openFiles) nodes.revoke(at);
8003
8029
  for (const holds of this.held) holds.revoke(at);
8004
8030
  }
8031
+ unmountAll() {
8032
+ const targets = this.mounts.list().map((m) => m.target);
8033
+ for (const target of targets.sort((a, b) => b.length - a.length)) this.umount(target, true);
8034
+ }
8005
8035
  async permit(req) {
8006
8036
  const policy = this.processMounts;
8007
8037
  const allowed = typeof policy === "function" ? await policy(req) : policy;
@@ -8829,6 +8859,7 @@ async function createNodeKernel(options = {}) {
8829
8859
  for (const client of [...clients]) client.detach();
8830
8860
  for (const reject of [...pending]) reject(new Error(TERMINATED));
8831
8861
  for (const kill of [...live]) kill();
8862
+ launcher.unmountAll();
8832
8863
  }
8833
8864
  };
8834
8865
  }