@ai-ecoverse/slicc-kernel 1.117.3 → 1.117.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.
@@ -5381,7 +5381,7 @@ var KERNEL_VERSION, OS_RELEASE;
5381
5381
  var init_version = __esm({
5382
5382
  "src/version.ts"() {
5383
5383
  "use strict";
5384
- KERNEL_VERSION = true ? "1.117.3" : "0.0.0-dev";
5384
+ KERNEL_VERSION = true ? "1.117.5" : "0.0.0-dev";
5385
5385
  OS_RELEASE = "6.0.0-slicc";
5386
5386
  }
5387
5387
  });
@@ -5878,7 +5878,7 @@ function checkOpen(abs, o, existing) {
5878
5878
  function flagsOf(o) {
5879
5879
  const write2 = o.write || o.append || o.truncate;
5880
5880
  const access = write2 ? o.read ? O_RDWR3 : O_WRONLY3 : 0;
5881
- return access | (o.append ? O_APPEND3 : 0);
5881
+ return access | (o.append ? O_APPEND3 : 0) | (o.nonblock ? O_NONBLOCK_OPEN : 0);
5882
5882
  }
5883
5883
  function openRequest2(abs, o) {
5884
5884
  return {
@@ -5894,7 +5894,7 @@ function openRequest2(abs, o) {
5894
5894
  function index2(n, what) {
5895
5895
  if (!Number.isSafeInteger(n) || n < 0) throw new JsCallError("EINVAL", what);
5896
5896
  }
5897
- 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;
5898
5898
  var init_js_io = __esm({
5899
5899
  "src/process/js/js-io.ts"() {
5900
5900
  "use strict";
@@ -5906,6 +5906,7 @@ var init_js_io = __esm({
5906
5906
  O_RDWR3 = 2;
5907
5907
  O_APPEND3 = 1024;
5908
5908
  BLOCK = 4096;
5909
+ O_NONBLOCK_OPEN = 2048;
5909
5910
  }
5910
5911
  });
5911
5912
 
@@ -11277,9 +11278,60 @@ async function vfsStat(kernel, abs, op, tryDev) {
11277
11278
  return devAsync(kernel, devStat(devPath, op === "stat"));
11278
11279
  }
11279
11280
  }
11280
- 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;
11281
11330
  const existing = await statOf(isExclusive(options) ? "lstat" : "stat", abs).catch(absent);
11282
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);
11283
11335
  const fd = await kernel.json(openRequest2(abs, options));
11284
11336
  try {
11285
11337
  await kernel.call({ op: "fd-vfs-stat", fd });
@@ -11348,11 +11400,11 @@ function createContext(o) {
11348
11400
  return vfsStat(kernel, abs, op, tryDev);
11349
11401
  };
11350
11402
  const devIo = { infos, handles, read: read2, write: writeAll };
11351
- const open = async (path, options = {}) => {
11403
+ const open = async (path, options = {}, whole = false) => {
11352
11404
  const abs = resolve(path);
11353
11405
  if (inDev(abs)) return openDev(kernel, abs, options, devIo);
11354
11406
  try {
11355
- return await vfsOpen(kernel, abs, options, statOf, infos, handles);
11407
+ return await vfsOpen(kernel, abs, options, statOf, devIo, whole);
11356
11408
  } catch (err) {
11357
11409
  if (!(err instanceof JsCallError) || err.code !== "ENOENT") throw err;
11358
11410
  const devPath = await tryDev(abs);
@@ -11617,12 +11669,11 @@ function pathOps(kernel, resolve, statOf, open, tryDev) {
11617
11669
  },
11618
11670
  async writeFile(path, data, options) {
11619
11671
  const mode = options?.mode;
11620
- const file = await open(path, {
11621
- write: true,
11622
- create: true,
11623
- truncate: true,
11624
- ...mode !== void 0 ? { mode } : {}
11625
- });
11672
+ const file = await open(
11673
+ path,
11674
+ { write: true, create: true, truncate: true, ...mode !== void 0 ? { mode } : {} },
11675
+ true
11676
+ );
11626
11677
  try {
11627
11678
  await file.write(0, typeof data === "string" ? encoder4.encode(data) : data);
11628
11679
  } finally {