@ai-ecoverse/slicc-kernel 1.117.2 → 1.117.4

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.
@@ -3995,15 +3995,19 @@ var init_wasi_host = __esm({
3995
3995
  locked: () => this.fds.holdLocks(),
3996
3996
  promote: (fd) => this.fds.promote(fd),
3997
3997
  calls: {
3998
- flock: (fd, kind, wait2) => void this.o.kernel.call({ op: "flock", fd, kind, ...wait2 ? { wait: wait2 } : {} }),
3999
- set: (target, kind, start2, len, wait2) => void this.o.kernel.call({
4000
- op: "lk-set",
4001
- ...target,
4002
- kind,
4003
- start: start2,
4004
- len,
4005
- ...wait2 ? { wait: wait2 } : {}
4006
- }),
3998
+ flock: (fd, kind, wait2) => void this.fds.restarting(
3999
+ () => this.o.kernel.call({ op: "flock", fd, kind, ...wait2 ? { wait: wait2 } : {} })
4000
+ ),
4001
+ set: (target, kind, start2, len, wait2) => void this.fds.restarting(
4002
+ () => this.o.kernel.call({
4003
+ op: "lk-set",
4004
+ ...target,
4005
+ kind,
4006
+ start: start2,
4007
+ len,
4008
+ ...wait2 ? { wait: wait2 } : {}
4009
+ })
4010
+ ),
4007
4011
  get: (target, kind, start2, len) => this.o.kernel.call({ op: "lk-get", ...target, kind, start: start2, len })
4008
4012
  }
4009
4013
  }),
@@ -5377,7 +5381,7 @@ var KERNEL_VERSION, OS_RELEASE;
5377
5381
  var init_version = __esm({
5378
5382
  "src/version.ts"() {
5379
5383
  "use strict";
5380
- KERNEL_VERSION = true ? "1.117.2" : "0.0.0-dev";
5384
+ KERNEL_VERSION = true ? "1.117.4" : "0.0.0-dev";
5381
5385
  OS_RELEASE = "6.0.0-slicc";
5382
5386
  }
5383
5387
  });
