@ai-ecoverse/slicc-kernel 1.17.5 → 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.
package/dist/node.js CHANGED
@@ -5494,6 +5494,48 @@ var VfsNodes = class {
5494
5494
  }
5495
5495
  }
5496
5496
  };
5497
+ var MAX_LINKS5 = 40;
5498
+ function parentOf5(path) {
5499
+ return path.slice(0, path.lastIndexOf("/")) || "/";
5500
+ }
5501
+ async function linkOf(fs, path) {
5502
+ return fs.readlink?.(path).catch(() => void 0);
5503
+ }
5504
+ async function realDir(fs, dir) {
5505
+ const queue = dir.split("/").filter(Boolean);
5506
+ let at = "/";
5507
+ let hops = 0;
5508
+ while (queue.length > 0) {
5509
+ const part = queue.shift();
5510
+ if (part === ".") continue;
5511
+ if (part === "..") {
5512
+ at = parentOf5(at);
5513
+ continue;
5514
+ }
5515
+ const next = at === "/" ? `/${part}` : `${at}/${part}`;
5516
+ const link2 = hops < MAX_LINKS5 ? await linkOf(fs, next) : void 0;
5517
+ if (link2 === void 0) {
5518
+ at = next;
5519
+ continue;
5520
+ }
5521
+ hops++;
5522
+ queue.unshift(...link2.split("/").filter(Boolean));
5523
+ if (link2.startsWith("/")) at = "/";
5524
+ }
5525
+ return at;
5526
+ }
5527
+ async function targetDir(fs, path) {
5528
+ let dir = await realDir(fs, parentOf5(path));
5529
+ let name2 = path.slice(path.lastIndexOf("/") + 1);
5530
+ for (let hops = 0; hops < MAX_LINKS5; hops++) {
5531
+ const link2 = await linkOf(fs, dir === "/" ? `/${name2}` : `${dir}/${name2}`);
5532
+ if (link2 === void 0) return dir;
5533
+ const target = link2.startsWith("/") ? link2 : `${dir}/${link2}`;
5534
+ dir = await realDir(fs, parentOf5(target));
5535
+ name2 = target.slice(target.lastIndexOf("/") + 1);
5536
+ }
5537
+ return dir;
5538
+ }
5497
5539
  async function refuseReadonly(fs, path, flags, opts = {}) {
5498
5540
  const writes = (flags & O_ACCMODE) !== 0 || opts.truncate === true;
5499
5541
  if (!writes && !opts.create || !fs.stat) return;
@@ -5502,10 +5544,9 @@ async function refuseReadonly(fs, path, flags, opts = {}) {
5502
5544
  if (isMissing(err) || typeof code !== "string") return void 0;
5503
5545
  throw err;
5504
5546
  });
5505
- const parent = path.slice(0, path.lastIndexOf("/")) || "/";
5506
5547
  const own = await stat(path);
5507
5548
  if (own && !writes) return;
5508
- const st = own ?? await stat(parent);
5549
+ const st = own ?? await stat(await targetDir(fs, path));
5509
5550
  if (st?.readonly) throw new KernelError("EROFS");
5510
5551
  }
5511
5552
  function vfsFile(fs, opts, nodes) {