@ai-ecoverse/slicc-kernel 1.164.3 → 1.164.5

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.
@@ -1202,12 +1202,8 @@ var RemoteWatch = class {
1202
1202
  if (data.holds !== void 0) this.heldBy(data);
1203
1203
  if (data.to === this.tab && (data.keeping || data.kept)) void this.keepAsked(data);
1204
1204
  }
1205
- keepChains = /* @__PURE__ */ new Map();
1206
1205
  keepAsked(data) {
1207
- const from = data.tab;
1208
- const next3 = (this.keepChains.get(from) ?? Promise.resolve()).then(() => this.keepOne(data));
1209
- this.keepChains.set(from, next3);
1210
- return next3;
1206
+ return this.keepOne(data);
1211
1207
  }
1212
1208
  async keepOne({ tab, seq: seq2, keeping, kept }) {
1213
1209
  const from = tab;
@@ -8444,7 +8440,7 @@ function satisfies(version, range2) {
8444
8440
  }
8445
8441
 
8446
8442
  // src/version.ts
8447
- var KERNEL_VERSION = true ? "1.164.3" : "0.0.0-dev";
8443
+ var KERNEL_VERSION = true ? "1.164.5" : "0.0.0-dev";
8448
8444
  var OS_RELEASE = "6.0.0-slicc";
8449
8445
  function procVersion() {
8450
8446
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -9518,7 +9514,7 @@ var UnlinkedKeeper = class {
9518
9514
  async rm(path, options) {
9519
9515
  const target = fs.resolvePath("/", path);
9520
9516
  const kept = await keeper.peerKeep(target, false, () => keeper.removable(target, options));
9521
- if (kept.whole) return;
9517
+ if (kept.whole) return kept.undoing(async () => void 0);
9522
9518
  await kept.undoing(
9523
9519
  () => replace(target, async (gated, sealed) => {
9524
9520
  const pinned = await keeper.pin(target, gated, sealed);
@@ -9712,54 +9708,60 @@ var UnlinkedKeeper = class {
9712
9708
  void peers.ask(tab, { kept: { items: [], paths } }, PEER_RM_MS);
9713
9709
  throw fsError("EBUSY", `${target}: open in another tab that did not answer`);
9714
9710
  }
9715
- const { whole, moved: moved2 } = await this.setAside(peers, target, asked, heard);
9716
- return { whole, undoing: (op) => this.undoing(op, moved2) };
9711
+ const { whole, sends } = await this.setAside(target, asked);
9712
+ return { whole, undoing: (op) => this.undoing(op, peers, sends, heard) };
9717
9713
  }
9718
- async setAside(peers, target, asked, heard) {
9714
+ async setAside(target, asked) {
9719
9715
  const mine = this.heldWithin(target);
9720
9716
  const taken = /* @__PURE__ */ new Set();
9721
9717
  let whole = false;
9722
- const told = [];
9723
- const moved2 = [];
9724
- for (const [i, { tab, holders, paths }] of asked.entries()) {
9718
+ const sends = [];
9719
+ for (const { tab, holders, paths } of asked) {
9725
9720
  const items = [];
9726
9721
  for (const holder of holders) {
9727
9722
  const free = !mine.has(holder.path) && !taken.has(holder.path);
9728
9723
  const hidden = free ? await this.asideFor(holder.path, holder.instance) : void 0;
9729
9724
  if (hidden !== void 0) {
9730
9725
  taken.add(holder.path);
9731
- moved2.push({ tab, path: holder.path, hidden, fid: holder.fid });
9732
9726
  if (holder.path === target) whole = true;
9733
9727
  }
9734
9728
  items.push({ path: holder.path, hidden, fid: holder.fid });
9735
9729
  }
9736
- const answer2 = peers.ask(tab, { kept: { items, paths } }, PEER_RM_MS);
9737
- if (heard[i]) told.push(answer2);
9730
+ sends.push({ tab, items, paths });
9738
9731
  }
9739
- await Promise.all(told);
9740
- return { whole, moved: moved2 };
9732
+ return { whole, sends };
9741
9733
  }
9742
- async undoing(op, moved2) {
9734
+ async undoing(op, peers, sends, heard) {
9735
+ let failed3;
9736
+ let out;
9743
9737
  try {
9744
- return await op();
9738
+ out = await op();
9745
9739
  } catch (err) {
9746
- for (const { tab, path, hidden, fid } of moved2) {
9747
- const back = await this.serial(async () => {
9748
- if (await this.present(path)) return false;
9749
- return this.fs.rename(hidden, path).then(
9750
- () => true,
9751
- () => false
9752
- );
9753
- });
9754
- if (!back) continue;
9755
- void this.peers?.ask(
9756
- tab,
9757
- { kept: { items: [{ path, hidden: void 0, fid, undo: hidden }], paths: [] } },
9758
- PEER_RM_MS
9759
- );
9740
+ failed3 = err ?? new Error("failed");
9741
+ for (const send2 of sends) {
9742
+ for (const item of send2.items) {
9743
+ const { hidden, path } = item;
9744
+ if (hidden !== void 0 && await this.moveBack(hidden, path)) item.hidden = void 0;
9745
+ }
9760
9746
  }
9761
- throw err;
9762
9747
  }
9748
+ await Promise.all(
9749
+ sends.map(({ tab, items, paths }, i) => {
9750
+ const told = peers.ask(tab, { kept: { items, paths } }, PEER_RM_MS);
9751
+ return heard[i] ? told : void 0;
9752
+ })
9753
+ );
9754
+ if (failed3 !== void 0) throw failed3;
9755
+ return out;
9756
+ }
9757
+ moveBack(hidden, path) {
9758
+ return this.serial(async () => {
9759
+ if (await this.present(path)) return false;
9760
+ return this.fs.rename(hidden, path).then(
9761
+ () => true,
9762
+ () => false
9763
+ );
9764
+ });
9763
9765
  }
9764
9766
  async removable(target, options) {
9765
9767
  const st = await this.fs.lstat(target).catch(() => void 0);
@@ -13349,9 +13351,6 @@ var HeldPaths = class extends Map {
13349
13351
  this.uses.set(file, Math.max(fresh3.length, 1));
13350
13352
  this.unlinked.set(path, file);
13351
13353
  }
13352
- unkeepAt(path, hidden) {
13353
- for (const file of [...this.uses.keys()]) if (file.hidden === hidden) this.unkeep(path, file);
13354
- }
13355
13354
  unkeep(path, file) {
13356
13355
  for (const [id2, kept] of this.keptHandles) if (kept === file) this.keptHandles.delete(id2);
13357
13356
  this.uses.delete(file);
@@ -33464,52 +33463,49 @@ var Launcher = class {
33464
33463
  const gone = /* @__PURE__ */ new Set();
33465
33464
  const instance = this.unlinked.id;
33466
33465
  const ours = (hidden) => hidden.startsWith(`/${UNLINKED_DIR}/${instance}.p`) && /^[0-9a-f]+$/.test(hidden.slice(`/${UNLINKED_DIR}/${instance}.p`.length));
33467
- const open2 = (tab, paths) => {
33468
- for (const [key, release] of [...gates]) {
33466
+ const gate = async (tab, path) => {
33467
+ const release = await this.unlinked.gate.acquire(path);
33468
+ let done5 = false;
33469
+ const once2 = () => {
33470
+ if (done5) return;
33471
+ done5 = true;
33472
+ clearTimeout(timer);
33473
+ release();
33474
+ };
33475
+ const timer = setTimeout(once2, PEER_GATE_MS);
33476
+ if (gone.has(tab)) once2();
33477
+ return once2;
33478
+ };
33479
+ const open2 = async (tab, paths, all = false) => {
33480
+ for (const [key, queue] of [...gates]) {
33469
33481
  const [owner, path] = key.split("\0");
33470
33482
  if (owner !== tab || paths && !paths.includes(path)) continue;
33471
- gates.delete(key);
33472
- release();
33483
+ const taken = all ? queue.splice(0) : queue.splice(0, 1);
33484
+ if (queue.length === 0) gates.delete(key);
33485
+ for (const entry of taken) (await entry)();
33473
33486
  }
33474
33487
  };
33475
33488
  return {
33476
33489
  keeping: async (tab, paths) => {
33477
- for (const path of paths) {
33478
- if (gone.has(tab)) return;
33479
- const release = await this.unlinked.gate.acquire(path);
33490
+ if (gone.has(tab)) return;
33491
+ const mine = paths.map((path) => {
33480
33492
  const key = `${tab}\0${path}`;
33481
- let done5 = false;
33482
- const once2 = () => {
33483
- if (done5) return;
33484
- done5 = true;
33485
- clearTimeout(timer);
33486
- release();
33487
- };
33488
- const timer = setTimeout(() => {
33489
- if (gates.get(key) === once2) gates.delete(key);
33490
- once2();
33491
- }, PEER_GATE_MS);
33492
- if (gone.has(tab)) once2();
33493
- else gates.set(key, once2);
33494
- }
33493
+ const entry = gate(tab, path);
33494
+ gates.set(key, [...gates.get(key) ?? [], entry]);
33495
+ return entry;
33496
+ });
33497
+ await Promise.all(mine);
33495
33498
  },
33496
33499
  kept: async (tab, items, paths) => {
33497
- for (const { path, hidden, fid, undo } of items) {
33498
- if (undo !== void 0) this.unadopt(path, undo, fid);
33499
- else this.adoptKept(path, hidden, fid, ours);
33500
- }
33501
- open2(tab, paths);
33500
+ for (const { path, hidden, fid } of items) this.adoptKept(path, hidden, fid, ours);
33501
+ await open2(tab, paths);
33502
33502
  },
33503
33503
  left: (tab) => {
33504
33504
  gone.add(tab);
33505
- open2(tab);
33505
+ void open2(tab, void 0, true);
33506
33506
  }
33507
33507
  };
33508
33508
  }
33509
- unadopt(path, undo, fid) {
33510
- for (const holds2 of this.held) holds2.unkeepAt(path, undo);
33511
- void this.rootFs.announceHolds?.([[path, fid]], [], false);
33512
- }
33513
33509
  adoptKept(path, hidden, fid, ours) {
33514
33510
  if (hidden === void 0 || !ours(hidden)) {
33515
33511
  this.held.doubt([path]);