@ai-ecoverse/slicc-kernel 1.61.1 → 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.
@@ -1703,9 +1703,34 @@ var init_wasi_fds = __esm({
1703
1703
  }
1704
1704
  if (!s && !(oflags & OFLAGS.CREAT)) throw new WasiError("ENOENT");
1705
1705
  refuseWrite(s, oflags, rights);
1706
- if (this.shared) return this.kernelFile(path, s, oflags, rights, fdflags);
1706
+ return this.regular(path, s, oflags, rights, fdflags);
1707
+ }
1708
+ regular(path, s, oflags, rights, fdflags) {
1709
+ if (this.shared || this.kernelHolds(path, s)) {
1710
+ return this.kernelFile(path, s, oflags, rights, fdflags);
1711
+ }
1707
1712
  return this.install({ type: "file", file: this.file(path, s, oflags, rights, fdflags) });
1708
1713
  }
1714
+ kernelHolds(path, st) {
1715
+ for (const [fd, e] of this.table) {
1716
+ if (e.type !== "kernel" || this.kind(fd, e) !== "file") continue;
1717
+ this.named(fd, e);
1718
+ if (e.path === path || st?.ino !== void 0 && e.ino === st.ino) return true;
1719
+ }
1720
+ return false;
1721
+ }
1722
+ learned = /* @__PURE__ */ new WeakSet();
1723
+ named(fd, e) {
1724
+ if (e.path !== void 0 || this.learned.has(e)) return;
1725
+ this.learned.add(e);
1726
+ try {
1727
+ const vfs = this.kernel.call({ op: "fd-vfs-stat", fd });
1728
+ if (vfs.orphan || vfs.path === void 0) return;
1729
+ e.path = vfs.path;
1730
+ e.ino = this.inoOf(vfs.path);
1731
+ } catch {
1732
+ }
1733
+ }
1709
1734
  file(path, existing, oflags, rights, fdflags) {
1710
1735
  const { readable: readable2, writable: writable2 } = openAccess(existing, oflags, rights);
1711
1736
  let buffer = this.buffers.get(path);