@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.
@@ -1883,9 +1883,9 @@ async function copiedEntry(handle, path, file) {
1883
1883
  function absent(err) {
1884
1884
  return err.name === "NotFoundError";
1885
1885
  }
1886
- async function removeOne(parent, name2, rest2, entries, signal) {
1886
+ async function removeOne(parent, name2, rest2, lookup2, signal) {
1887
1887
  signal?.throwIfAborted();
1888
- const entry = entries.get(rest2);
1888
+ const entry = await lookup2(rest2);
1889
1889
  if (!entry) return;
1890
1890
  try {
1891
1891
  const handle = entry.kind === "file" ? await parent.getFileHandle(name2) : await parent.getDirectoryHandle(name2);
@@ -1895,7 +1895,7 @@ async function removeOne(parent, name2, rest2, entries, signal) {
1895
1895
  if (file.lastModified !== entry.mtime || file.size !== entry.size) return;
1896
1896
  } else {
1897
1897
  for await (const child2 of handle.keys())
1898
- await removeOne(handle, child2, rest2 + "/" + child2, entries, signal);
1898
+ await removeOne(handle, child2, rest2 + "/" + child2, lookup2, signal);
1899
1899
  }
1900
1900
  signal?.throwIfAborted();
1901
1901
  await parent.removeEntry(name2);
@@ -1903,10 +1903,64 @@ async function removeOne(parent, name2, rest2, entries, signal) {
1903
1903
  if (!absent(err) && err.name !== "TypeMismatchError") throw err;
1904
1904
  }
1905
1905
  }
1906
- function removeCopied(parent, name2, manifest, signal) {
1907
- return removeOne(parent, name2, "", new Map(manifest.map((entry) => [entry.path, entry])), signal);
1906
+ function removeCopied(parent, name2, manifest, signal, overflow) {
1907
+ const entries = new Map(manifest.map((entry) => [entry.path, entry]));
1908
+ return removeOne(parent, name2, "", (path) => entries.get(path) ?? overflow?.(path), signal);
1908
1909
  }
1909
1910
 
1911
+ // src/fs/rename-manifest.ts
1912
+ var INLINE_BYTES = 256 * 1024;
1913
+ var BATCH = 64;
1914
+ function manifestRoot(intent) {
1915
+ return "rename-manifest:" + intent;
1916
+ }
1917
+ async function storedStamp(meta, intent, path) {
1918
+ const [row] = await meta.get([manifestRoot(intent) + path]);
1919
+ return row?.copyStamp && { path, ...row.copyStamp };
1920
+ }
1921
+ var RenameManifest = class {
1922
+ meta;
1923
+ intent;
1924
+ entries = [];
1925
+ pending = [];
1926
+ bytes = 2;
1927
+ indexed = false;
1928
+ constructor(meta, intent) {
1929
+ this.meta = meta;
1930
+ this.intent = intent;
1931
+ }
1932
+ async record(entry) {
1933
+ if (!this.indexed) {
1934
+ this.bytes += storedSize(JSON.stringify(entry)) + 1;
1935
+ if (this.bytes <= INLINE_BYTES) {
1936
+ this.entries.push(entry);
1937
+ return;
1938
+ }
1939
+ this.indexed = true;
1940
+ }
1941
+ const { path: relative2, ...copyStamp } = entry;
1942
+ const path = manifestRoot(this.intent) + relative2;
1943
+ this.pending.push({ path, change: () => ({ path, copyStamp }) });
1944
+ if (this.pending.length === BATCH) await this.flush();
1945
+ }
1946
+ async flush() {
1947
+ if (!this.pending.length) return;
1948
+ if (this.meta.updateMany) await this.meta.updateMany(this.pending);
1949
+ else for (const { path, change } of this.pending) await this.meta.update(path, change);
1950
+ this.pending.length = 0;
1951
+ }
1952
+ async marker(to) {
1953
+ await this.flush();
1954
+ if (!this.entries.length && !this.indexed) return void 0;
1955
+ return {
1956
+ intent: this.intent,
1957
+ to,
1958
+ entries: this.entries,
1959
+ ...this.indexed && { indexed: true }
1960
+ };
1961
+ }
1962
+ };
1963
+
1910
1964
  // src/fs/view.ts
1911
1965
  function view(target, overrides) {
1912
1966
  const keys2 = new Set(Object.keys(overrides));
@@ -1971,9 +2025,10 @@ var INTENT_POLL_MS = 5;
1971
2025
  var SOURCE_RETRY_MS = 250;
1972
2026
  var SOURCE_BACKOFF_MS = 1e3;
1973
2027
  var Copies = class extends Map {
1974
- remaining = [];
1975
- marker(intent, to) {
1976
- return intent && this.remaining.length ? { intent, to, entries: this.remaining } : void 0;
2028
+ manifest;
2029
+ constructor(meta, intent) {
2030
+ super();
2031
+ if (intent) this.manifest = new RenameManifest(meta, intent);
1977
2032
  }
1978
2033
  };
1979
2034
  function needsCopy(handle, swap) {
@@ -3739,12 +3794,12 @@ var OpfsFs = class {
3739
3794
  return this.privateCopy(source, parent, destination, target?.handle, moving);
3740
3795
  const place = async () => {
3741
3796
  this.forget(destination);
3742
- const copies = new Copies();
3743
- const root = { ino: inodeOf(source.path), ...moving };
3797
+ const root = { ino: sourceStat.ino, ...moving };
3744
3798
  const owned4 = lock ? { lock } : {};
3745
3799
  hooks.notify?.();
3746
3800
  const first = copying ? await this.intend({ from: source.path, to: staged2, root, ...owned4 }) : void 0;
3747
3801
  const second = copying && swap ? await this.intend({ from: staged2, to: destination, replace: true, root, ...owned4 }) : void 0;
3802
+ const copies = new Copies(this.meta, first);
3748
3803
  await hooks.started?.().catch(async (err) => {
3749
3804
  for (const intent of [first, second]) {
3750
3805
  if (intent) await this.meta.update(intent, () => void 0);
@@ -3760,21 +3815,21 @@ var OpfsFs = class {
3760
3815
  });
3761
3816
  if (swap) await PLAIN.rm.call(this, destination);
3762
3817
  if (second) await this.intend({ from: staged2, to: destination, root, ...owned4 }, second);
3763
- left.copyCommit = copies.marker(first, destination);
3818
+ left.copyCommit = await copies.manifest?.marker(destination);
3764
3819
  await this.meta.move(source.path, destination, carry, left);
3765
3820
  this.movePending(source.path, destination);
3766
3821
  if (!moved2 && first)
3767
- await this.releaseSource(first, source.path, destination, left.ino, lock, copies.remaining);
3768
- else if (first) await this.meta.update(first, () => void 0);
3769
- if (swap) {
3822
+ await this.releaseSource(first, source.path, destination, left.ino, lock);
3823
+ else if (first) await this.retireIntent(first);
3824
+ if (swap && second) {
3770
3825
  const hidden = await dir.getDirectoryHandle(staging);
3771
- copies.remaining = [];
3826
+ copies.manifest = new RenameManifest(this.meta, second);
3772
3827
  const placed = await this.place(hidden, dir, name2, copies, copying);
3773
- if (!placed && second) {
3774
- const mark = vacatedAt(staged2, copies.marker(second, destination));
3828
+ if (!placed) {
3829
+ const mark = vacatedAt(staged2, await copies.manifest.marker(destination));
3775
3830
  await this.meta.update(staged2, () => mark);
3776
- await this.releaseSource(second, staged2, destination, mark.ino, lock, copies.remaining);
3777
- } else if (second) await this.meta.update(second, () => void 0);
3831
+ await this.releaseSource(second, staged2, destination, mark.ino, lock);
3832
+ } else await this.retireIntent(second);
3778
3833
  }
3779
3834
  await this.restamp(destination, copies);
3780
3835
  this.changed(source.path, destination);
@@ -4156,7 +4211,6 @@ var OpfsFs = class {
4156
4211
  const handle = source.handle;
4157
4212
  const dir = parent.handle;
4158
4213
  const name2 = baseOf(to);
4159
- const copies = new Copies();
4160
4214
  const [entry] = await this.meta.get([source.path]);
4161
4215
  const root = { ino: occupied(entry).ino ?? inodeOf(source.path), ...owner };
4162
4216
  if (target?.kind === "directory" && movable(target) && movable(handle)) {
@@ -4166,14 +4220,23 @@ var OpfsFs = class {
4166
4220
  if (await this.swapNative(source, dir, name2, target, emptyBackup, intent2)) {
4167
4221
  this.forget(source.path);
4168
4222
  this.forget(to);
4169
- await this.commitPrivateCopy(source.path, to, root, intent2, copies, emptyBackup);
4223
+ await this.commitPrivateCopy(
4224
+ source.path,
4225
+ to,
4226
+ root,
4227
+ intent2,
4228
+ new Copies(this.meta, intent2),
4229
+ emptyBackup
4230
+ );
4170
4231
  return;
4171
4232
  }
4172
4233
  }
4173
4234
  await this.beforePrivateCopy?.();
4174
4235
  const intent = await this.intend({ from: source.path, to, root, privateCopy: true });
4236
+ const copies = new Copies(this.meta, intent);
4175
4237
  try {
4176
4238
  await this.duplicate(handle, dir, name2, copies, "");
4239
+ await copies.manifest?.flush();
4177
4240
  } catch (err) {
4178
4241
  if (!target)
4179
4242
  await dir.removeEntry(name2, { recursive: true }).catch((e) => {
@@ -4184,7 +4247,7 @@ var OpfsFs = class {
4184
4247
  await target.removeEntry(child2, { recursive: true });
4185
4248
  }
4186
4249
  this.forget(to);
4187
- await this.meta.update(intent, () => void 0);
4250
+ await this.retireIntent(intent);
4188
4251
  throw translate(err, to, "write");
4189
4252
  }
4190
4253
  await this.commitPrivateCopy(source.path, to, root, intent, copies);
@@ -4211,7 +4274,7 @@ var OpfsFs = class {
4211
4274
  const entries = await this.meta.get([from, to]);
4212
4275
  let mark = entries[0];
4213
4276
  if (!mark?.vacated || entries[1]?.ino !== ino) {
4214
- mark = vacatedAt(from, copies.marker(intent, to));
4277
+ mark = vacatedAt(from, await copies.manifest?.marker(to));
4215
4278
  await this.meta.move(
4216
4279
  from,
4217
4280
  to,
@@ -4219,8 +4282,7 @@ var OpfsFs = class {
4219
4282
  mark
4220
4283
  );
4221
4284
  }
4222
- if (!emptyBackup)
4223
- await this.releaseSource(intent, from, to, mark.ino, void 0, copies.remaining);
4285
+ if (!emptyBackup) await this.releaseSource(intent, from, to, mark.ino);
4224
4286
  this.movePending(from, to);
4225
4287
  await this.restamp(to, copies);
4226
4288
  this.changed(from, to);
@@ -4242,22 +4304,45 @@ var OpfsFs = class {
4242
4304
  }
4243
4305
  return cleanupId(handle);
4244
4306
  }
4245
- async releaseSource(intent, from, to, id2, lock, copiedEntries) {
4307
+ retireIntent(intent) {
4308
+ return this.meta.remove([intent, manifestRoot(intent)]);
4309
+ }
4310
+ async releaseSource(intent, from, to, id2, lock, unverified = false) {
4246
4311
  this.syncSourceReservation(intent, from);
4247
- const physicalSource = copiedEntries?.find((entry) => entry.path === "")?.id;
4248
4312
  await this.intend(
4249
4313
  {
4250
4314
  from,
4251
4315
  to,
4252
4316
  sourceCleanup: id2,
4253
- ...lock && { lock },
4254
- ...physicalSource && { physicalSource },
4255
- ...copiedEntries && { copiedEntries }
4317
+ ...unverified && { unverifiedSource: true },
4318
+ ...lock && { lock }
4256
4319
  },
4257
4320
  intent
4258
4321
  );
4259
4322
  await this.cleanSource(intent, from, id2);
4260
4323
  }
4324
+ async removeReserved(intent, from, reservation, rename, signal) {
4325
+ if (rename.unverifiedSource) {
4326
+ await this.sourceId(from);
4327
+ throw fsError("EBUSY", from);
4328
+ }
4329
+ const commit = reservation.copyCommit?.intent === intent ? reservation.copyCommit : void 0;
4330
+ const entries = commit?.entries ?? rename.copiedEntries;
4331
+ const expected = entries?.find((entry) => entry.path === "")?.id ?? rename.physicalSource;
4332
+ if (expected === void 0 || await this.sourceId(from) === expected) {
4333
+ const [dir, name2] = await this.parent(from);
4334
+ await this.inDir(dir, (parent) => {
4335
+ signal?.throwIfAborted();
4336
+ return entries ? removeCopied(
4337
+ parent,
4338
+ name2,
4339
+ entries,
4340
+ signal,
4341
+ commit?.indexed ? (path) => storedStamp(this.meta, intent, path) : void 0
4342
+ ) : parent.removeEntry(name2);
4343
+ });
4344
+ }
4345
+ }
4261
4346
  async cleanSource(intent, from, id2, signal) {
4262
4347
  const remove = async () => {
4263
4348
  if (signal?.aborted) return;
@@ -4266,14 +4351,7 @@ var OpfsFs = class {
4266
4351
  const [reservation] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [from]);
4267
4352
  if (reservation?.vacated && reservation.ino === id2) {
4268
4353
  try {
4269
- const expected = current.rename.physicalSource;
4270
- if (expected === void 0 || await this.sourceId(from) === expected) {
4271
- const [dir, name2] = await this.parent(from);
4272
- await this.inDir(dir, (parent) => {
4273
- signal?.throwIfAborted();
4274
- return current.rename?.copiedEntries ? removeCopied(parent, name2, current.rename.copiedEntries, signal) : parent.removeEntry(name2);
4275
- });
4276
- }
4354
+ await this.removeReserved(intent, from, reservation, current.rename, signal);
4277
4355
  } catch (err) {
4278
4356
  if (!missing2(err) && err.name !== "NotFoundError") return;
4279
4357
  }
@@ -4282,7 +4360,7 @@ var OpfsFs = class {
4282
4360
  (current2) => current2?.vacated && current2.ino === reservation.ino ? vacatedAt(from) : current2
4283
4361
  );
4284
4362
  }
4285
- await this.meta.update(intent, () => void 0);
4363
+ await this.retireIntent(intent);
4286
4364
  }
4287
4365
  this.syncSourceReservation(intent);
4288
4366
  };
@@ -4294,7 +4372,7 @@ var OpfsFs = class {
4294
4372
  }
4295
4373
  async duplicate(handle, parent, name2, copies, rest2) {
4296
4374
  if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
4297
- copies.remaining.push(await copiedEntry(handle, rest2));
4375
+ await copies.manifest?.record(await copiedEntry(handle, rest2));
4298
4376
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
4299
4377
  this.others++;
4300
4378
  for await (const child2 of handle.values())
@@ -4386,7 +4464,7 @@ var OpfsFs = class {
4386
4464
  }
4387
4465
  this.forget(from);
4388
4466
  this.forget(to);
4389
- for (const intent of intents) if (intent) await this.meta.update(intent, () => void 0);
4467
+ for (const intent of intents) if (intent) await this.retireIntent(intent);
4390
4468
  } catch {
4391
4469
  }
4392
4470
  }
@@ -4422,7 +4500,7 @@ var OpfsFs = class {
4422
4500
  }
4423
4501
  if (!left) {
4424
4502
  if ((await this.swapEntry(to))?.kind !== "directory") throw fsError("EIO", to);
4425
- return this.commitPrivateCopy(from, to, root, intent, new Copies(), backup);
4503
+ return this.commitPrivateCopy(from, to, root, intent, new Copies(this.meta, intent), backup);
4426
4504
  }
4427
4505
  const staged2 = await this.swapEntry(backup);
4428
4506
  if (staged2) {
@@ -4440,16 +4518,27 @@ var OpfsFs = class {
4440
4518
  const [mark, placed] = await this.meta.get([from, to]);
4441
4519
  if (mark?.vacated && mark.ino !== void 0 && mark.copyCommit?.intent === intent) {
4442
4520
  const commit = mark.copyCommit;
4443
- return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock, commit.entries);
4521
+ return this.releaseSource(intent, from, commit.to, mark.ino, rename.lock);
4522
+ }
4523
+ if (mark?.vacated && mark.ino !== void 0 && mark.ino !== root?.ino) {
4524
+ if (!mark.copyCommit)
4525
+ return this.releaseSource(
4526
+ intent,
4527
+ from,
4528
+ to,
4529
+ mark.ino,
4530
+ rename.lock,
4531
+ !root || placed?.ino !== root.ino
4532
+ );
4533
+ return this.retireIntent(intent);
4444
4534
  }
4445
4535
  const left = await this.real(from);
4446
- if (left && root && mark?.vacated && mark.ino !== void 0 && placed?.ino === root.ino)
4447
- return this.releaseSource(intent, from, to, mark.ino, rename.lock);
4536
+ await this.meta.remove([manifestRoot(intent)]);
4448
4537
  if (rename.privateCopy) {
4449
4538
  if (left) {
4450
4539
  const src = await this.locate(from, false);
4451
4540
  const dir = await this.locate(parentOf4(to), true);
4452
- const copies = new Copies();
4541
+ const copies = new Copies(this.meta, intent);
4453
4542
  await this.duplicate(
4454
4543
  src.handle,
4455
4544
  dir.handle,
@@ -4458,14 +4547,14 @@ var OpfsFs = class {
4458
4547
  ""
4459
4548
  );
4460
4549
  await this.commitPrivateCopy(from, to, root ?? { ino: inodeOf(from) }, intent, copies);
4461
- } else await this.meta.update(intent, () => void 0);
4550
+ } else await this.retireIntent(intent);
4462
4551
  return;
4463
4552
  }
4464
4553
  await this.resumeCoordinatedCopy(intent, rename, left);
4465
4554
  }
4466
4555
  async resumeCoordinatedCopy(intent, rename, left) {
4467
4556
  const { from, to, replace, root } = rename;
4468
- const copies = new Copies();
4557
+ const copies = new Copies(this.meta, intent);
4469
4558
  if (left && replace && await this.real(to))
4470
4559
  await PLAIN.rm.call(this, to, { recursive: true });
4471
4560
  if (left) {
@@ -4480,7 +4569,7 @@ var OpfsFs = class {
4480
4569
  this.forget(from);
4481
4570
  this.forget(to);
4482
4571
  }
4483
- const mark = left ? vacatedAt(from, copies.marker(intent, to)) : void 0;
4572
+ const mark = left ? vacatedAt(from, await copies.manifest?.marker(to)) : void 0;
4484
4573
  if ((await this.meta.under(from)).some((entry) => !entry.vacated)) {
4485
4574
  await this.meta.move(
4486
4575
  from,
@@ -4494,8 +4583,8 @@ var OpfsFs = class {
4494
4583
  mark
4495
4584
  );
4496
4585
  } else if (mark) await this.meta.update(from, () => mark);
4497
- if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock, copies.remaining);
4498
- else await this.meta.update(intent, () => void 0);
4586
+ if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock);
4587
+ else await this.retireIntent(intent);
4499
4588
  this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
4500
4589
  }
4501
4590
  async finishRename(entry) {
@@ -4651,6 +4740,7 @@ var OpfsFs = class {
4651
4740
  const before = this.fileMoves;
4652
4741
  try {
4653
4742
  await this.copy(handle, dir, name2, { copies });
4743
+ await copies.manifest?.flush();
4654
4744
  } catch (err) {
4655
4745
  if (handle.kind === "directory" && this.fileMoves === before) {
4656
4746
  await this.io(dir.removeEntry(name2, { recursive: true }));
@@ -4697,7 +4787,7 @@ var OpfsFs = class {
4697
4787
  if (await this.moveChild(handle, dir, name2)) return;
4698
4788
  return this.copyBytes(handle, dir, name2, options, rest2);
4699
4789
  }
4700
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2));
4790
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2));
4701
4791
  const target = await this.io(dir.getDirectoryHandle(name2, { create: true }));
4702
4792
  this.others++;
4703
4793
  for await (const child2 of handle.values()) {
@@ -4706,6 +4796,7 @@ var OpfsFs = class {
4706
4796
  }
4707
4797
  async copyBytes(handle, dir, name2, options, rest2) {
4708
4798
  const file = await this.io(handle.getFile());
4799
+ await options.copies?.manifest?.record(await copiedEntry(handle, rest2, file));
4709
4800
  const made2 = await this.io(dir.getFileHandle(name2, { create: true }));
4710
4801
  const writable3 = await this.io(made2.createWritable());
4711
4802
  try {
@@ -4715,7 +4806,6 @@ var OpfsFs = class {
4715
4806
  await writable3.abort().catch(nothing);
4716
4807
  throw err;
4717
4808
  }
4718
- if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2, file));
4719
4809
  options.copies?.set(rest2, {
4720
4810
  before: options.copies.get(rest2)?.before ?? file.lastModified,
4721
4811
  made: made2
@@ -4857,7 +4947,7 @@ var OpfsFs = class {
4857
4947
  const entries = await this.meta.all();
4858
4948
  const carried = new Set(entries.filter((e) => !e.vacated).map((e) => e.ino));
4859
4949
  const checked = entries.filter(
4860
- (e) => !e.rename && !(e.vacated && carried.has(inodeOf(e.path)))
4950
+ (e) => !e.rename && !e.copyStamp && !(e.vacated && carried.has(inodeOf(e.path)))
4861
4951
  );
4862
4952
  const real = await this.present(
4863
4953
  checked.flatMap((e) => e.link === void 0 ? [e.path] : [e.path, parentOf4(e.path)])
@@ -10305,7 +10395,7 @@ function satisfies(version, range2) {
10305
10395
  }
10306
10396
 
10307
10397
  // src/version.ts
10308
- var KERNEL_VERSION = true ? "1.196.43" : "0.0.0-dev";
10398
+ var KERNEL_VERSION = true ? "1.196.44" : "0.0.0-dev";
10309
10399
  var OS_RELEASE = "6.0.0-slicc";
10310
10400
  function procVersion() {
10311
10401
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC