@ai-ecoverse/slicc-kernel 1.147.4 → 1.147.6

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
@@ -3305,7 +3305,7 @@ function satisfies(version, range2) {
3305
3305
  }
3306
3306
 
3307
3307
  // src/version.ts
3308
- var KERNEL_VERSION = true ? "1.147.4" : "0.0.0-dev";
3308
+ var KERNEL_VERSION = true ? "1.147.6" : "0.0.0-dev";
3309
3309
  var OS_RELEASE = "6.0.0-slicc";
3310
3310
  function procVersion() {
3311
3311
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -6913,13 +6913,14 @@ var FsWatchers = class {
6913
6913
  this.watchers.delete(watcher);
6914
6914
  };
6915
6915
  }
6916
- typedWatch(root, recursive, alias) {
6916
+ typedWatch(root, recursive, alias, directory = recursive) {
6917
6917
  const main = normalizePath(root);
6918
6918
  const other = alias === void 0 ? main : normalizePath(alias);
6919
6919
  const watch = {
6920
6920
  roots: other === main ? [main] : [main, other],
6921
6921
  names: /* @__PURE__ */ new Map(),
6922
6922
  recursive,
6923
+ directory,
6923
6924
  notes: [],
6924
6925
  overflowed: false,
6925
6926
  ended: false,
@@ -7007,6 +7008,19 @@ var FsWatchers = class {
7007
7008
  if (!followed2.has(watch)) route(watch, "rename", at, seq2);
7008
7009
  }
7009
7010
  }
7011
+ heard(type, paths) {
7012
+ if (this.typed.size === 0) return;
7013
+ for (const path of paths) {
7014
+ const at = normalizePath(path);
7015
+ const seq2 = ++this.seq;
7016
+ for (const watch of [...this.typed]) {
7017
+ if (type === "rename" && watch.roots.some((root) => at === root || under2(root, at)))
7018
+ continue;
7019
+ if (type === "change" && watch.directory && watch.roots.includes(at)) continue;
7020
+ route(watch, type, at, seq2);
7021
+ }
7022
+ }
7023
+ }
7010
7024
  changed(...paths) {
7011
7025
  this.report(paths);
7012
7026
  this.emit("change", paths);
@@ -18255,6 +18269,17 @@ var VfsNode = class {
18255
18269
  this.queue = next3.catch(() => void 0);
18256
18270
  return next3;
18257
18271
  }
18272
+ named = 0;
18273
+ byName(op) {
18274
+ return this.serial(async () => {
18275
+ this.named++;
18276
+ try {
18277
+ return await op();
18278
+ } finally {
18279
+ this.named--;
18280
+ }
18281
+ });
18282
+ }
18258
18283
  revoke() {
18259
18284
  this.revoked = true;
18260
18285
  clearTimeout(this.writeBack);
@@ -18262,7 +18287,7 @@ var VfsNode = class {
18262
18287
  this.data = void 0;
18263
18288
  this.ranged = void 0;
18264
18289
  }
18265
- async prepare() {
18290
+ async prepare(onFd = this.named === 0) {
18266
18291
  if (this.revoked) throw new KernelError("EIO");
18267
18292
  if (this.ranged || this.data) return this.ranged;
18268
18293
  const io = rangedOps(this.fs);
@@ -18277,15 +18302,15 @@ var VfsNode = class {
18277
18302
  this.ranged = new AsyncRangedFile(io, this.path, st.size ?? 0, st.version);
18278
18303
  return this.ranged;
18279
18304
  }
18280
- await this.load();
18305
+ await this.load(onFd);
18281
18306
  return void 0;
18282
18307
  }
18283
18308
  async keep() {
18284
- const ranged2 = await this.prepare();
18285
- if (ranged2) await this.followed(() => ranged2.pin());
18309
+ const ranged2 = await this.prepare(false);
18310
+ if (ranged2) await this.followed(() => ranged2.pin(), false);
18286
18311
  }
18287
18312
  moving = /* @__PURE__ */ new Set();
18288
- async followed(op) {
18313
+ async followed(op, onFd = this.named === 0) {
18289
18314
  for (; ; ) {
18290
18315
  const at = this.path;
18291
18316
  try {
@@ -18293,11 +18318,11 @@ var VfsNode = class {
18293
18318
  } catch (err) {
18294
18319
  if (!isMissing(err)) throw err;
18295
18320
  while (this.moving.size > 0) await Promise.all(this.moving);
18296
- if (this.path === at) throw err;
18321
+ if (this.path === at) throw onFd && !this.made ? new KernelError("EIO") : err;
18297
18322
  }
18298
18323
  }
18299
18324
  }
18300
- async load() {
18325
+ async load(onFd = this.named === 0) {
18301
18326
  if (this.revoked) throw new KernelError("EIO");
18302
18327
  while (!this.data) {
18303
18328
  const at = this.path;
@@ -18307,7 +18332,7 @@ var VfsNode = class {
18307
18332
  if (!isMissing(err)) throw err;
18308
18333
  while (this.moving.size > 0) await Promise.all(this.moving);
18309
18334
  if (this.path !== at) continue;
18310
- if (!this.made) throw new KernelError("ENOENT");
18335
+ if (!this.made) throw new KernelError(onFd ? "EIO" : "ENOENT");
18311
18336
  this.data = new Uint8Array(0);
18312
18337
  this.missing = true;
18313
18338
  }
@@ -18812,7 +18837,7 @@ function heldIo(fs, nodes, changed) {
18812
18837
  const write = async (path, op, fallback) => {
18813
18838
  const held = await node(path);
18814
18839
  if (!held) return fallback();
18815
- const out = await held.serial(async () => {
18840
+ const out = await held.byName(async () => {
18816
18841
  const done4 = await op(held);
18817
18842
  await held.flush();
18818
18843
  return done4;
@@ -18844,22 +18869,22 @@ function heldIo(fs, nodes, changed) {
18844
18869
  async stat(path) {
18845
18870
  const st = await fs.stat(path);
18846
18871
  const held = st.isFile ? await node(path) : void 0;
18847
- return held ? { ...st, size: await held.serial(() => held.size()) } : st;
18872
+ return held ? { ...st, size: await held.byName(() => held.size()) } : st;
18848
18873
  },
18849
18874
  async lstat(path) {
18850
18875
  const st = await fs.lstat(path);
18851
18876
  const held = st.isFile && !st.isSymbolicLink ? await node(path) : void 0;
18852
- return held ? { ...st, size: await held.serial(() => held.size()) } : st;
18877
+ return held ? { ...st, size: await held.byName(() => held.size()) } : st;
18853
18878
  },
18854
18879
  async readFileBuffer(path) {
18855
18880
  const held = await node(path);
18856
18881
  if (!held) return fs.readFileBuffer(path);
18857
- return held.serial(async () => held.pread(await held.size(), 0));
18882
+ return held.byName(async () => held.pread(await held.size(), 0));
18858
18883
  },
18859
18884
  ...ranged2 ? {
18860
18885
  pread: async (path, at, n, version) => {
18861
18886
  const held = await node(path);
18862
- return held ? held.serial(() => held.pread(n, at)) : ranged2.pread(path, at, n, version);
18887
+ return held ? held.byName(() => held.pread(n, at)) : ranged2.pread(path, at, n, version);
18863
18888
  },
18864
18889
  pwrite: (path, at, bytes, transfer) => write(
18865
18890
  path,
@@ -18912,7 +18937,7 @@ function keepingOpen(fs, nodes, changed = () => {
18912
18937
  const held = await heldAt(fs, nodes, at);
18913
18938
  if (!held) return nodes.onEntry(at, () => fs.writeFile(path, content, owner));
18914
18939
  const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content;
18915
- return held.serial(async () => {
18940
+ return held.byName(async () => {
18916
18941
  await held.truncate(0);
18917
18942
  await held.pwrite(bytes, 0);
18918
18943
  await held.flush();
@@ -21784,7 +21809,7 @@ var RemoteWatch = class {
21784
21809
  if (data.ack !== void 0 && data.to === this.tab && data.from !== void 0) {
21785
21810
  this.acked(data.ack, data.from);
21786
21811
  }
21787
- if (data.changed !== void 0) this.emit({ paths: data.changed, trees: [] });
21812
+ if (data.changed !== void 0) this.emit({ paths: data.changed, trees: [], content: true });
21788
21813
  }
21789
21814
  arrived(peer) {
21790
21815
  this.peers.add(peer);
@@ -23402,6 +23427,18 @@ var Extent = class {
23402
23427
  };
23403
23428
  var LOCKED = /* @__PURE__ */ new Set(["NotReadableError", "NoModificationAllowedError", "InvalidStateError"]);
23404
23429
  var SYNC_BACKOFF_MS = [5, 10, 20, 40, 80];
23430
+ async function unlocked(name2, op) {
23431
+ for (let attempt = 0; ; attempt++) {
23432
+ try {
23433
+ return await op();
23434
+ } catch (err) {
23435
+ if (!LOCKED.has(err?.name)) throw err;
23436
+ const delay = SYNC_BACKOFF_MS[attempt];
23437
+ if (delay === void 0) throw fsError("EBUSY", name2);
23438
+ await new Promise((resolve2) => setTimeout(resolve2, delay));
23439
+ }
23440
+ }
23441
+ }
23405
23442
  async function openSync(handle) {
23406
23443
  const sync = handle.createSyncAccessHandle;
23407
23444
  if (!sync) return void 0;
@@ -23524,7 +23561,12 @@ var OpfsFs = class {
23524
23561
  meta.listen?.((c) => {
23525
23562
  for (const path of [...c.paths ?? [], ...c.trees ?? []]) this.forget(path);
23526
23563
  const moved2 = movedOf(c.moved);
23527
- remote?.emit({ paths: c.paths ?? [], trees: c.trees ?? [], ...moved2 ? { moved: moved2 } : {} });
23564
+ remote?.emit({
23565
+ paths: c.paths ?? [],
23566
+ trees: c.trees ?? [],
23567
+ content: true,
23568
+ ...moved2 ? { moved: moved2 } : {}
23569
+ });
23528
23570
  });
23529
23571
  remote?.listen((c) => {
23530
23572
  for (const path of [...c.paths, ...c.trees]) this.forget(path);
@@ -24592,7 +24634,10 @@ var OpfsFs = class {
24592
24634
  try {
24593
24635
  await this.inDir(
24594
24636
  dir,
24595
- (parent) => this.io(parent.removeEntry(name2, { recursive: options.recursive === true }))
24637
+ (parent) => unlocked(
24638
+ name2,
24639
+ () => this.io(parent.removeEntry(name2, { recursive: options.recursive === true }))
24640
+ )
24596
24641
  );
24597
24642
  } catch (err) {
24598
24643
  throw translate(err, path);
@@ -28284,6 +28329,8 @@ var Launcher = class {
28284
28329
  this.changes.flush();
28285
28330
  this.cwds.touched(change.paths, change.trees);
28286
28331
  this.rewritten(change.paths, change.trees);
28332
+ this.watchers.heard(change.content ? "change" : "rename", change.paths);
28333
+ this.watchers.heard("rename", change.trees ?? []);
28287
28334
  });
28288
28335
  const holders = [this.held, this.openFiles];
28289
28336
  this.unlinked = new UnlinkedKeeper(
@@ -29962,7 +30009,12 @@ var Launcher = class {
29962
30009
  if (g) await readable(g, "watch", at);
29963
30010
  const st = await this.fs.stat(at);
29964
30011
  const real = await this.fs.realpath?.(at, true).catch(() => at) ?? at;
29965
- const watch = this.watchers.typedWatch(real, recursive && st.isDirectory, at);
30012
+ const watch = this.watchers.typedWatch(
30013
+ real,
30014
+ recursive && st.isDirectory,
30015
+ at,
30016
+ st.isDirectory
30017
+ );
29966
30018
  if (!g || g.cred.euid === 0) return watch;
29967
30019
  return visibleTo(watch, real, async (dir) => {
29968
30020
  const walked = await access(g.fs, g.cred, dir, R_OK | X_OK, { directory: true });