@ai-ecoverse/slicc-kernel 1.196.43 → 1.196.44

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.
@@ -5309,7 +5309,7 @@ function satisfies(version, range2) {
5309
5309
  }
5310
5310
 
5311
5311
  // src/version.ts
5312
- var KERNEL_VERSION = true ? "1.196.43" : "0.0.0-dev";
5312
+ var KERNEL_VERSION = true ? "1.196.44" : "0.0.0-dev";
5313
5313
  var OS_RELEASE = "6.0.0-slicc";
5314
5314
  function procVersion() {
5315
5315
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -33934,9 +33934,9 @@ async function copiedEntry(handle, path, file) {
33934
33934
  function absent(err) {
33935
33935
  return err.name === "NotFoundError";
33936
33936
  }
33937
- async function removeOne(parent, name2, rest2, entries, signal) {
33937
+ async function removeOne(parent, name2, rest2, lookup2, signal) {
33938
33938
  signal?.throwIfAborted();
33939
- const entry = entries.get(rest2);
33939
+ const entry = await lookup2(rest2);
33940
33940
  if (!entry) return;
33941
33941
  try {
33942
33942
  const handle = entry.kind === "file" ? await parent.getFileHandle(name2) : await parent.getDirectoryHandle(name2);
@@ -33946,7 +33946,7 @@ async function removeOne(parent, name2, rest2, entries, signal) {
33946
33946
  if (file.lastModified !== entry.mtime || file.size !== entry.size) return;
33947
33947
  } else {
33948
33948
  for await (const child2 of handle.keys())
33949
- await removeOne(handle, child2, rest2 + "/" + child2, entries, signal);
33949
+ await removeOne(handle, child2, rest2 + "/" + child2, lookup2, signal);
33950
33950
  }
33951
33951
  signal?.throwIfAborted();
33952
33952
  await parent.removeEntry(name2);
@@ -33954,10 +33954,64 @@ async function removeOne(parent, name2, rest2, entries, signal) {
33954
33954
  if (!absent(err) && err.name !== "TypeMismatchError") throw err;
33955
33955
  }
33956
33956
  }
33957
- function removeCopied(parent, name2, manifest, signal) {
33958
- return removeOne(parent, name2, "", new Map(manifest.map((entry) => [entry.path, entry])), signal);
33957
+ function removeCopied(parent, name2, manifest, signal, overflow) {
33958
+ const entries = new Map(manifest.map((entry) => [entry.path, entry]));
33959
+ return removeOne(parent, name2, "", (path) => entries.get(path) ?? overflow?.(path), signal);
33959
33960
  }
33960
33961
 
33962
+ // src/fs/rename-manifest.ts
33963
+ var INLINE_BYTES = 256 * 1024;
33964
+ var BATCH = 64;
33965
+ function manifestRoot(intent) {
33966
+ return "rename-manifest:" + intent;
33967
+ }
33968
+ async function storedStamp(meta, intent, path) {
33969
+ const [row] = await meta.get([manifestRoot(intent) + path]);
33970
+ return row?.copyStamp && { path, ...row.copyStamp };
33971
+ }
33972
+ var RenameManifest = class {
33973
+ meta;
33974
+ intent;
33975
+ entries = [];
33976
+ pending = [];
33977
+ bytes = 2;
33978
+ indexed = false;
33979
+ constructor(meta, intent) {
33980
+ this.meta = meta;
33981
+ this.intent = intent;
33982
+ }
33983
+ async record(entry) {
33984
+ if (!this.indexed) {
33985
+ this.bytes += storedSize(JSON.stringify(entry)) + 1;
33986
+ if (this.bytes <= INLINE_BYTES) {
33987
+ this.entries.push(entry);
33988
+ return;
33989
+ }
33990
+ this.indexed = true;
33991
+ }
33992
+ const { path: relative2, ...copyStamp } = entry;
33993
+ const path = manifestRoot(this.intent) + relative2;
33994
+ this.pending.push({ path, change: () => ({ path, copyStamp }) });
33995
+ if (this.pending.length === BATCH) await this.flush();
33996
+ }
33997
+ async flush() {
33998
+ if (!this.pending.length) return;
33999
+ if (this.meta.updateMany) await this.meta.updateMany(this.pending);
34000
+ else for (const { path, change } of this.pending) await this.meta.update(path, change);
34001
+ this.pending.length = 0;
34002
+ }
34003
+ async marker(to) {
34004
+ await this.flush();
34005
+ if (!this.entries.length && !this.indexed) return void 0;
34006
+ return {
34007
+ intent: this.intent,
34008
+ to,
34009
+ entries: this.entries,
34010
+ ...this.indexed && { indexed: true }
34011
+ };
34012
+ }
34013
+ };
34014
+
33961
34015
  // src/fs/opfs.ts
33962
34016
  var S_IFDIR2 = 16384;
33963
34017
  var S_IFREG3 = 32768;
@@ -34005,9 +34059,10 @@ var INTENT_POLL_MS = 5;
34005
34059
  var SOURCE_RETRY_MS = 250;
34006
34060
  var SOURCE_BACKOFF_MS = 1e3;
34007
34061
  var Copies = class extends Map {
34008
- remaining = [];
34009
- marker(intent, to) {
34010
- return intent && this.remaining.length ? { intent, to, entries: this.remaining } : void 0;
34062
+ manifest;
34063
+ constructor(meta, intent) {
34064
+ super();
34065
+ if (intent) this.manifest = new RenameManifest(meta, intent);
34011
34066
  }
34012
34067
  };
34013
34068
  function needsCopy(handle, swap) {
@@ -35769,12 +35824,12 @@ var OpfsFs = class {
35769
35824
  return this.privateCopy(source, parent, destination, target?.handle, moving);
35770
35825
  const place = async () => {
35771
35826
  this.forget(destination);
35772
- const copies = new Copies();
35773
- const root = { ino: inodeOf(source.path), ...moving };
35827
+ const root = { ino: sourceStat.ino, ...moving };
35774
35828
  const owned4 = lock ? { lock } : {};
35775
35829
  hooks.notify?.();
35776
35830
  const first = copying ? await this.intend({ from: source.path, to: staged2, root, ...owned4 }) : void 0;
35777
35831
  const second = copying && swap ? await this.intend({ from: staged2, to: destination, replace: true, root, ...owned4 }) : void 0;
35832
+ const copies = new Copies(this.meta, first);
35778
35833
  await hooks.started?.().catch(async (err) => {
35779
35834
  for (const intent of [first, second]) {
35780
35835
  if (intent) await this.meta.update(intent, () => void 0);
@@ -35790,21 +35845,21 @@ var OpfsFs = class {
35790
35845
  });
35791
35846
  if (swap) await PLAIN3.rm.call(this, destination);
35792
35847
  if (second) await this.intend({ from: staged2, to: destination, root, ...owned4 }, second);
35793
- left.copyCommit = copies.marker(first, destination);
35848
+ left.copyCommit = await copies.manifest?.marker(destination);
35794
35849
  await this.meta.move(source.path, destination, carry, left);
35795
35850
  this.movePending(source.path, destination);
35796
35851
  if (!moved3 && first)
35797
- await this.releaseSource(first, source.path, destination, left.ino, lock, copies.remaining);
35798
- else if (first) await this.meta.update(first, () => void 0);
35799
- if (swap) {
35852
+ await this.releaseSource(first, source.path, destination, left.ino, lock);
35853
+ else if (first) await this.retireIntent(first);
35854
+ if (swap && second) {
35800
35855
  const hidden = await dir.getDirectoryHandle(staging);
35801
- copies.remaining = [];
35856
+ copies.manifest = new RenameManifest(this.meta, second);
35802
35857
  const placed = await this.place(hidden, dir, name2, copies, copying);
35803
- if (!placed && second) {
35804
- const mark = vacatedAt(staged2, copies.marker(second, destination));
35858
+ if (!placed) {
35859
+ const mark = vacatedAt(staged2, await copies.manifest.marker(destination));
35805
35860
  await this.meta.update(staged2, () => mark);
35806
- await this.releaseSource(second, staged2, destination, mark.ino, lock, copies.remaining);
35807
- } else if (second) await this.meta.update(second, () => void 0);
35861
+ await this.releaseSource(second, staged2, destination, mark.ino, lock);
35862
+ } else await this.retireIntent(second);
35808
35863
  }
35809
35864
  await this.restamp(destination, copies);
35810
35865
  this.changed(source.path, destination);
@@ -36186,7 +36241,6 @@ var OpfsFs = class {
36186
36241
  const handle = source.handle;
36187
36242
  const dir = parent.handle;
36188
36243
  const name2 = baseOf4(to);
36189
- const copies = new Copies();
36190
36244
  const [entry] = await this.meta.get([source.path]);
36191
36245
  const root = { ino: occupied(entry).ino ?? inodeOf(source.path), ...owner };
36192
36246
  if (target?.kind === "directory" && movable(target) && movable(handle)) {
@@ -36196,14 +36250,23 @@ var OpfsFs = class {
36196
36250
  if (await this.swapNative(source, dir, name2, target, emptyBackup, intent2)) {
36197
36251
  this.forget(source.path);
36198
36252
  this.forget(to);
36199
- await this.commitPrivateCopy(source.path, to, root, intent2, copies, emptyBackup);
36253
+ await this.commitPrivateCopy(
36254
+ source.path,
36255
+ to,
36256
+ root,
36257
+ intent2,
36258
+ new Copies(this.meta, intent2),
36259
+ emptyBackup
36260
+ );
36200
36261
  return;
36201
36262
  }
36202
36263
  }
36203
36264
  await this.beforePrivateCopy?.();
36204
36265
  const intent = await this.intend({ from: source.path, to, root, privateCopy: true });
36266
+ const copies = new Copies(this.meta, intent);
36205
36267
  try {
36206
36268
  await this.duplicate(handle, dir, name2, copies, "");
36269
+ await copies.manifest?.flush();
36207
36270
  } catch (err) {
36208
36271
  if (!target)
36209
36272
  await dir.removeEntry(name2, { recursive: true }).catch((e) => {
@@ -36214,7 +36277,7 @@ var OpfsFs = class {
36214
36277
  await target.removeEntry(child2, { recursive: true });
36215
36278
  }
36216
36279
  this.forget(to);
36217
- await this.meta.update(intent, () => void 0);
36280
+ await this.retireIntent(intent);
36218
36281
  throw translate(err, to, "write");
36219
36282
  }
36220
36283
  await this.commitPrivateCopy(source.path, to, root, intent, copies);
@@ -36241,7 +36304,7 @@ var OpfsFs = class {
36241
36304
  const entries = await this.meta.get([from, to]);
36242
36305
  let mark = entries[0];
36243
36306
  if (!mark?.vacated || entries[1]?.ino !== ino) {
36244
- mark = vacatedAt(from, copies.marker(intent, to));
36307
+ mark = vacatedAt(from, await copies.manifest?.marker(to));
36245
36308
  await this.meta.move(
36246
36309
  from,
36247
36310
  to,
@@ -36249,8 +36312,7 @@ var OpfsFs = class {
36249
36312
  mark
36250
36313
  );
36251
36314
  }
36252
- if (!emptyBackup)
36253
- await this.releaseSource(intent, from, to, mark.ino, void 0, copies.remaining);
36315
+ if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino);
36254
36316
  this.movePending(from, to);
36255
36317
  await this.restamp(to, copies);
36256
36318
  this.changed(from, to);
@@ -36272,22 +36334,45 @@ var OpfsFs = class {
36272
36334
  }
36273
36335
  return cleanupId(handle);
36274
36336
  }
36275
- async releaseSource(intent, from, to, id2, lock, copiedEntries) {
36337
+ retireIntent(intent) {
36338
+ return this.meta.remove([intent, manifestRoot(intent)]);
36339
+ }
36340
+ async releaseSource(intent, from, to, id2, lock, unverified = false) {
36276
36341
  this.syncSourceReservation(intent, from);
36277
- const physicalSource = copiedEntries?.find((entry) => entry.path === "")?.id;
36278
36342
  await this.intend(
36279
36343
  {
36280
36344
  from,
36281
36345
  to,
36282
36346
  sourceCleanup: id2,
36283
- ...lock && { lock },
36284
- ...physicalSource && { physicalSource },
36285
- ...copiedEntries && { copiedEntries }
36347
+ ...unverified && { unverifiedSource: true },
36348
+ ...lock && { lock }
36286
36349
  },
36287
36350
  intent
36288
36351
  );
36289
36352
  await this.cleanSource(intent, from, id2);
36290
36353
  }
36354
+ async removeReserved(intent, from, reservation, rename, signal) {
36355
+ if (rename.unverifiedSource) {
36356
+ await this.sourceId(from);
36357
+ throw fsError("EBUSY", from);
36358
+ }
36359
+ const commit = reservation.copyCommit?.intent === intent ? reservation.copyCommit : void 0;
36360
+ const entries = commit?.entries ?? rename.copiedEntries;
36361
+ const expected = entries?.find((entry) => entry.path === "")?.id ?? rename.physicalSource;
36362
+ if (expected === void 0 || await this.sourceId(from) === expected) {
36363
+ const [dir, name2] = await this.parent(from);
36364
+ await this.inDir(dir, (parent) => {
36365
+ signal?.throwIfAborted();
36366
+ return entries ? removeCopied(
36367
+ parent,
36368
+ name2,
36369
+ entries,
36370
+ signal,
36371
+ commit?.indexed ? (path) => storedStamp(this.meta, intent, path) : void 0
36372
+ ) : parent.removeEntry(name2);
36373
+ });
36374
+ }
36375
+ }
36291
36376
  async cleanSource(intent, from, id2, signal) {
36292
36377
  const remove = async () => {
36293
36378
  if (signal?.aborted) return;
@@ -36296,14 +36381,7 @@ var OpfsFs = class {
36296
36381
  const [reservation] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [from]);
36297
36382
  if (reservation?.vacated && reservation.ino === id2) {
36298
36383
  try {
36299
- const expected = current.rename.physicalSource;
36300
- if (expected === void 0 || await this.sourceId(from) === expected) {
36301
- const [dir, name2] = await this.parent(from);
36302
- await this.inDir(dir, (parent) => {
36303
- signal?.throwIfAborted();
36304
- return current.rename?.copiedEntries ? removeCopied(parent, name2, current.rename.copiedEntries, signal) : parent.removeEntry(name2);
36305
- });
36306
- }
36384
+ await this.removeReserved(intent, from, reservation, current.rename, signal);
36307
36385
  } catch (err) {
36308
36386
  if (!missing5(err) && err.name !== "NotFoundError") return;
36309
36387
  }
@@ -36312,7 +36390,7 @@ var OpfsFs = class {
36312
36390
  (current2) => current2?.vacated && current2.ino === reservation.ino ? vacatedAt(from) : current2
36313
36391
  );
36314
36392
  }
36315
- await this.meta.update(intent, () => void 0);
36393
+ await this.retireIntent(intent);
36316
36394
  }
36317
36395
  this.syncSourceReservation(intent);
36318
36396
  };
@@ -36324,7 +36402,7 @@ var OpfsFs = class {
36324
36402
  }
36325
36403
  async duplicate(handle, parent, name2, copies, rest2) {
36326
36404
  if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
36327
- copies.remaining.push(await copiedEntry(handle, rest2));
36405
+ await copies.manifest?.record(await copiedEntry(handle, rest2));
36328
36406
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
36329
36407
  this.others++;
36330
36408
  for await (const child2 of handle.values())
@@ -36416,7 +36494,7 @@ var OpfsFs = class {
36416
36494
  }
36417
36495
  this.forget(from);
36418
36496
  this.forget(to);
36419
- for (const intent of intents) if (intent) await this.meta.update(intent, () => void 0);
36497
+ for (const intent of intents) if (intent) await this.retireIntent(intent);
36420
36498
  } catch {
36421
36499
  }
36422
36500
  }
@@ -36452,7 +36530,7 @@ var OpfsFs = class {
36452
36530
  }
36453
36531
  if (!left) {
36454
36532
  if ((await this.swapEntry(to))?.kind !== "directory") throw fsError("EIO", to);
36455
- return this.commitPrivateCopy(from, to, root, intent, new Copies(), backup);
36533
+ return this.commitPrivateCopy(from, to, root, intent, new Copies(this.meta, intent), backup);
36456
36534
  }
36457
36535
  const staged2 = await this.swapEntry(backup);
36458
36536
  if (staged2) {
@@ -36470,16 +36548,27 @@ var OpfsFs = class {
36470
36548
  const [mark, placed] = await this.meta.get([from, to]);
36471
36549
  if (mark?.vacated && mark.ino !== void 0 && mark.copyCommit?.intent === intent) {
36472
36550
  const commit = mark.copyCommit;
36473
- return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock, commit.entries);
36551
+ return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock);
36552
+ }
36553
+ if (mark?.vacated && mark.ino !== void 0 && mark.ino !== root?.ino) {
36554
+ if (!mark.copyCommit)
36555
+ return this.releaseSource(
36556
+ intent,
36557
+ from,
36558
+ to,
36559
+ mark.ino,
36560
+ rename.lock,
36561
+ !root || placed?.ino !== root.ino
36562
+ );
36563
+ return this.retireIntent(intent);
36474
36564
  }
36475
36565
  const left = await this.real(from);
36476
- if (left && root && mark?.vacated && mark.ino !== void 0 && placed?.ino === root.ino)
36477
- return this.releaseSource(intent, from, to, mark.ino, rename.lock);
36566
+ await this.meta.remove([manifestRoot(intent)]);
36478
36567
  if (rename.privateCopy) {
36479
36568
  if (left) {
36480
36569
  const src = await this.locate(from, false);
36481
36570
  const dir = await this.locate(parentOf11(to), true);
36482
- const copies = new Copies();
36571
+ const copies = new Copies(this.meta, intent);
36483
36572
  await this.duplicate(
36484
36573
  src.handle,
36485
36574
  dir.handle,
@@ -36488,14 +36577,14 @@ var OpfsFs = class {
36488
36577
  ""
36489
36578
  );
36490
36579
  await this.commitPrivateCopy(from, to, root ?? { ino: inodeOf(from) }, intent, copies);
36491
- } else await this.meta.update(intent, () => void 0);
36580
+ } else await this.retireIntent(intent);
36492
36581
  return;
36493
36582
  }
36494
36583
  await this.resumeCoordinatedCopy(intent, rename, left);
36495
36584
  }
36496
36585
  async resumeCoordinatedCopy(intent, rename, left) {
36497
36586
  const { from, to, replace, root } = rename;
36498
- const copies = new Copies();
36587
+ const copies = new Copies(this.meta, intent);
36499
36588
  if (left && replace && await this.real(to))
36500
36589
  await PLAIN3.rm.call(this, to, { recursive: true });
36501
36590
  if (left) {
@@ -36510,7 +36599,7 @@ var OpfsFs = class {
36510
36599
  this.forget(from);
36511
36600
  this.forget(to);
36512
36601
  }
36513
- const mark = left ? vacatedAt(from, copies.marker(intent, to)) : void 0;
36602
+ const mark = left ? vacatedAt(from, await copies.manifest?.marker(to)) : void 0;
36514
36603
  if ((await this.meta.under(from)).some((entry) => !entry.vacated)) {
36515
36604
  await this.meta.move(
36516
36605
  from,
@@ -36524,8 +36613,8 @@ var OpfsFs = class {
36524
36613
  mark
36525
36614
  );
36526
36615
  } else if (mark) await this.meta.update(from, () => mark);
36527
- if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock, copies.remaining);
36528
- else await this.meta.update(intent, () => void 0);
36616
+ if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock);
36617
+ else await this.retireIntent(intent);
36529
36618
  this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36530
36619
  }
36531
36620
  async finishRename(entry) {
@@ -36681,6 +36770,7 @@ var OpfsFs = class {
36681
36770
  const before = this.fileMoves;
36682
36771
  try {
36683
36772
  await this.copy(handle, dir, name2, { copies });
36773
+ await copies.manifest?.flush();
36684
36774
  } catch (err) {
36685
36775
  if (handle.kind === "directory" && this.fileMoves === before) {
36686
36776
  await this.io(dir.removeEntry(name2, { recursive: true }));
@@ -36727,7 +36817,7 @@ var OpfsFs = class {
36727
36817
  if (await this.moveChild(handle, dir, name2)) return;
36728
36818
  return this.copyBytes(handle, dir, name2, options, rest2);
36729
36819
  }
36730
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2));
36820
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2));
36731
36821
  const target = await this.io(dir.getDirectoryHandle(name2, { create: true }));
36732
36822
  this.others++;
36733
36823
  for await (const child2 of handle.values()) {
@@ -36736,6 +36826,7 @@ var OpfsFs = class {
36736
36826
  }
36737
36827
  async copyBytes(handle, dir, name2, options, rest2) {
36738
36828
  const file = await this.io(handle.getFile());
36829
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2, file));
36739
36830
  const made2 = await this.io(dir.getFileHandle(name2, { create: true }));
36740
36831
  const writable3 = await this.io(made2.createWritable());
36741
36832
  try {
@@ -36745,7 +36836,6 @@ var OpfsFs = class {
36745
36836
  await writable3.abort().catch(nothing2);
36746
36837
  throw err;
36747
36838
  }
36748
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2, file));
36749
36839
  options.copies?.set(rest2, {
36750
36840
  before: options.copies.get(rest2)?.before ?? file.lastModified,
36751
36841
  made: made2
@@ -36887,7 +36977,7 @@ var OpfsFs = class {
36887
36977
  const entries = await this.meta.all();
36888
36978
  const carried = new Set(entries.filter((e) => !e.vacated).map((e) => e.ino));
36889
36979
  const checked = entries.filter(
36890
- (e) => !e.rename && !(e.vacated && carried.has(inodeOf(e.path)))
36980
+ (e) => !e.rename && !e.copyStamp && !(e.vacated && carried.has(inodeOf(e.path)))
36891
36981
  );
36892
36982
  const real2 = await this.present(
36893
36983
  checked.flatMap((e) => e.link === void 0 ? [e.path] : [e.path, parentOf11(e.path)])