@ai-ecoverse/slicc-kernel 1.61.0 → 1.61.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.
@@ -1675,6 +1675,11 @@ function createSyncFsSabBridge(transport, opts = {}) {
1675
1675
  ...io({}),
1676
1676
  pinned: (handle) => io({ handle }),
1677
1677
  kept: (handle) => json({ op: "kept", path: "/", handle }, "/") === true,
1678
+ keptStat: (handle) => {
1679
+ const s = parseSyncFsStat(json({ op: "stat", path: "/", handle }, "/"));
1680
+ if (!s) throw errnoError("EIO", "/");
1681
+ return s;
1682
+ },
1678
1683
  stat: (path) => {
1679
1684
  const s = parseSyncFsStat(json({ op: "stat", path }, path));
1680
1685
  if (!s) throw errnoError("EIO", path);
@@ -4763,6 +4768,7 @@ function cachingBridge(bridge, now = () => performance.now(), shared) {
4763
4768
  lutimes: (p, a, m) => mutating(() => bridge.lutimes(p, a, m), p),
4764
4769
  ...bridge.hold ? { hold: bridge.hold.bind(bridge) } : {},
4765
4770
  ...bridge.kept ? { kept: bridge.kept.bind(bridge) } : {},
4771
+ ...bridge.keptStat ? { keptStat: bridge.keptStat.bind(bridge) } : {},
4766
4772
  ...bridge.pinned ? { pinned: (handle) => pinnedIo2(bridge, handle, rewriting) } : {},
4767
4773
  ...bridge.create ? { create: (p) => mutating(() => bridge.create?.(p), ...entry(p)) } : {},
4768
4774
  ...chown ? {
@@ -5655,9 +5661,34 @@ var init_wasi_fds = __esm({
5655
5661
  }
5656
5662
  if (!s && !(oflags & OFLAGS.CREAT)) throw new WasiError("ENOENT");
5657
5663
  refuseWrite(s, oflags, rights);
5658
- if (this.shared) return this.kernelFile(path, s, oflags, rights, fdflags);
5664
+ return this.regular(path, s, oflags, rights, fdflags);
5665
+ }
5666
+ regular(path, s, oflags, rights, fdflags) {
5667
+ if (this.shared || this.kernelHolds(path, s)) {
5668
+ return this.kernelFile(path, s, oflags, rights, fdflags);
5669
+ }
5659
5670
  return this.install({ type: "file", file: this.file(path, s, oflags, rights, fdflags) });
5660
5671
  }
5672
+ kernelHolds(path, st) {
5673
+ for (const [fd, e] of this.table) {
5674
+ if (e.type !== "kernel" || this.kind(fd, e) !== "file") continue;
5675
+ this.named(fd, e);
5676
+ if (e.path === path || st?.ino !== void 0 && e.ino === st.ino) return true;
5677
+ }
5678
+ return false;
5679
+ }
5680
+ learned = /* @__PURE__ */ new WeakSet();
5681
+ named(fd, e) {
5682
+ if (e.path !== void 0 || this.learned.has(e)) return;
5683
+ this.learned.add(e);
5684
+ try {
5685
+ const vfs = this.kernel.call({ op: "fd-vfs-stat", fd });
5686
+ if (vfs.orphan || vfs.path === void 0) return;
5687
+ e.path = vfs.path;
5688
+ e.ino = this.inoOf(vfs.path);
5689
+ } catch {
5690
+ }
5691
+ }
5661
5692
  file(path, existing, oflags, rights, fdflags) {
5662
5693
  const { readable: readable2, writable: writable2 } = openAccess(existing, oflags, rights);
5663
5694
  let buffer = this.buffers.get(path);
@@ -6699,16 +6730,41 @@ var init_wasi_host = __esm({
6699
6730
  fdFilestat(fd) {
6700
6731
  const e = this.fds.get(fd);
6701
6732
  if (e.type === "dir") return filestatOf(e.path, this.o.fs.stat(e.path));
6702
- if (e.type === "file") return this.statOrphanable(e.file.path, e.file.size());
6733
+ if (e.type === "file") return this.localFilestat(e.file);
6703
6734
  const kind = e.type === "kernel" ? this.fds.kind(fd, e) : void 0;
6704
6735
  if (kind === "file") {
6705
6736
  const vfs = this.kernelStat(fd);
6706
- if (vfs.path) return this.statOrphanable(vfs.path, vfs.size, vfs.orphan);
6737
+ if (vfs.path) return this.statOrphanable(vfs.path, vfs.size, vfs.orphan, vfs.orphan);
6707
6738
  }
6708
6739
  const filetype = kind ? kernelFiletype(kind).filetype : FILETYPE.CHARACTER_DEVICE;
6709
6740
  return this.local({ filetype, size: 0n, ino: BigInt(fd + 1), mtimeNs: 0n });
6710
6741
  }
6711
- statOrphanable(path, size, orphan = false) {
6742
+ localFilestat(file) {
6743
+ const { buffer } = file;
6744
+ if (buffer.isOrphan()) return this.statOrphanable(file.path, file.size(), false, true);
6745
+ let s;
6746
+ try {
6747
+ s = this.o.fs.stat(file.path);
6748
+ } catch {
6749
+ s = this.keptStat(buffer.handle);
6750
+ }
6751
+ return this.sized(file.path, s, file.size());
6752
+ }
6753
+ keptStat(handle) {
6754
+ if (handle === void 0) return void 0;
6755
+ try {
6756
+ return this.o.fs.keptStat?.(handle);
6757
+ } catch {
6758
+ return void 0;
6759
+ }
6760
+ }
6761
+ sized(path, s, size) {
6762
+ return {
6763
+ ...filestatOf(path, s ?? { isFile: true, isDirectory: false, size: 0 }),
6764
+ size: BigInt(size)
6765
+ };
6766
+ }
6767
+ statOrphanable(path, size, orphan = false, gone = false) {
6712
6768
  let s;
6713
6769
  if (!orphan) {
6714
6770
  try {
@@ -6716,10 +6772,8 @@ var init_wasi_host = __esm({
6716
6772
  } catch {
6717
6773
  }
6718
6774
  }
6719
- return {
6720
- ...filestatOf(path, s ?? { isFile: true, isDirectory: false, size: 0 }),
6721
- size: BigInt(size)
6722
- };
6775
+ const out = this.sized(path, s, size);
6776
+ return gone ? { ...out, nlink: 0n } : out;
6723
6777
  }
6724
6778
  pathFilestat(path, lookup) {
6725
6779
  if (deviceOf(path)) {