@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.
package/dist/node.js CHANGED
@@ -7845,7 +7845,7 @@ function satisfies(version, range2) {
7845
7845
  }
7846
7846
 
7847
7847
  // src/version.ts
7848
- var KERNEL_VERSION = true ? "1.196.43" : "0.0.0-dev";
7848
+ var KERNEL_VERSION = true ? "1.196.44" : "0.0.0-dev";
7849
7849
  var OS_RELEASE = "6.0.0-slicc";
7850
7850
  function procVersion() {
7851
7851
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -34262,9 +34262,9 @@ async function copiedEntry(handle, path, file) {
34262
34262
  function absent(err) {
34263
34263
  return err.name === "NotFoundError";
34264
34264
  }
34265
- async function removeOne(parent, name2, rest2, entries, signal) {
34265
+ async function removeOne(parent, name2, rest2, lookup4, signal) {
34266
34266
  signal?.throwIfAborted();
34267
- const entry = entries.get(rest2);
34267
+ const entry = await lookup4(rest2);
34268
34268
  if (!entry) return;
34269
34269
  try {
34270
34270
  const handle = entry.kind === "file" ? await parent.getFileHandle(name2) : await parent.getDirectoryHandle(name2);
@@ -34274,7 +34274,7 @@ async function removeOne(parent, name2, rest2, entries, signal) {
34274
34274
  if (file.lastModified !== entry.mtime || file.size !== entry.size) return;
34275
34275
  } else {
34276
34276
  for await (const child2 of handle.keys())
34277
- await removeOne(handle, child2, rest2 + "/" + child2, entries, signal);
34277
+ await removeOne(handle, child2, rest2 + "/" + child2, lookup4, signal);
34278
34278
  }
34279
34279
  signal?.throwIfAborted();
34280
34280
  await parent.removeEntry(name2);
@@ -34282,10 +34282,64 @@ async function removeOne(parent, name2, rest2, entries, signal) {
34282
34282
  if (!absent(err) && err.name !== "TypeMismatchError") throw err;
34283
34283
  }
34284
34284
  }
34285
- function removeCopied(parent, name2, manifest, signal) {
34286
- return removeOne(parent, name2, "", new Map(manifest.map((entry) => [entry.path, entry])), signal);
34285
+ function removeCopied(parent, name2, manifest, signal, overflow) {
34286
+ const entries = new Map(manifest.map((entry) => [entry.path, entry]));
34287
+ return removeOne(parent, name2, "", (path) => entries.get(path) ?? overflow?.(path), signal);
34287
34288
  }
34288
34289
 
34290
+ // src/fs/rename-manifest.ts
34291
+ var INLINE_BYTES = 256 * 1024;
34292
+ var BATCH = 64;
34293
+ function manifestRoot(intent) {
34294
+ return "rename-manifest:" + intent;
34295
+ }
34296
+ async function storedStamp(meta, intent, path) {
34297
+ const [row] = await meta.get([manifestRoot(intent) + path]);
34298
+ return row?.copyStamp && { path, ...row.copyStamp };
34299
+ }
34300
+ var RenameManifest = class {
34301
+ meta;
34302
+ intent;
34303
+ entries = [];
34304
+ pending = [];
34305
+ bytes = 2;
34306
+ indexed = false;
34307
+ constructor(meta, intent) {
34308
+ this.meta = meta;
34309
+ this.intent = intent;
34310
+ }
34311
+ async record(entry) {
34312
+ if (!this.indexed) {
34313
+ this.bytes += storedSize(JSON.stringify(entry)) + 1;
34314
+ if (this.bytes <= INLINE_BYTES) {
34315
+ this.entries.push(entry);
34316
+ return;
34317
+ }
34318
+ this.indexed = true;
34319
+ }
34320
+ const { path: relative2, ...copyStamp } = entry;
34321
+ const path = manifestRoot(this.intent) + relative2;
34322
+ this.pending.push({ path, change: () => ({ path, copyStamp }) });
34323
+ if (this.pending.length === BATCH) await this.flush();
34324
+ }
34325
+ async flush() {
34326
+ if (!this.pending.length) return;
34327
+ if (this.meta.updateMany) await this.meta.updateMany(this.pending);
34328
+ else for (const { path, change } of this.pending) await this.meta.update(path, change);
34329
+ this.pending.length = 0;
34330
+ }
34331
+ async marker(to) {
34332
+ await this.flush();
34333
+ if (!this.entries.length && !this.indexed) return void 0;
34334
+ return {
34335
+ intent: this.intent,
34336
+ to,
34337
+ entries: this.entries,
34338
+ ...this.indexed && { indexed: true }
34339
+ };
34340
+ }
34341
+ };
34342
+
34289
34343
  // src/fs/opfs.ts
34290
34344
  var S_IFDIR2 = 16384;
34291
34345
  var S_IFREG3 = 32768;
@@ -34333,9 +34387,10 @@ var INTENT_POLL_MS = 5;
34333
34387
  var SOURCE_RETRY_MS = 250;
34334
34388
  var SOURCE_BACKOFF_MS = 1e3;
34335
34389
  var Copies = class extends Map {
34336
- remaining = [];
34337
- marker(intent, to) {
34338
- return intent && this.remaining.length ? { intent, to, entries: this.remaining } : void 0;
34390
+ manifest;
34391
+ constructor(meta, intent) {
34392
+ super();
34393
+ if (intent) this.manifest = new RenameManifest(meta, intent);
34339
34394
  }
34340
34395
  };
34341
34396
  function needsCopy(handle, swap) {
@@ -36097,12 +36152,12 @@ var OpfsFs = class {
36097
36152
  return this.privateCopy(source, parent, destination, target?.handle, moving);
36098
36153
  const place = async () => {
36099
36154
  this.forget(destination);
36100
- const copies = new Copies();
36101
- const root = { ino: inodeOf(source.path), ...moving };
36155
+ const root = { ino: sourceStat.ino, ...moving };
36102
36156
  const owned4 = lock ? { lock } : {};
36103
36157
  hooks.notify?.();
36104
36158
  const first = copying ? await this.intend({ from: source.path, to: staged2, root, ...owned4 }) : void 0;
36105
36159
  const second = copying && swap ? await this.intend({ from: staged2, to: destination, replace: true, root, ...owned4 }) : void 0;
36160
+ const copies = new Copies(this.meta, first);
36106
36161
  await hooks.started?.().catch(async (err) => {
36107
36162
  for (const intent of [first, second]) {
36108
36163
  if (intent) await this.meta.update(intent, () => void 0);
@@ -36118,21 +36173,21 @@ var OpfsFs = class {
36118
36173
  });
36119
36174
  if (swap) await PLAIN3.rm.call(this, destination);
36120
36175
  if (second) await this.intend({ from: staged2, to: destination, root, ...owned4 }, second);
36121
- left.copyCommit = copies.marker(first, destination);
36176
+ left.copyCommit = await copies.manifest?.marker(destination);
36122
36177
  await this.meta.move(source.path, destination, carry, left);
36123
36178
  this.movePending(source.path, destination);
36124
36179
  if (!moved2 && first)
36125
- await this.releaseSource(first, source.path, destination, left.ino, lock, copies.remaining);
36126
- else if (first) await this.meta.update(first, () => void 0);
36127
- if (swap) {
36180
+ await this.releaseSource(first, source.path, destination, left.ino, lock);
36181
+ else if (first) await this.retireIntent(first);
36182
+ if (swap && second) {
36128
36183
  const hidden = await dir.getDirectoryHandle(staging);
36129
- copies.remaining = [];
36184
+ copies.manifest = new RenameManifest(this.meta, second);
36130
36185
  const placed = await this.place(hidden, dir, name2, copies, copying);
36131
- if (!placed && second) {
36132
- const mark = vacatedAt(staged2, copies.marker(second, destination));
36186
+ if (!placed) {
36187
+ const mark = vacatedAt(staged2, await copies.manifest.marker(destination));
36133
36188
  await this.meta.update(staged2, () => mark);
36134
- await this.releaseSource(second, staged2, destination, mark.ino, lock, copies.remaining);
36135
- } else if (second) await this.meta.update(second, () => void 0);
36189
+ await this.releaseSource(second, staged2, destination, mark.ino, lock);
36190
+ } else await this.retireIntent(second);
36136
36191
  }
36137
36192
  await this.restamp(destination, copies);
36138
36193
  this.changed(source.path, destination);
@@ -36514,7 +36569,6 @@ var OpfsFs = class {
36514
36569
  const handle = source.handle;
36515
36570
  const dir = parent.handle;
36516
36571
  const name2 = baseOf4(to);
36517
- const copies = new Copies();
36518
36572
  const [entry] = await this.meta.get([source.path]);
36519
36573
  const root = { ino: occupied(entry).ino ?? inodeOf(source.path), ...owner };
36520
36574
  if (target?.kind === "directory" && movable(target) && movable(handle)) {
@@ -36524,14 +36578,23 @@ var OpfsFs = class {
36524
36578
  if (await this.swapNative(source, dir, name2, target, emptyBackup, intent2)) {
36525
36579
  this.forget(source.path);
36526
36580
  this.forget(to);
36527
- await this.commitPrivateCopy(source.path, to, root, intent2, copies, emptyBackup);
36581
+ await this.commitPrivateCopy(
36582
+ source.path,
36583
+ to,
36584
+ root,
36585
+ intent2,
36586
+ new Copies(this.meta, intent2),
36587
+ emptyBackup
36588
+ );
36528
36589
  return;
36529
36590
  }
36530
36591
  }
36531
36592
  await this.beforePrivateCopy?.();
36532
36593
  const intent = await this.intend({ from: source.path, to, root, privateCopy: true });
36594
+ const copies = new Copies(this.meta, intent);
36533
36595
  try {
36534
36596
  await this.duplicate(handle, dir, name2, copies, "");
36597
+ await copies.manifest?.flush();
36535
36598
  } catch (err) {
36536
36599
  if (!target)
36537
36600
  await dir.removeEntry(name2, { recursive: true }).catch((e) => {
@@ -36542,7 +36605,7 @@ var OpfsFs = class {
36542
36605
  await target.removeEntry(child2, { recursive: true });
36543
36606
  }
36544
36607
  this.forget(to);
36545
- await this.meta.update(intent, () => void 0);
36608
+ await this.retireIntent(intent);
36546
36609
  throw translate(err, to, "write");
36547
36610
  }
36548
36611
  await this.commitPrivateCopy(source.path, to, root, intent, copies);
@@ -36569,7 +36632,7 @@ var OpfsFs = class {
36569
36632
  const entries = await this.meta.get([from, to]);
36570
36633
  let mark = entries[0];
36571
36634
  if (!mark?.vacated || entries[1]?.ino !== ino) {
36572
- mark = vacatedAt(from, copies.marker(intent, to));
36635
+ mark = vacatedAt(from, await copies.manifest?.marker(to));
36573
36636
  await this.meta.move(
36574
36637
  from,
36575
36638
  to,
@@ -36577,8 +36640,7 @@ var OpfsFs = class {
36577
36640
  mark
36578
36641
  );
36579
36642
  }
36580
- if (!emptyBackup)
36581
- await this.releaseSource(intent, from, to, mark.ino, void 0, copies.remaining);
36643
+ if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino);
36582
36644
  this.movePending(from, to);
36583
36645
  await this.restamp(to, copies);
36584
36646
  this.changed(from, to);
@@ -36600,22 +36662,45 @@ var OpfsFs = class {
36600
36662
  }
36601
36663
  return cleanupId(handle);
36602
36664
  }
36603
- async releaseSource(intent, from, to, id2, lock, copiedEntries) {
36665
+ retireIntent(intent) {
36666
+ return this.meta.remove([intent, manifestRoot(intent)]);
36667
+ }
36668
+ async releaseSource(intent, from, to, id2, lock, unverified = false) {
36604
36669
  this.syncSourceReservation(intent, from);
36605
- const physicalSource = copiedEntries?.find((entry) => entry.path === "")?.id;
36606
36670
  await this.intend(
36607
36671
  {
36608
36672
  from,
36609
36673
  to,
36610
36674
  sourceCleanup: id2,
36611
- ...lock && { lock },
36612
- ...physicalSource && { physicalSource },
36613
- ...copiedEntries && { copiedEntries }
36675
+ ...unverified && { unverifiedSource: true },
36676
+ ...lock && { lock }
36614
36677
  },
36615
36678
  intent
36616
36679
  );
36617
36680
  await this.cleanSource(intent, from, id2);
36618
36681
  }
36682
+ async removeReserved(intent, from, reservation, rename, signal) {
36683
+ if (rename.unverifiedSource) {
36684
+ await this.sourceId(from);
36685
+ throw fsError("EBUSY", from);
36686
+ }
36687
+ const commit = reservation.copyCommit?.intent === intent ? reservation.copyCommit : void 0;
36688
+ const entries = commit?.entries ?? rename.copiedEntries;
36689
+ const expected = entries?.find((entry) => entry.path === "")?.id ?? rename.physicalSource;
36690
+ if (expected === void 0 || await this.sourceId(from) === expected) {
36691
+ const [dir, name2] = await this.parent(from);
36692
+ await this.inDir(dir, (parent) => {
36693
+ signal?.throwIfAborted();
36694
+ return entries ? removeCopied(
36695
+ parent,
36696
+ name2,
36697
+ entries,
36698
+ signal,
36699
+ commit?.indexed ? (path) => storedStamp(this.meta, intent, path) : void 0
36700
+ ) : parent.removeEntry(name2);
36701
+ });
36702
+ }
36703
+ }
36619
36704
  async cleanSource(intent, from, id2, signal) {
36620
36705
  const remove = async () => {
36621
36706
  if (signal?.aborted) return;
@@ -36624,14 +36709,7 @@ var OpfsFs = class {
36624
36709
  const [reservation] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [from]);
36625
36710
  if (reservation?.vacated && reservation.ino === id2) {
36626
36711
  try {
36627
- const expected = current.rename.physicalSource;
36628
- if (expected === void 0 || await this.sourceId(from) === expected) {
36629
- const [dir, name2] = await this.parent(from);
36630
- await this.inDir(dir, (parent) => {
36631
- signal?.throwIfAborted();
36632
- return current.rename?.copiedEntries ? removeCopied(parent, name2, current.rename.copiedEntries, signal) : parent.removeEntry(name2);
36633
- });
36634
- }
36712
+ await this.removeReserved(intent, from, reservation, current.rename, signal);
36635
36713
  } catch (err) {
36636
36714
  if (!missing6(err) && err.name !== "NotFoundError") return;
36637
36715
  }
@@ -36640,7 +36718,7 @@ var OpfsFs = class {
36640
36718
  (current2) => current2?.vacated && current2.ino === reservation.ino ? vacatedAt(from) : current2
36641
36719
  );
36642
36720
  }
36643
- await this.meta.update(intent, () => void 0);
36721
+ await this.retireIntent(intent);
36644
36722
  }
36645
36723
  this.syncSourceReservation(intent);
36646
36724
  };
@@ -36652,7 +36730,7 @@ var OpfsFs = class {
36652
36730
  }
36653
36731
  async duplicate(handle, parent, name2, copies, rest2) {
36654
36732
  if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
36655
- copies.remaining.push(await copiedEntry(handle, rest2));
36733
+ await copies.manifest?.record(await copiedEntry(handle, rest2));
36656
36734
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
36657
36735
  this.others++;
36658
36736
  for await (const child2 of handle.values())
@@ -36744,7 +36822,7 @@ var OpfsFs = class {
36744
36822
  }
36745
36823
  this.forget(from);
36746
36824
  this.forget(to);
36747
- for (const intent of intents) if (intent) await this.meta.update(intent, () => void 0);
36825
+ for (const intent of intents) if (intent) await this.retireIntent(intent);
36748
36826
  } catch {
36749
36827
  }
36750
36828
  }
@@ -36780,7 +36858,7 @@ var OpfsFs = class {
36780
36858
  }
36781
36859
  if (!left) {
36782
36860
  if ((await this.swapEntry(to))?.kind !== "directory") throw fsError("EIO", to);
36783
- return this.commitPrivateCopy(from, to, root, intent, new Copies(), backup);
36861
+ return this.commitPrivateCopy(from, to, root, intent, new Copies(this.meta, intent), backup);
36784
36862
  }
36785
36863
  const staged2 = await this.swapEntry(backup);
36786
36864
  if (staged2) {
@@ -36798,16 +36876,27 @@ var OpfsFs = class {
36798
36876
  const [mark, placed] = await this.meta.get([from, to]);
36799
36877
  if (mark?.vacated && mark.ino !== void 0 && mark.copyCommit?.intent === intent) {
36800
36878
  const commit = mark.copyCommit;
36801
- return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock, commit.entries);
36879
+ return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock);
36880
+ }
36881
+ if (mark?.vacated && mark.ino !== void 0 && mark.ino !== root?.ino) {
36882
+ if (!mark.copyCommit)
36883
+ return this.releaseSource(
36884
+ intent,
36885
+ from,
36886
+ to,
36887
+ mark.ino,
36888
+ rename.lock,
36889
+ !root || placed?.ino !== root.ino
36890
+ );
36891
+ return this.retireIntent(intent);
36802
36892
  }
36803
36893
  const left = await this.real(from);
36804
- if (left && root && mark?.vacated && mark.ino !== void 0 && placed?.ino === root.ino)
36805
- return this.releaseSource(intent, from, to, mark.ino, rename.lock);
36894
+ await this.meta.remove([manifestRoot(intent)]);
36806
36895
  if (rename.privateCopy) {
36807
36896
  if (left) {
36808
36897
  const src = await this.locate(from, false);
36809
36898
  const dir = await this.locate(parentOf11(to), true);
36810
- const copies = new Copies();
36899
+ const copies = new Copies(this.meta, intent);
36811
36900
  await this.duplicate(
36812
36901
  src.handle,
36813
36902
  dir.handle,
@@ -36816,14 +36905,14 @@ var OpfsFs = class {
36816
36905
  ""
36817
36906
  );
36818
36907
  await this.commitPrivateCopy(from, to, root ?? { ino: inodeOf(from) }, intent, copies);
36819
- } else await this.meta.update(intent, () => void 0);
36908
+ } else await this.retireIntent(intent);
36820
36909
  return;
36821
36910
  }
36822
36911
  await this.resumeCoordinatedCopy(intent, rename, left);
36823
36912
  }
36824
36913
  async resumeCoordinatedCopy(intent, rename, left) {
36825
36914
  const { from, to, replace, root } = rename;
36826
- const copies = new Copies();
36915
+ const copies = new Copies(this.meta, intent);
36827
36916
  if (left && replace && await this.real(to))
36828
36917
  await PLAIN3.rm.call(this, to, { recursive: true });
36829
36918
  if (left) {
@@ -36838,7 +36927,7 @@ var OpfsFs = class {
36838
36927
  this.forget(from);
36839
36928
  this.forget(to);
36840
36929
  }
36841
- const mark = left ? vacatedAt(from, copies.marker(intent, to)) : void 0;
36930
+ const mark = left ? vacatedAt(from, await copies.manifest?.marker(to)) : void 0;
36842
36931
  if ((await this.meta.under(from)).some((entry) => !entry.vacated)) {
36843
36932
  await this.meta.move(
36844
36933
  from,
@@ -36852,8 +36941,8 @@ var OpfsFs = class {
36852
36941
  mark
36853
36942
  );
36854
36943
  } else if (mark) await this.meta.update(from, () => mark);
36855
- if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock, copies.remaining);
36856
- else await this.meta.update(intent, () => void 0);
36944
+ if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock);
36945
+ else await this.retireIntent(intent);
36857
36946
  this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36858
36947
  }
36859
36948
  async finishRename(entry) {
@@ -37009,6 +37098,7 @@ var OpfsFs = class {
37009
37098
  const before = this.fileMoves;
37010
37099
  try {
37011
37100
  await this.copy(handle, dir, name2, { copies });
37101
+ await copies.manifest?.flush();
37012
37102
  } catch (err) {
37013
37103
  if (handle.kind === "directory" && this.fileMoves === before) {
37014
37104
  await this.io(dir.removeEntry(name2, { recursive: true }));
@@ -37055,7 +37145,7 @@ var OpfsFs = class {
37055
37145
  if (await this.moveChild(handle, dir, name2)) return;
37056
37146
  return this.copyBytes(handle, dir, name2, options, rest2);
37057
37147
  }
37058
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2));
37148
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2));
37059
37149
  const target = await this.io(dir.getDirectoryHandle(name2, { create: true }));
37060
37150
  this.others++;
37061
37151
  for await (const child2 of handle.values()) {
@@ -37064,6 +37154,7 @@ var OpfsFs = class {
37064
37154
  }
37065
37155
  async copyBytes(handle, dir, name2, options, rest2) {
37066
37156
  const file = await this.io(handle.getFile());
37157
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2, file));
37067
37158
  const made2 = await this.io(dir.getFileHandle(name2, { create: true }));
37068
37159
  const writable3 = await this.io(made2.createWritable());
37069
37160
  try {
@@ -37073,7 +37164,6 @@ var OpfsFs = class {
37073
37164
  await writable3.abort().catch(nothing2);
37074
37165
  throw err;
37075
37166
  }
37076
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2, file));
37077
37167
  options.copies?.set(rest2, {
37078
37168
  before: options.copies.get(rest2)?.before ?? file.lastModified,
37079
37169
  made: made2
@@ -37215,7 +37305,7 @@ var OpfsFs = class {
37215
37305
  const entries = await this.meta.all();
37216
37306
  const carried = new Set(entries.filter((e) => !e.vacated).map((e) => e.ino));
37217
37307
  const checked = entries.filter(
37218
- (e) => !e.rename && !(e.vacated && carried.has(inodeOf(e.path)))
37308
+ (e) => !e.rename && !e.copyStamp && !(e.vacated && carried.has(inodeOf(e.path)))
37219
37309
  );
37220
37310
  const real = await this.present(
37221
37311
  checked.flatMap((e) => e.link === void 0 ? [e.path] : [e.path, parentOf11(e.path)])