@ai-ecoverse/slicc-kernel 1.56.0 → 1.56.2

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.
@@ -438,12 +438,34 @@ var OpfsFs = class {
438
438
  const link2 = await this.linkAlong(current);
439
439
  if (!link2) throw err;
440
440
  if (link2.path === current && !follow2) return { path: current, link: link2 };
441
- const rest2 = current.slice(link2.path.length);
442
- current = resolvePath(parentOf2(link2.path), `${link2.link}${rest2}`);
441
+ const target = `${link2.link}${current.slice(link2.path.length)}`;
442
+ current = target.split("/").includes("..") ? await this.physical(parentOf2(link2.path), target, hops + 1) : resolvePath(parentOf2(link2.path), target);
443
443
  }
444
444
  }
445
445
  throw fsError("ELOOP", path);
446
446
  }
447
+ async physical(base, path, used) {
448
+ let done4 = [];
449
+ let todo = (path.startsWith("/") ? path : `${base}/${path}`).split("/").filter((p) => p !== "" && p !== ".");
450
+ for (let hops = used; todo.length > 0; ) {
451
+ const part = todo.shift();
452
+ if (part === "..") done4.pop();
453
+ else if (!todo.includes("..")) done4.push(part);
454
+ else {
455
+ const at = `/${[...done4, part].join("/")}`;
456
+ const st = await this.lstat(at);
457
+ if (!st.isSymbolicLink && !st.isDirectory) throw fsError("ENOTDIR", at);
458
+ if (!st.isSymbolicLink) done4.push(part);
459
+ else if (++hops > MAX_LINKS) throw fsError("ELOOP", path);
460
+ else {
461
+ const link2 = await this.readlink(at);
462
+ if (link2.startsWith("/")) done4 = [];
463
+ todo = [...link2.split("/").filter((p) => p !== "" && p !== "."), ...todo];
464
+ }
465
+ }
466
+ }
467
+ return `/${done4.join("/")}`;
468
+ }
447
469
  mode(path, directory, meta) {
448
470
  const fallback = directory || EXECUTABLE.test(path) ? 493 : 420;
449
471
  return (directory ? S_IFDIR : S_IFREG) | (meta?.mode ?? fallback);
@@ -9631,6 +9653,11 @@ var MAX_LINKS5 = 40;
9631
9653
  function parentOf6(path) {
9632
9654
  return path.slice(0, path.lastIndexOf("/")) || "/";
9633
9655
  }
9656
+ async function mustBeDir(fs, path) {
9657
+ if (!fs.lstat) return;
9658
+ const st = await fs.lstat(path);
9659
+ if (st.isDirectory !== true) throw fsError("ENOTDIR", path);
9660
+ }
9634
9661
  async function linkOf(fs, path) {
9635
9662
  return fs.readlink?.(path).catch(() => void 0);
9636
9663
  }
@@ -9647,6 +9674,7 @@ async function realDir(fs, dir, budget = { hops: 0 }) {
9647
9674
  const next2 = at === "/" ? `/${part}` : `${at}/${part}`;
9648
9675
  const link2 = await linkOf(fs, next2);
9649
9676
  if (link2 === void 0) {
9677
+ if (queue.find((p) => p !== ".") === "..") await mustBeDir(fs, next2);
9650
9678
  at = next2;
9651
9679
  continue;
9652
9680
  }
@@ -11905,7 +11933,7 @@ var HostfsClient = class {
11905
11933
  false,
11906
11934
  true
11907
11935
  );
11908
- await response.body?.cancel();
11936
+ return response.json().catch(() => null);
11909
11937
  }
11910
11938
  async read(fh, offset, size, ifMatch) {
11911
11939
  const response = await this.send(
@@ -11961,7 +11989,8 @@ var HostfsClient = class {
11961
11989
  }
11962
11990
  }
11963
11991
  };
11964
- function hostfsHandlers(current) {
11992
+ var RESTORE_AGAIN_MS = 3e4;
11993
+ function hostfsHandlers(current, againMs = RESTORE_AGAIN_MS) {
11965
11994
  const handles = /* @__PURE__ */ new Map();
11966
11995
  let nextFh = 0;
11967
11996
  const fresh = (remote) => {
@@ -11974,10 +12003,18 @@ function hostfsHandlers(current) {
11974
12003
  return fresh(remote);
11975
12004
  };
11976
12005
  const call = (op, body = {}) => current().call(op, body);
11977
- const settle3 = (client, restore) => client.call("setattr", restore).catch((err) => {
12006
+ const same = (was, mode, seen) => seen?.mode === (mode | 128) && (was.ino !== void 0 && seen.ino !== void 0 ? seen.ino === was.ino : seen.size === was.size && seen.mtime === was.mtime);
12007
+ const settle3 = (client, { was, ...restore }) => client.call("setattr", restore).catch((err) => {
11978
12008
  if (!client.gone || !client.cleanup) throw err;
11979
12009
  void client.cleanup("setattr", restore).catch(() => {
11980
12010
  });
12011
+ const timer = setTimeout(async () => {
12012
+ const seen = await client.cleanup?.("stat", { path: restore.path }).catch(() => null);
12013
+ if (same(was, restore.mode, seen))
12014
+ void client.cleanup?.("setattr", restore).catch(() => {
12015
+ });
12016
+ }, againMs);
12017
+ timer.unref?.();
11981
12018
  });
11982
12019
  async function writable(client, path, flags) {
11983
12020
  const { ifMatch: _, ...asked } = flags;
@@ -11986,9 +12023,10 @@ function hostfsHandlers(current) {
11986
12023
  return { opened: await opening(), restore: void 0 };
11987
12024
  } catch (err) {
11988
12025
  if (!flags.write || codeOf4(err) !== "EACCES") throw err;
11989
- const mode = (await client.call("stat", { path: rel(path) })).mode ?? 0;
12026
+ const was = await client.call("stat", { path: rel(path) });
12027
+ const mode = was.mode ?? 0;
11990
12028
  if (mode & 128) throw err;
11991
- const restore = { path: rel(path), mode };
12029
+ const restore = { path: rel(path), mode, was };
11992
12030
  const opened2 = await client.call("setattr", { path: rel(path), mode: mode | 128 }).then(opening).catch(async (again) => {
11993
12031
  await settle3(client, restore).catch(() => {
11994
12032
  });
@@ -12209,7 +12247,7 @@ function timed(transport, ms) {
12209
12247
  });
12210
12248
  const cleanup = async (op, body, skip) => {
12211
12249
  await Promise.allSettled([...inflight].filter((work) => work !== skip));
12212
- await transport.cleanup?.(op, body);
12250
+ return await transport.cleanup?.(op, body);
12213
12251
  };
12214
12252
  const release = (opened2) => {
12215
12253
  const fh = opened2?.fh;