@@ -5874,7 +5878,7 @@ function checkOpen(abs, o, existing) {
5874
5878
  function flagsOf(o) {
5875
5879
  const write2 = o.write || o.append || o.truncate;
5876
5880
  const access = write2 ? o.read ? O_RDWR3 : O_WRONLY3 : 0;
5877
- return access | (o.append ? O_APPEND3 : 0);
5881
+ return access | (o.append ? O_APPEND3 : 0) | (o.nonblock ? O_NONBLOCK_OPEN : 0);
5878
5882
  }
5879
5883
  function openRequest2(abs, o) {
5880
5884
  return {
@@ -5890,7 +5894,7 @@ function openRequest2(abs, o) {
5890
5894
  function index2(n, what) {
5891
5895
  if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
5892
5896
  }
5893
- var CHUNK, MAX_IO, O_WRONLY3, O_RDWR3, O_APPEND3, BLOCK;
5897
+ var CHUNK, MAX_IO, O_WRONLY3, O_RDWR3, O_APPEND3, BLOCK, O_NONBLOCK_OPEN;
5894
5898
  var init_js_io = __esm({
5895
5899
  "src/process/js/js-io.ts"() {
5896
5900
  "use strict";
@@ -5902,6 +5906,7 @@ var init_js_io = __esm({
5902
5906
  O_RDWR3 = 2;
5903
5907
  O_APPEND3 = 1024;
5904
5908
  BLOCK = 4096;
5909
+ O_NONBLOCK_OPEN = 2048;
5905
5910
  }
5906
5911
  });
5907
5912
 
@@ -11273,9 +11278,60 @@ async function vfsStat(kernel, abs, op, tryDev) {
11273
11278
  return devAsync(kernel, devStat(devPath, op === "stat"));
11274
11279
  }
11275
11280
  }
11276
- async function vfsOpen(kernel, abs, options, statOf, infos, handles) {
11281
+ async function fifoOpen(kernel, abs, options, io) {
11282
+ options.signal?.throwIfAborted();
11283
+ const req = { ...openRequest2(abs, { ...options, create: false }), fifo: true };
11284
+ const r = await kernel.blocking(req, options.signal);
11285
+ const fd = r.ok && r.kind === "json" ? r.json : -1;
11286
+ io.infos.set(fd, { kind: "stream" });
11287
+ let open = true;
11288
+ const live = () => {
11289
+ if (!open) throw new JsCallError("EBADF", abs);
11290
+ };
11291
+ const seekless = (position, what) => {
11292
+ live();
11293
+ if (position !== 0) throw new JsCallError("ESPIPE", what);
11294
+ };
11295
+ io.handles.set(fd, () => {
11296
+ open = false;
11297
+ });
11298
+ return {
11299
+ fd,
11300
+ path: abs,
11301
+ async size() {
11302
+ live();
11303
+ return 0;
11304
+ },
11305
+ async read(position, length) {
11306
+ seekless(position, "read");
11307
+ return io.read(fd, length);
11308
+ },
11309
+ async write(position, data) {
11310
+ seekless(position, "write");
11311
+ await io.write(fd, data);
11312
+ return data.length;
11313
+ },
11314
+ async truncate() {
11315
+ live();
11316
+ throw new JsCallError("EINVAL", "truncate");
11317
+ },
11318
+ sync: async () => live(),
11319
+ async close() {
11320
+ if (!open) return;
11321
+ open = false;
11322
+ io.infos.delete(fd);
11323
+ io.handles.delete(fd);
11324
+ await kernel.raw({ op: "fd-close", fd });
11325
+ }
11326
+ };
11327
+ }
11328
+ async function vfsOpen(kernel, abs, options, statOf, io, whole) {
11329
+ const { infos, handles } = io;
11277
11330
  const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
11278
11331
  checkOpen(abs, options, existing);
11332
+ const special = existing?.isSocket || whole && existing?.isFifo;
11333
+ if (special && !isExclusive(options)) throw new JsCallError("ENXIO", abs);
11334
+ if (existing?.isFifo && !isExclusive(options)) return fifoOpen(kernel, abs, options, io);
11279
11335
  const fd = await kernel.json(openRequest2(abs, options));
11280
11336
  try {
11281
11337
  await kernel.call({ op: "fd-vfs-stat", fd });
@@ -11344,11 +11400,11 @@ function createContext(o) {
11344
11400
  return vfsStat(kernel, abs, op, tryDev);
11345
11401
  };
11346
11402
  const devIo = { infos, handles, read: read2, write: writeAll };
11347
- const open = async (path, options = {}) => {
11403
+ const open = async (path, options = {}, whole = false) => {
11348
11404
  const abs = resolve(path);
11349
11405
  if (inDev(abs)) return openDev(kernel, abs, options, devIo);
11350
11406
  try {
11351
- return await vfsOpen(kernel, abs, options, statOf, infos, handles);
11407
+ return await vfsOpen(kernel, abs, options, statOf, devIo, whole);
11352
11408
  } catch (err) {
11353
11409
  if (!(err instanceof JsCallError) || err.code !== "ENOENT") throw err;
11354
11410
  const devPath = await tryDev(abs);
@@ -11613,12 +11669,11 @@ function pathOps(kernel, resolve, statOf, open, tryDev) {
11613
11669
  },
11614
11670
  async writeFile(path, data, options) {
11615
11671
  const mode = options?.mode;
11616
- const file = await open(path, {
11617
- write: true,
11618
- create: true,
11619
- truncate: true,
11620
- ...mode !== void 0 ? { mode } : {}
11621
- });
11672
+ const file = await open(
11673
+ path,
11674
+ { write: true, create: true, truncate: true, ...mode !== void 0 ? { mode } : {} },
11675
+ true
11676
+ );
11622
11677
  try {
11623
11678
  await file.write(0, typeof data === "string" ? encoder4.encode(data) : data);
11624
11679
  } finally {