@ai-ecoverse/slicc-kernel 1.62.0 → 1.62.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
@@ -6740,9 +6740,37 @@ async function holdOp(entry, path, req) {
6740
6740
  entry.hold?.(path, on, open, void 0, req.handle);
6741
6741
  return done;
6742
6742
  }
6743
+ var IDENTITY_OPS = /* @__PURE__ */ new Set([
6744
+ "write",
6745
+ "pwrite",
6746
+ "truncate",
6747
+ "chmod",
6748
+ "utimes",
6749
+ "chown",
6750
+ "lchown"
6751
+ ]);
6743
6752
  async function dispatchSyncFs(req) {
6744
6753
  const entry = resolveSyncFsToken(req.token);
6745
6754
  if (!entry) return { ok: false, errno: "EACCES", message: "sync-fs: unknown or revoked token" };
6755
+ if (!req.identity || !IDENTITY_OPS.has(req.op)) return dispatchOne(entry, req);
6756
+ const { fs, cwd } = entry;
6757
+ const path = fs.resolvePath(cwd, req.path);
6758
+ const identified = async (held) => {
6759
+ const own = held ? { ...entry, fs: { ...fs, writeFile: held.writeFile } } : entry;
6760
+ const result = await dispatchOne(own, req);
6761
+ if (!result.ok) return result;
6762
+ if (held && !held.direct) return json2(null);
6763
+ const look = req.op === "lchown" ? fs.lstat : fs.stat;
6764
+ const st = await look.call(fs, path).catch(() => void 0);
6765
+ return json2(st ? statJson(st) : null);
6766
+ };
6767
+ try {
6768
+ return await (fs.exclusive ? fs.exclusive(path, identified, req.op !== "lchown") : identified());
6769
+ } catch (err) {
6770
+ return toErrno(err);
6771
+ }
6772
+ }
6773
+ async function dispatchOne(entry, req) {
6746
6774
  const { fs, cwd } = entry;
6747
6775
  try {
6748
6776
  const path = fs.resolvePath(cwd, req.path);
@@ -10090,7 +10118,9 @@ var VfsNode = class {
10090
10118
  this.ranged = new AsyncRangedFile(io, this.path, this.pin.size, this.pin.version);
10091
10119
  return this.ranged;
10092
10120
  }
10093
- const st = io && !this.orphaned ? await this.fs.stat?.(this.path).catch(() => void 0) : void 0;
10121
+ const at = this.path;
10122
+ const st = io && !this.orphaned ? await this.fs.stat?.(at).catch(() => void 0) : void 0;
10123
+ this.note(at, st);
10094
10124
  if (io && st?.ranged) {
10095
10125
  this.ranged = new AsyncRangedFile(io, this.path, st.size ?? 0, st.version);
10096
10126
  return this.ranged;
@@ -10150,12 +10180,23 @@ var VfsNode = class {
10150
10180
  const stat = this.fs.stat?.bind(this.fs);
10151
10181
  if (!stat || this.orphaned) return Promise.resolve(void 0);
10152
10182
  const parent = this.path.slice(0, this.path.lastIndexOf("/")) || "/";
10153
- this.cap ??= stat(this.path).catch(() => stat(parent)).then(
10183
+ const at = this.path;
10184
+ this.cap ??= stat(at).then((st) => {
10185
+ this.note(at, st);
10186
+ return st;
10187
+ }).catch(() => stat(parent)).then(
10154
10188
  (st) => st.maxFile,
10155
10189
  () => void 0
10156
10190
  );
10157
10191
  return this.cap;
10158
10192
  }
10193
+ seen;
10194
+ note(path, st) {
10195
+ if (st?.ino !== void 0) this.seen = { path, ino: st.ino };
10196
+ }
10197
+ known() {
10198
+ return this.seen?.path === this.path && !this.orphaned ? this.seen.ino : void 0;
10199
+ }
10159
10200
  async fits(end) {
10160
10201
  const max = await this.limit();
10161
10202
  if (max !== void 0 && end > max) throw new KernelError("EFBIG");
@@ -10469,6 +10510,18 @@ async function refuseReadonly(fs, path, flags, opts = {}) {
10469
10510
  function keepingOpen(fs, nodes) {
10470
10511
  return {
10471
10512
  ...fs,
10513
+ async exclusive(path, run2, follow2 = true) {
10514
+ const at = fs.resolvePath("/", path);
10515
+ const key = follow2 ? nodes.targetKey(at) : nodes.entryKey(at);
10516
+ const locked = await key.catch(() => at);
10517
+ return nodes.onEntry(
10518
+ locked,
10519
+ () => run2({
10520
+ writeFile: (p, content, owner) => fs.writeFile(p, content, owner),
10521
+ direct: locked === at
10522
+ })
10523
+ );
10524
+ },
10472
10525
  async rm(path, options) {
10473
10526
  const at = await nodes.entryKey(fs.resolvePath("/", path));
10474
10527
  await nodes.unlinking(at);
@@ -10561,6 +10614,7 @@ function vfsFile(fs, opts, nodes) {
10561
10614
  size: await node.size(),
10562
10615
  ...node.orphaned ? { orphan: true } : {}
10563
10616
  })),
10617
+ known: () => node.known(),
10564
10618
  flush: () => serial(() => node.flush()),
10565
10619
  close: () => node.serial(async () => {
10566
10620
  try {
@@ -10955,6 +11009,20 @@ var WasmProcess = class {
10955
11009
  }
10956
11010
  return fd;
10957
11011
  }
11012
+ async identified(stat, known) {
11013
+ const first = await stat();
11014
+ if (first.orphan) return first;
11015
+ const ino = known?.();
11016
+ if (ino !== void 0) return { ...first, ino };
11017
+ const { fs } = this.options;
11018
+ const look = async () => {
11019
+ const now = await stat();
11020
+ if (now.path !== first.path || now.orphan) return now;
11021
+ const st = await fs.stat?.(now.path).catch(() => void 0);
11022
+ return st?.ino === void 0 ? now : { ...now, ino: st.ino };
11023
+ };
11024
+ return fs.exclusive ? fs.exclusive(first.path, look) : look();
11025
+ }
10958
11026
  newOwner() {
10959
11027
  if (!this.options.owners) return void 0;
10960
11028
  return { uid: this.cred.euid, gid: this.cred.egid, mode: 438 & ~this.umask };
@@ -11116,7 +11184,11 @@ var WasmProcess = class {
11116
11184
  await file.resize(req.size);
11117
11185
  return { ok: true, kind: "void" };
11118
11186
  case "fd-vfs-stat":
11119
- return { ok: true, kind: "json", json: await file.stat() };
11187
+ return {
11188
+ ok: true,
11189
+ kind: "json",
11190
+ json: req.identity ? await this.identified(file.stat.bind(file), file.known?.bind(file)) : await file.stat()
11191
+ };
11120
11192
  }
11121
11193
  }
11122
11194
  keptPath;