@ai-ecoverse/slicc-kernel 1.18.0 → 1.18.1

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.
@@ -5742,6 +5742,48 @@ var VfsNodes = class {
5742
5742
  }
5743
5743
  }
5744
5744
  };
5745
+ var MAX_LINKS5 = 40;
5746
+ function parentOf5(path) {
5747
+ return path.slice(0, path.lastIndexOf("/")) || "/";
5748
+ }
5749
+ async function linkOf(fs, path) {
5750
+ return fs.readlink?.(path).catch(() => void 0);
5751
+ }
5752
+ async function realDir(fs, dir) {
5753
+ const queue = dir.split("/").filter(Boolean);
5754
+ let at = "/";
5755
+ let hops = 0;
5756
+ while (queue.length > 0) {
5757
+ const part = queue.shift();
5758
+ if (part === ".") continue;
5759
+ if (part === "..") {
5760
+ at = parentOf5(at);
5761
+ continue;
5762
+ }
5763
+ const next = at === "/" ? `/${part}` : `${at}/${part}`;
5764
+ const link2 = hops < MAX_LINKS5 ? await linkOf(fs, next) : void 0;
5765
+ if (link2 === void 0) {
5766
+ at = next;
5767
+ continue;
5768
+ }
5769
+ hops++;
5770
+ queue.unshift(...link2.split("/").filter(Boolean));
5771
+ if (link2.startsWith("/")) at = "/";
5772
+ }
5773
+ return at;
5774
+ }
5775
+ async function targetDir(fs, path) {
5776
+ let dir = await realDir(fs, parentOf5(path));
5777
+ let name2 = path.slice(path.lastIndexOf("/") + 1);
5778
+ for (let hops = 0; hops < MAX_LINKS5; hops++) {
5779
+ const link2 = await linkOf(fs, dir === "/" ? `/${name2}` : `${dir}/${name2}`);
5780
+ if (link2 === void 0) return dir;
5781
+ const target = link2.startsWith("/") ? link2 : `${dir}/${link2}`;
5782
+ dir = await realDir(fs, parentOf5(target));
5783
+ name2 = target.slice(target.lastIndexOf("/") + 1);
5784
+ }
5785
+ return dir;
5786
+ }
5745
5787
  async function refuseReadonly(fs, path, flags, opts = {}) {
5746
5788
  const writes = (flags & O_ACCMODE) !== 0 || opts.truncate === true;
5747
5789
  if (!writes && !opts.create || !fs.stat) return;
@@ -5750,10 +5792,9 @@ async function refuseReadonly(fs, path, flags, opts = {}) {
5750
5792
  if (isMissing(err) || typeof code !== "string") return void 0;
5751
5793
  throw err;
5752
5794
  });
5753
- const parent = path.slice(0, path.lastIndexOf("/")) || "/";
5754
5795
  const own = await stat(path);
5755
5796
  if (own && !writes) return;
5756
- const st = own ?? await stat(parent);
5797
+ const st = own ?? await stat(await targetDir(fs, path));
5757
5798
  if (st?.readonly) throw new KernelError("EROFS");
5758
5799
  }
5759
5800
  function vfsFile(fs, opts, nodes) {