@ai-ecoverse/slicc-kernel 1.152.0 → 1.152.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.
@@ -1569,9 +1569,10 @@ var OpfsFs = class {
1569
1569
  }
1570
1570
  async fileId(path) {
1571
1571
  const found = await this.locate(path, true);
1572
- const [entry] = await this.meta.get([found.path]);
1572
+ const [entry] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [found.path]);
1573
1573
  if (entry?.fid !== void 0) return entry.fid;
1574
1574
  const fid = crypto.randomUUID();
1575
+ this.idWrites++;
1575
1576
  await this.meta.update(found.path, (now) => ({
1576
1577
  ...occupied(now),
1577
1578
  path: found.path,
@@ -1842,6 +1843,10 @@ var OpfsFs = class {
1842
1843
  opfsCalls() {
1843
1844
  return this.calls;
1844
1845
  }
1846
+ idWrites = 0;
1847
+ fileIdWrites() {
1848
+ return this.idWrites;
1849
+ }
1845
1850
  opfsOps() {
1846
1851
  return this.calls + this.others;
1847
1852
  }
@@ -2301,7 +2306,7 @@ var OpfsFs = class {
2301
2306
  return new Uint8Array(await file.slice(offset, offset + length2).arrayBuffer());
2302
2307
  });
2303
2308
  }
2304
- async pwrite(path, offset, bytes) {
2309
+ async pwrite(path, offset, bytes, _transfer, options) {
2305
2310
  const at = normalizePath(path);
2306
2311
  const movedAway = this.renamesInFlight() ? await this.writeWaits(at) : false;
2307
2312
  this.fileWrites.set(at, (this.fileWrites.get(at) ?? 0) + 1);
@@ -2316,7 +2321,10 @@ var OpfsFs = class {
2316
2321
  this.files.delete(target);
2317
2322
  }
2318
2323
  }
2319
- const [handle] = await this.fileFor(path, !existed && !movedAway);
2324
+ const [handle] = await this.fileFor(
2325
+ path,
2326
+ !existed && !movedAway && options?.create !== false
2327
+ );
2320
2328
  await this.writeAt(handle, target, path, offset, bytes);
2321
2329
  } finally {
2322
2330
  this.writeEnded(at);
@@ -7918,7 +7926,7 @@ function satisfies(version, range2) {
7918
7926
  }
7919
7927
 
7920
7928
  // src/version.ts
7921
- var KERNEL_VERSION = true ? "1.152.0" : "0.0.0-dev";
7929
+ var KERNEL_VERSION = true ? "1.152.1" : "0.0.0-dev";
7922
7930
  var OS_RELEASE = "6.0.0-slicc";
7923
7931
  function procVersion() {
7924
7932
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -10699,9 +10707,9 @@ function withEtcFiles(fs, files) {
10699
10707
  readFileBuffer: (path) => fs.readFileBuffer(path).catch(fallback(path, (b) => b)),
10700
10708
  ...ranged2 ? {
10701
10709
  pread: (path, offset, length2, version) => ranged2.pread(path, offset, length2, version).catch(fallback(path, (b) => b.slice(offset, offset + length2))),
10702
- pwrite: async (path, offset, bytes, transfer) => {
10710
+ pwrite: async (path, offset, bytes, transfer, options) => {
10703
10711
  if (files.has(path)) await materialize(path);
10704
- return ranged2.pwrite(path, offset, bytes, transfer);
10712
+ return ranged2.pwrite(path, offset, bytes, transfer, options);
10705
10713
  },
10706
10714
  truncate: async (path, size) => {
10707
10715
  if (files.has(path)) await materialize(path);
@@ -10810,10 +10818,10 @@ var FreshModules = class {
10810
10818
  };
10811
10819
  const ranged2 = rangedOps(fs);
10812
10820
  if (ranged2) {
10813
- overrides.pwrite = async (path, at, bytes, transfer) => {
10821
+ overrides.pwrite = async (path, at, bytes, transfer, options) => {
10814
10822
  const touches3 = at < MAGIC.length && this.fresh.has(normalizePath(path));
10815
10823
  const first = at === 0 && bytes.length >= MAGIC.length ? bytes.slice(0, MAGIC.length) : void 0;
10816
- await ranged2.pwrite(path, at, bytes, transfer);
10824
+ await ranged2.pwrite(path, at, bytes, transfer, options);
10817
10825
  if (touches3) await decide(path, first);
10818
10826
  };
10819
10827
  overrides.truncate = async (path, size) => {
@@ -12091,6 +12099,9 @@ var HeldSet = class extends Set {
12091
12099
  if (over !== void 0) holds2.doubt(over);
12092
12100
  }
12093
12101
  }
12102
+ async bindIds(id2) {
12103
+ for (const holds2 of [...this]) await holds2.bindIds(id2);
12104
+ }
12094
12105
  delete(holds2) {
12095
12106
  const removed = super.delete(holds2);
12096
12107
  for (const path of /* @__PURE__ */ new Set([...holds2.keys(), ...holds2.opens.keys()])) this.idle(path);
@@ -12144,8 +12155,17 @@ var HeldPaths = class extends Map {
12144
12155
  }
12145
12156
  boundIno(handle) {
12146
12157
  const doubt = this.doubted.get(handle);
12147
- const ino = this.bound.get(handle);
12148
- return doubt === void 0 || ino === void 0 ? void 0 : { ino, doubt };
12158
+ const bound3 = this.bound.get(handle);
12159
+ return doubt === void 0 || bound3 === void 0 ? void 0 : { ...bound3, doubt };
12160
+ }
12161
+ async bindIds(id2) {
12162
+ for (const [handle, bound3] of [...this.bound]) {
12163
+ const key = this.handles.get(handle);
12164
+ if (bound3.fid !== void 0 || key === void 0) continue;
12165
+ const fid = await id2(key)?.catch(() => void 0);
12166
+ if (fid !== void 0 && this.bound.get(handle) === bound3)
12167
+ this.bound.set(handle, { ...bound3, fid });
12168
+ }
12149
12169
  }
12150
12170
  trust(handle, doubt) {
12151
12171
  if (this.doubted.get(handle) === doubt) this.doubted.delete(handle);
@@ -12186,14 +12206,15 @@ var HeldPaths = class extends Map {
12186
12206
  for (const file of [...this.uses.keys()]) this.letGo(file, true);
12187
12207
  this.keptHandles.clear();
12188
12208
  }
12189
- hold(path, on, open2 = false, real, handle, ino) {
12209
+ hold(path, on, open2 = false, real, handle, ino, fid) {
12190
12210
  if (open2) {
12191
12211
  const made2 = this.holdOpen(path, on, real, handle);
12192
12212
  if (handle !== void 0) {
12193
12213
  this.bound.delete(handle);
12194
12214
  this.doubted.delete(handle);
12195
12215
  }
12196
- if (made2 !== void 0 && ino !== void 0) this.bound.set(made2, ino);
12216
+ if (made2 !== void 0 && ino !== void 0)
12217
+ this.bound.set(made2, fid === void 0 ? { ino } : { ino, fid });
12197
12218
  return made2;
12198
12219
  }
12199
12220
  this.holdWrite(path, on);
@@ -12929,7 +12950,7 @@ var MountFs = class _MountFs {
12929
12950
  );
12930
12951
  }
12931
12952
  }
12932
- async pwrite(path, offset, bytes, transfer = false, redirects = 0) {
12953
+ async pwrite(path, offset, bytes, transfer = false, options, redirects = 0) {
12933
12954
  const real = await this.follow(path, 0, true);
12934
12955
  const found = this.at(real);
12935
12956
  const { pwrite } = this.base;
@@ -12937,8 +12958,8 @@ var MountFs = class _MountFs {
12937
12958
  return this.based(
12938
12959
  [real],
12939
12960
  redirects,
12940
- () => pwrite.call(this.base, real, offset, bytes),
12941
- ([to], n) => this.pwrite(to, offset, bytes, transfer, n)
12961
+ () => pwrite.call(this.base, real, offset, bytes, false, options),
12962
+ ([to], n) => this.pwrite(to, offset, bytes, transfer, options, n)
12942
12963
  );
12943
12964
  }
12944
12965
  if (!found)
@@ -12962,7 +12983,7 @@ var MountFs = class _MountFs {
12962
12983
  op: "open",
12963
12984
  path: rel2,
12964
12985
  write: true,
12965
- create: true,
12986
+ create: options?.create !== false,
12966
12987
  truncate: false,
12967
12988
  exclusive: false
12968
12989
  });
@@ -13730,7 +13751,7 @@ async function run(entry, path, req) {
13730
13751
  case "truncate":
13731
13752
  return ranged(fs, path, req);
13732
13753
  case "append":
13733
- return json2(await appended(fs, path, req.body ?? new Uint8Array(0)));
13754
+ return json2(await appended(fs, path, req.body ?? new Uint8Array(0), req.handle));
13734
13755
  default:
13735
13756
  return { ok: false, errno: "EINVAL", message: `sync-fs: unknown op '${req.op}'` };
13736
13757
  }
@@ -13874,13 +13895,17 @@ async function holdOp(entry, path, req) {
13874
13895
  await entry.source?.open(path, real);
13875
13896
  await stillThere(entry, path, req);
13876
13897
  if (req.nofollow && !await ownEntry(entry, path, real ?? path)) continue;
13898
+ const fid = req.ino === void 0 ? void 0 : await idOf(entry, real ?? path);
13877
13899
  if (!r || !r.missed(path) && !r.changedSince(path, gen) && !r.inFlight?.(path))
13878
- return json2(entry.hold?.(path, on, open2, real, void 0, req.ino) ?? null);
13900
+ return json2(entry.hold?.(path, on, open2, real, void 0, req.ino, fid) ?? null);
13879
13901
  }
13880
13902
  }
13881
13903
  entry.hold?.(path, on, open2, void 0, req.handle);
13882
13904
  return done2;
13883
13905
  }
13906
+ async function idOf(entry, path) {
13907
+ return await entry.fileId?.(path)?.catch(() => void 0) ?? void 0;
13908
+ }
13884
13909
  async function ownEntry(entry, path, real) {
13885
13910
  const own = await entry.fs.realpath?.(path, false).catch((err) => {
13886
13911
  if (err.code !== "ENOENT") throw err;
@@ -13975,14 +14000,14 @@ async function createExclusive(fs, path, owner) {
13975
14000
  await fs.writeFile(path, new Uint8Array(0), owner);
13976
14001
  }
13977
14002
  var appending = /* @__PURE__ */ new Map();
13978
- async function appended(fs, path, body) {
14003
+ async function appended(fs, path, body, handle) {
13979
14004
  const key = await fs.realpath?.(path, true).catch(() => void 0) ?? path;
13980
14005
  const before = appending.get(key) ?? Promise.resolve();
13981
14006
  const run2 = before.then(async () => {
13982
14007
  if (fs.append) return fs.append(path, body);
13983
14008
  const size = (await fs.stat(path)).size;
13984
14009
  const ops = rangedOps(fs);
13985
- if (ops) await ops.pwrite(path, size, body, true);
14010
+ if (ops) await ops.pwrite(path, size, body, true, noCreate(handle));
13986
14011
  else {
13987
14012
  const whole = new Uint8Array(size + body.length);
13988
14013
  whole.set(await fs.readFileBuffer(path));
@@ -13998,6 +14023,9 @@ async function appended(fs, path, body) {
13998
14023
  });
13999
14024
  return run2;
14000
14025
  }
14026
+ function noCreate(handle) {
14027
+ return handle === void 0 ? void 0 : { create: false };
14028
+ }
14001
14029
  async function ranged(fs, path, req) {
14002
14030
  const ops = rangedOps(fs);
14003
14031
  if (!ops) throw syncError("ENOSYS", path);
@@ -14008,7 +14036,8 @@ async function ranged(fs, path, req) {
14008
14036
  kind: "bytes",
14009
14037
  bytes: await ops.pread(path, offset, req.length ?? 0, req.version)
14010
14038
  };
14011
- if (req.op === "pwrite") await ops.pwrite(path, offset, req.body ?? new Uint8Array(0), true);
14039
+ if (req.op === "pwrite")
14040
+ await ops.pwrite(path, offset, req.body ?? new Uint8Array(0), true, noCreate(req.handle));
14012
14041
  else await ops.truncate(path, req.length ?? 0);
14013
14042
  return done2;
14014
14043
  }
@@ -14038,7 +14067,10 @@ async function bound(entry, path, handle) {
14038
14067
  const bound3 = entry.boundIno?.(handle);
14039
14068
  if (bound3 === void 0) return;
14040
14069
  const now = await entry.fs.stat(path).catch(() => void 0);
14041
- if (now?.ino === bound3.ino) {
14070
+ if (now === void 0 && bound3.fid !== void 0 && !await entry.fs.lstat(path).catch(() => void 0))
14071
+ throw syncError("ENOENT", path);
14072
+ const same3 = bound3.fid === void 0 ? now?.ino === bound3.ino : now?.fid === bound3.fid || await idOf(entry, path) === bound3.fid;
14073
+ if (same3) {
14042
14074
  entry.trust?.(handle, bound3.doubt);
14043
14075
  return;
14044
14076
  }
@@ -14852,6 +14884,8 @@ var SYS_TREE = {
14852
14884
  slicc_rename_ack_busy: (listing) => `${listing.renameAcks?.busy ?? 0}
14853
14885
  `,
14854
14886
  slicc_stale_fds: (listing) => `${listing.staleFds ?? 0}
14887
+ `,
14888
+ slicc_file_ids: (listing) => `${listing.fileIds ?? 0}
14855
14889
  `,
14856
14890
  slicc_rename_acks: (listing) => {
14857
14891
  const samples = [...listing.renameAcks?.ackMs ?? []].sort((a, b) => a - b);
@@ -23519,10 +23553,10 @@ function heldIo(fs, nodes, changed) {
23519
23553
  const held = await node(path);
23520
23554
  return held ? held.byName(() => held.pread(n, at)) : ranged2.pread(path, at, n, version);
23521
23555
  },
23522
- pwrite: (path, at, bytes, transfer) => write(
23556
+ pwrite: (path, at, bytes, transfer, options) => write(
23523
23557
  path,
23524
23558
  async (held) => void await held.pwrite(bytes, at),
23525
- () => ranged2.pwrite(path, at, bytes, transfer)
23559
+ () => ranged2.pwrite(path, at, bytes, transfer, options)
23526
23560
  ),
23527
23561
  truncate: (path, size) => write(
23528
23562
  path,
@@ -25807,8 +25841,9 @@ function holdingToken(opts, holds2, caller) {
25807
25841
  cwd: opts.cwd,
25808
25842
  ...opts.statfs ? { statfs: opts.statfs } : {},
25809
25843
  ...opts.renames ? { renames: opts.renames } : {},
25844
+ ...opts.fileId ? { fileId: opts.fileId } : {},
25810
25845
  ...opts.renameSeq ? { renameSeq: opts.renameSeq } : {},
25811
- hold: (path, on, open2, real, handle, ino) => holds2.hold(path, on, open2, real, handle, ino),
25846
+ hold: (path, on, open2, real, handle, ino, fid) => holds2.hold(path, on, open2, real, handle, ino, fid),
25812
25847
  boundIno: holds2.boundIno.bind(holds2),
25813
25848
  trust: holds2.trust.bind(holds2),
25814
25849
  keptFor: (handle) => holds2.keptFor(handle),
@@ -30960,7 +30995,8 @@ var Launcher = class {
30960
30995
  opfsOps: this.rootFs.opfsOps?.() ?? 0,
30961
30996
  cwdChecks: this.cwds.checks,
30962
30997
  renameAcks: this.rootFs.renameWaits?.(),
30963
- staleFds: staleFdCount()
30998
+ staleFds: staleFdCount(),
30999
+ fileIds: this.rootFs.fileIdWrites?.() ?? 0
30964
31000
  }),
30965
31001
  sudo: (call, signal) => this.sudo(pid, call, signal),
30966
31002
  crontab: (call) => this.crontab(pid, call),
@@ -30971,6 +31007,7 @@ var Launcher = class {
30971
31007
  replacements: stack.unlinked,
30972
31008
  statfs: (path) => this.mounts.statfs(path),
30973
31009
  renames: (since, held) => this.renameLog.since(since, held),
31010
+ fileId: (path) => this.locks.shared?.() === true ? this.rootFileId(path) : void 0,
30974
31011
  renameSeq: (from, to) => this.renameLog.seqOf(from, to),
30975
31012
  mounts: () => this.mounts.list(),
30976
31013
  mount: (call, signal) => this.processMount(pid, call, signal),
@@ -31850,12 +31887,16 @@ var Launcher = class {
31850
31887
  this.writers ??= this.writerStack();
31851
31888
  return this.writers;
31852
31889
  }
31890
+ rootFileId(path) {
31891
+ return this.mounts.locate(path) === void 0 ? this.rootFs.fileId?.(path) : void 0;
31892
+ }
31853
31893
  flushingPeers(fs) {
31854
31894
  const peers = fs.peers?.();
31855
31895
  if (!peers) return void 0;
31856
31896
  peers.watch((crowded) => {
31857
31897
  this.changes.flush();
31858
31898
  this.changes.foreign(crowded);
31899
+ if (crowded) void this.held?.bindIds((path) => this.rootFileId(path));
31859
31900
  });
31860
31901
  return {
31861
31902
  ...peers,