@ai-ecoverse/slicc-kernel 1.196.31 → 1.196.33

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.
@@ -5273,7 +5273,7 @@ function satisfies(version, range2) {
5273
5273
  }
5274
5274
 
5275
5275
  // src/version.ts
5276
- var KERNEL_VERSION = true ? "1.196.31" : "0.0.0-dev";
5276
+ var KERNEL_VERSION = true ? "1.196.33" : "0.0.0-dev";
5277
5277
  var OS_RELEASE = "6.0.0-slicc";
5278
5278
  function procVersion() {
5279
5279
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -8763,14 +8763,14 @@ function withCommandDirs(fs, names2, userDir = async () => void 0, owners = fals
8763
8763
  }
8764
8764
  return target?.path;
8765
8765
  }
8766
- const absent2 = (err) => {
8766
+ const absent3 = (err) => {
8767
8767
  if (missing2(err)) return EMPTY2;
8768
8768
  throw err;
8769
8769
  };
8770
8770
  async function content(path, err) {
8771
8771
  if (!missing2(err) || !(await linked2(path))?.isFile) throw err;
8772
8772
  const target = await redirected2(path);
8773
- return target === void 0 ? EMPTY2 : fs.readFileBuffer(target).catch(absent2);
8773
+ return target === void 0 ? EMPTY2 : fs.readFileBuffer(target).catch(absent3);
8774
8774
  }
8775
8775
  const ranged2 = rangedOps(fs);
8776
8776
  async function stat(path, real2) {
@@ -8847,7 +8847,7 @@ function withCommandDirs(fs, names2, userDir = async () => void 0, owners = fals
8847
8847
  pread: (path, offset, length2, version) => ranged2.pread(path, offset, length2, version).catch(async (err) => {
8848
8848
  const target = missing2(err) ? await redirected2(path) : void 0;
8849
8849
  if (target === void 0) throw err;
8850
- return ranged2.pread(target, offset, length2).catch(absent2);
8850
+ return ranged2.pread(target, offset, length2).catch(absent3);
8851
8851
  })
8852
8852
  } : {}
8853
8853
  };
@@ -8936,9 +8936,9 @@ function withEtcFiles(fs, files) {
8936
8936
  const text = files.get(path)?.();
8937
8937
  return text === void 0 ? void 0 : new TextEncoder().encode(text);
8938
8938
  };
8939
- const absent2 = (path) => fs.lstat(path).then(() => false, missing3);
8939
+ const absent3 = (path) => fs.lstat(path).then(() => false, missing3);
8940
8940
  const follow2 = linkFollower(fs, files);
8941
- const listedAbsent = async (path) => files.has(path) && await absent2(path) ? bytesOf7(path) : void 0;
8941
+ const listedAbsent = async (path) => files.has(path) && await absent3(path) ? bytesOf7(path) : void 0;
8942
8942
  const fallback = (path, make) => async (err) => {
8943
8943
  const at = missing3(err) ? await follow2(path) : void 0;
8944
8944
  const bytes = at === void 0 ? void 0 : await listedAbsent(at);
@@ -8950,10 +8950,10 @@ function withEtcFiles(fs, files) {
8950
8950
  const own = {
8951
8951
  stat: (path) => fs.stat(path).catch(fallback(path, (b, at) => statOf(at, b))),
8952
8952
  lstat: (path) => fs.lstat(path).catch(fallback(path, (b, at) => statOf(at, b))),
8953
- exists: async (path) => await fs.exists(path) || files.has(path) && await absent2(path),
8953
+ exists: async (path) => await fs.exists(path) || files.has(path) && await absent3(path),
8954
8954
  ...fs.createExclusive ? {
8955
8955
  createExclusive: async (path, owner) => {
8956
- if (files.has(path) && await absent2(path)) throw fsError("EEXIST", path);
8956
+ if (files.has(path) && await absent3(path)) throw fsError("EEXIST", path);
8957
8957
  return fs.createExclusive.call(
8958
8958
  fs,
8959
8959
  path,
@@ -10156,11 +10156,11 @@ var FsWatchers = class {
10156
10156
  }
10157
10157
  },
10158
10158
  rm: reshaping(async (path, options) => {
10159
- const absent2 = options?.force === true && await fs.lstat(path).then(
10159
+ const absent3 = options?.force === true && await fs.lstat(path).then(
10160
10160
  () => false,
10161
10161
  () => true
10162
10162
  );
10163
- if (absent2) return fs.rm(path, options);
10163
+ if (absent3) return fs.rm(path, options);
10164
10164
  const retire = await retiring?.(path);
10165
10165
  await removing(path, options);
10166
10166
  await retire?.();
@@ -15265,8 +15265,8 @@ var DEV_PROBES = /* @__PURE__ */ new Set([
15265
15265
  ]);
15266
15266
  async function devsOf(entry, req, result) {
15267
15267
  if (req.devs !== true || !DEV_PROBES.has(req.op)) return result;
15268
- const absent2 = result.ok ? result.kind === "json" && result.json === false : result.errno === "ENOENT";
15269
- if (!absent2) return result;
15268
+ const absent3 = result.ok ? result.kind === "json" && result.json === false : result.errno === "ENOENT";
15269
+ if (!absent3) return result;
15270
15270
  const dev = await devTarget(entry, req, entry.fs.resolvePath(entry.cwd, req.path));
15271
15271
  if (dev === void 0) return result;
15272
15272
  return result.ok ? json2({ dev }) : { ...result, dev };
@@ -28479,13 +28479,27 @@ function words2(value2) {
28479
28479
  }
28480
28480
  return [...value2];
28481
28481
  }
28482
- function variables(value2) {
28483
- if (typeof value2 !== "object" || value2 === null) return {};
28484
- return Object.fromEntries(
28485
- Object.entries(value2).filter(
28486
- ([name2, v]) => typeof v === "string" && /^[^=\0]+$/.test(name2) && !v.includes("\0")
28487
- )
28488
- );
28482
+ var SUDO_ENV_MAX = 4096;
28483
+ var SUDO_ENV_BYTES = 1024 * 1024;
28484
+ function sudoVariables(value2, term) {
28485
+ const input = typeof value2 === "object" && value2 !== null ? value2 : {};
28486
+ const env = /* @__PURE__ */ Object.create(null);
28487
+ let count3 = 0;
28488
+ let budget = SUDO_ENV_BYTES;
28489
+ const fits = (name2, text) => {
28490
+ if (++count3 > SUDO_ENV_MAX || name2.length + text.length + 2 > budget) return false;
28491
+ budget -= storedSize(name2) + storedSize(text) + 2;
28492
+ return budget >= 0;
28493
+ };
28494
+ for (const name2 in input) {
28495
+ if (!Object.hasOwn(input, name2)) continue;
28496
+ const entry = input[name2];
28497
+ if (!fits(name2, typeof entry === "string" ? entry : "")) return void 0;
28498
+ if (typeof entry === "string" && /^[^=\0]+$/.test(name2) && !entry.includes("\0"))
28499
+ env[name2] = entry;
28500
+ }
28501
+ if (term !== void 0 && env.TERM !== term && !fits("TERM", term)) return void 0;
28502
+ return env;
28489
28503
  }
28490
28504
  var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
28491
28505
  function clipboardLine(text) {
@@ -30472,12 +30486,17 @@ var WasmProcess = class _WasmProcess {
30472
30486
  async sudo(req, cancelled) {
30473
30487
  const { sudo } = this.options;
30474
30488
  if (!sudo) throw new KernelError("ENOSYS");
30489
+ const args = words2(req.args);
30490
+ const term = typeof req.term === "string" ? req.term : void 0;
30491
+ const submitted = sudoVariables(req.env, term);
30492
+ if (submitted === void 0)
30493
+ return { errno: "E2BIG", error: "sudo: the submitted environment is too large" };
30475
30494
  const call = {
30476
30495
  op: "proc-sudo",
30477
- args: words2(req.args),
30496
+ args,
30478
30497
  cwd: typeof req.cwd === "string" && req.cwd.startsWith("/") ? req.cwd : "/",
30479
- ...typeof req.term === "string" ? { term: req.term } : {},
30480
- env: variables(req.env)
30498
+ ...term !== void 0 ? { term } : {},
30499
+ env: submitted
30481
30500
  };
30482
30501
  const answer2 = await sudo(
30483
30502
  call,
@@ -33605,6 +33624,44 @@ var PrivateRename = class {
33605
33624
  }
33606
33625
  };
33607
33626
 
33627
+ // src/fs/rename-cleanup.ts
33628
+ function cleanupId(handle) {
33629
+ return handle.getUniqueId?.();
33630
+ }
33631
+ async function copiedEntry(handle, path, file) {
33632
+ const id2 = await cleanupId(handle);
33633
+ return {
33634
+ path,
33635
+ kind: handle.kind,
33636
+ ...id2 !== void 0 && { id: id2 },
33637
+ ...file && { size: file.size, mtime: file.lastModified }
33638
+ };
33639
+ }
33640
+ function absent(err) {
33641
+ return err.name === "NotFoundError";
33642
+ }
33643
+ async function removeOne(parent, name2, rest2, entries) {
33644
+ const entry = entries.get(rest2);
33645
+ if (!entry) return;
33646
+ try {
33647
+ const handle = entry.kind === "file" ? await parent.getFileHandle(name2) : await parent.getDirectoryHandle(name2);
33648
+ if (entry.id !== void 0 && await cleanupId(handle) !== entry.id) return;
33649
+ if (handle.kind === "file") {
33650
+ const file = await handle.getFile();
33651
+ if (file.lastModified !== entry.mtime || file.size !== entry.size) return;
33652
+ } else {
33653
+ for await (const child2 of handle.keys())
33654
+ await removeOne(handle, child2, rest2 + "/" + child2, entries);
33655
+ }
33656
+ await parent.removeEntry(name2);
33657
+ } catch (err) {
33658
+ if (!absent(err) && err.name !== "TypeMismatchError") throw err;
33659
+ }
33660
+ }
33661
+ function removeCopied(parent, name2, manifest) {
33662
+ return removeOne(parent, name2, "", new Map(manifest.map((entry) => [entry.path, entry])));
33663
+ }
33664
+
33608
33665
  // src/fs/opfs.ts
33609
33666
  var S_IFDIR2 = 16384;
33610
33667
  var S_IFREG3 = 32768;
@@ -33649,6 +33706,9 @@ var PRIVATE_COPY = /* @__PURE__ */ Symbol("private-copy");
33649
33706
  var PRIVATE_NATIVE = /* @__PURE__ */ Symbol("private-native");
33650
33707
  var ACK_SAMPLES = 4096;
33651
33708
  var INTENT_POLL_MS = 5;
33709
+ var Copies = class extends Map {
33710
+ remaining = [];
33711
+ };
33652
33712
  function needsCopy(handle, swap) {
33653
33713
  return swap || handle.kind === "directory" && !movable(handle);
33654
33714
  }
@@ -34165,6 +34225,7 @@ var OpfsFs = class {
34165
34225
  return view(this, { rejectLinks: true });
34166
34226
  }
34167
34227
  refuse(path, holding = false) {
34228
+ this.reserveWrite(path, holding);
34168
34229
  if (isProtected(this.guarded, path) || holding && holdsProtected(this.guarded, path)) {
34169
34230
  throw fsError("EROFS", path);
34170
34231
  }
@@ -34376,6 +34437,7 @@ var OpfsFs = class {
34376
34437
  return this.lookups - seen.op < lookups && performance.now() - seen.at < GLANCE_CAP_MS;
34377
34438
  }
34378
34439
  async handle(path) {
34440
+ if (this.sourceReservation(path)) throw fsError("ENOENT", path);
34379
34441
  this.lookups++;
34380
34442
  if (split2(path).length === 0) return this.root;
34381
34443
  const cached = this.files.get(path);
@@ -35059,6 +35121,9 @@ var OpfsFs = class {
35059
35121
  const name2 = baseOf4(link2.path);
35060
35122
  if (!children3.has(name2)) children3.set(name2, link2);
35061
35123
  }
35124
+ for (const source of this.pendingSources.values()) {
35125
+ if (parentOf11(source) === found.path) children3.delete(baseOf4(source));
35126
+ }
35062
35127
  for (const backup of this.hiddenBackups) {
35063
35128
  if (parentOf11(backup) === found.path) children3.delete(baseOf4(backup));
35064
35129
  }
@@ -35238,7 +35303,7 @@ var OpfsFs = class {
35238
35303
  );
35239
35304
  }
35240
35305
  async removalParentId(path) {
35241
- const parent = await this.lstat(parentOf11(path));
35306
+ const parent = await PLAIN3.lstat.call(this, parentOf11(path));
35242
35307
  return parent.isDirectory ? `${parent.dev ?? 0}:${parent.ino}` : void 0;
35243
35308
  }
35244
35309
  async removePhysical(path, recursive) {
@@ -35397,7 +35462,7 @@ var OpfsFs = class {
35397
35462
  return this.privateCopy(source, parent, destination, target?.handle, moving);
35398
35463
  const place = async () => {
35399
35464
  this.forget(destination);
35400
- const copies = /* @__PURE__ */ new Map();
35465
+ const copies = new Copies();
35401
35466
  const root = { ino: inodeOf(source.path), ...moving };
35402
35467
  const owned4 = lock ? { lock } : {};
35403
35468
  hooks.notify?.();
@@ -35416,18 +35481,23 @@ var OpfsFs = class {
35416
35481
  if (first) await this.rollBack(staged2, source.path, [first, second]);
35417
35482
  throw err;
35418
35483
  });
35419
- if (swap) await this.rm(destination);
35484
+ if (swap) await PLAIN3.rm.call(this, destination);
35420
35485
  if (second) await this.intend({ from: staged2, to: destination, root, ...owned4 }, second);
35421
35486
  await this.meta.move(source.path, destination, carry, left);
35422
35487
  this.movePending(source.path, destination);
35423
- if (!moved3) await this.removePhysical(source.path, true);
35424
- if (first) await this.meta.update(first, () => void 0);
35488
+ if (!moved3 && first)
35489
+ await this.releaseSource(first, source.path, destination, left.ino, lock, copies.remaining);
35490
+ else if (first) await this.meta.update(first, () => void 0);
35425
35491
  if (swap) {
35426
35492
  const hidden = await dir.getDirectoryHandle(staging);
35493
+ copies.remaining = [];
35427
35494
  const placed = await this.place(hidden, dir, name2, copies, copying);
35428
- if (!placed) await dir.removeEntry(staging, { recursive: true });
35495
+ if (!placed && second) {
35496
+ const mark = vacatedAt(staged2);
35497
+ await this.meta.update(staged2, () => mark);
35498
+ await this.releaseSource(second, staged2, destination, mark.ino, lock, copies.remaining);
35499
+ } else if (second) await this.meta.update(second, () => void 0);
35429
35500
  }
35430
- if (second) await this.meta.update(second, () => void 0);
35431
35501
  await this.restamp(destination, copies);
35432
35502
  this.changed(source.path, destination);
35433
35503
  this.touch(Date.now(), parentOf11(source.path), parent.path);
@@ -35646,6 +35716,10 @@ var OpfsFs = class {
35646
35716
  const left = (await this.meta.under(RENAMES2)).filter((entry) => entry.rename?.lock === move.lock).sort(byIntent);
35647
35717
  for (const entry of left) await this.finishRename(entry);
35648
35718
  });
35719
+ for (const entry of await this.meta.under(RENAMES2)) {
35720
+ if (entry.rename?.lock === move.lock && entry.rename.sourceCleanup !== void 0)
35721
+ this.syncSourceReservation(entry.path, entry.rename.from);
35722
+ }
35649
35723
  this.peerMoves.delete(move.lock);
35650
35724
  for (const [from, to] of move.trees) {
35651
35725
  this.forget(from);
@@ -35673,9 +35747,10 @@ var OpfsFs = class {
35673
35747
  }
35674
35748
  aloneCalls = 0;
35675
35749
  aloneDrain;
35676
- async alonePlain(inner, args) {
35750
+ async alonePlain(name2, inner, args) {
35677
35751
  this.aloneCalls++;
35678
35752
  try {
35753
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
35679
35754
  return await inner.apply(this, args);
35680
35755
  } finally {
35681
35756
  this.aloneCalls--;
@@ -35706,6 +35781,7 @@ var OpfsFs = class {
35706
35781
  for (const at of paths) checked.push(...await this.peerSettled(at, listing, removing));
35707
35782
  if (!checked.some((at) => this.peerAt(at, listing, removing))) break;
35708
35783
  }
35784
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
35709
35785
  const busy = { paths: checked, removing, release: () => void 0 };
35710
35786
  const done4 = () => {
35711
35787
  this.inflight.delete(busy);
@@ -35736,6 +35812,7 @@ var OpfsFs = class {
35736
35812
  let sessionOwnsAdmission = false;
35737
35813
  let native = false;
35738
35814
  try {
35815
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
35739
35816
  if (name2 === "writeSession") {
35740
35817
  const session = await inner.apply(inside2, args);
35741
35818
  sessionOwnsAdmission = true;
@@ -35794,7 +35871,7 @@ var OpfsFs = class {
35794
35871
  const handle = source.handle;
35795
35872
  const dir = parent.handle;
35796
35873
  const name2 = baseOf4(to);
35797
- const copies = /* @__PURE__ */ new Map();
35874
+ const copies = new Copies();
35798
35875
  const [entry] = await this.meta.get([source.path]);
35799
35876
  const root = { ino: occupied(entry).ino ?? inodeOf(source.path), ...owner };
35800
35877
  if (target?.kind === "directory" && movable(target) && movable(handle)) {
@@ -35847,16 +35924,19 @@ var OpfsFs = class {
35847
35924
  async commitPrivateCopy(from, to, root, intent, copies, emptyBackup) {
35848
35925
  const { ino, ...owner } = root;
35849
35926
  const entries = await this.meta.get([from, to]);
35850
- if (!entries[0]?.vacated || entries[1]?.ino !== ino) {
35927
+ let mark = entries[0];
35928
+ if (!mark?.vacated || entries[1]?.ino !== ino) {
35929
+ mark = vacatedAt(from);
35851
35930
  await this.meta.move(
35852
35931
  from,
35853
35932
  to,
35854
35933
  (entry) => ({ ...occupied(entry), ...owner, ino, path: to, ctimeMs: Date.now() }),
35855
- vacatedAt(from)
35934
+ mark
35856
35935
  );
35857
35936
  }
35937
+ if (!emptyBackup)
35938
+ await this.releaseSource(intent, from, to, mark.ino, void 0, copies.remaining);
35858
35939
  this.movePending(from, to);
35859
- if (!emptyBackup) await this.removePhysical(from, true);
35860
35940
  await this.restamp(to, copies);
35861
35941
  this.changed(from, to);
35862
35942
  this.touch(Date.now(), parentOf11(from), parentOf11(to));
@@ -35864,16 +35944,102 @@ var OpfsFs = class {
35864
35944
  await this.intend({ from, to, root, emptyBackup, cleanupOnly: true }, intent);
35865
35945
  return this.cleanSwapIntent(intent, emptyBackup);
35866
35946
  }
35867
- await this.meta.update(intent, () => void 0);
35947
+ }
35948
+ async sourceId(path) {
35949
+ const [dir, name2] = await this.parent(path);
35950
+ const parent = await this.dir(dir);
35951
+ let handle;
35952
+ try {
35953
+ handle = await this.child(parent, name2, "directory");
35954
+ } catch (err) {
35955
+ if (err.name !== "TypeMismatchError") throw err;
35956
+ handle = await this.child(parent, name2, "file");
35957
+ }
35958
+ return cleanupId(handle);
35959
+ }
35960
+ async releaseSource(intent, from, to, id2, lock, copiedEntries) {
35961
+ this.syncSourceReservation(intent, from);
35962
+ const physicalSource = copiedEntries?.find((entry) => entry.path === "")?.id;
35963
+ await this.intend(
35964
+ {
35965
+ from,
35966
+ to,
35967
+ sourceCleanup: id2,
35968
+ ...lock && { lock },
35969
+ ...physicalSource && { physicalSource },
35970
+ ...copiedEntries && { copiedEntries }
35971
+ },
35972
+ intent
35973
+ );
35974
+ await this.cleanSource(intent, from, id2);
35975
+ }
35976
+ async cleanSource(intent, from, id2) {
35977
+ const remove = async () => {
35978
+ const [current] = await this.meta.under(intent);
35979
+ if (current?.rename?.sourceCleanup === id2) {
35980
+ const [reservation] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [from]);
35981
+ if (reservation?.vacated && reservation.ino === id2) {
35982
+ try {
35983
+ const expected = current.rename.physicalSource;
35984
+ if (expected === void 0 || await this.sourceId(from) === expected) {
35985
+ const [dir, name2] = await this.parent(from);
35986
+ await this.inDir(
35987
+ dir,
35988
+ (parent) => current.rename?.copiedEntries ? removeCopied(parent, name2, current.rename.copiedEntries) : parent.removeEntry(name2)
35989
+ );
35990
+ }
35991
+ } catch (err) {
35992
+ if (!missing5(err) && err.name !== "NotFoundError") return;
35993
+ }
35994
+ await this.meta.update(
35995
+ from,
35996
+ (current2) => current2?.vacated && current2.ino === reservation.ino ? vacatedAt(from) : current2
35997
+ );
35998
+ }
35999
+ await this.meta.update(intent, () => void 0);
36000
+ }
36001
+ this.syncSourceReservation(intent);
36002
+ };
36003
+ this.syncSourceReservation(intent, from);
36004
+ if (this.locks) await this.locks.request(this.lockPrefix + intent, remove);
36005
+ else await remove();
35868
36006
  }
35869
36007
  async duplicate(handle, parent, name2, copies, rest2) {
35870
36008
  if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
36009
+ copies.remaining.push(await copiedEntry(handle, rest2));
35871
36010
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
35872
36011
  this.others++;
35873
36012
  for await (const child2 of handle.values())
35874
36013
  await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name);
35875
36014
  }
35876
36015
  hiddenBackups = /* @__PURE__ */ new Set();
36016
+ pendingSources = /* @__PURE__ */ new Map();
36017
+ syncSourceReservation(intent, from) {
36018
+ const path = from ?? this.pendingSources.get(intent);
36019
+ if (from === void 0) this.pendingSources.delete(intent);
36020
+ else this.pendingSources.set(intent, from);
36021
+ if (path) this.forget(path);
36022
+ }
36023
+ async reservedOp(name2, args) {
36024
+ const touched = name2 === "symlink" ? args.slice(1, 2) : args.slice(0, PAIRED.has(name2) ? 2 : 1);
36025
+ for (const [intent, source] of this.pendingSources) {
36026
+ const [entry] = await this.meta.under(intent);
36027
+ if (entry?.rename?.sourceCleanup === void 0) this.syncSourceReservation(intent);
36028
+ else if (!READS.includes(name2) && touched.some((p) => {
36029
+ const at = normalizePath(p);
36030
+ return within11(at, source) || REMOVALS2.has(name2) && (at === "/" || within11(source, at));
36031
+ }))
36032
+ throw fsError("EBUSY", source);
36033
+ }
36034
+ }
36035
+ sourceReservation(path, ancestor = false) {
36036
+ for (const source of this.pendingSources.values())
36037
+ if (within11(path, source) || ancestor && within11(source, path)) return source;
36038
+ return void 0;
36039
+ }
36040
+ reserveWrite(path, ancestor = false) {
36041
+ if (this.sourceReservation(path, ancestor)) throw fsError("EBUSY", path);
36042
+ }
35877
36043
  renamingDirs = /* @__PURE__ */ new Set();
35878
36044
  intents = 0;
35879
36045
  async intend(rename, at = `${RENAMES2}/${crypto.randomUUID()}`) {
@@ -35934,7 +36100,7 @@ var OpfsFs = class {
35934
36100
  }
35935
36101
  if (!left) {
35936
36102
  if ((await this.swapEntry(to))?.kind !== "directory") throw fsError("EIO", to);
35937
- return this.commitPrivateCopy(from, to, root, intent, /* @__PURE__ */ new Map(), backup);
36103
+ return this.commitPrivateCopy(from, to, root, intent, new Copies(), backup);
35938
36104
  }
35939
36105
  const staged2 = await this.swapEntry(backup);
35940
36106
  if (staged2) {
@@ -35947,10 +36113,72 @@ var OpfsFs = class {
35947
36113
  }
35948
36114
  await this.dropSwapIntent(intent, backup);
35949
36115
  }
36116
+ async resumeCopiedTree(intent, rename) {
36117
+ const { from, to, root } = rename;
36118
+ const left = await this.real(from);
36119
+ if (left && root) {
36120
+ const [mark, placed] = await this.meta.get([from, to]);
36121
+ if (mark?.vacated && mark.ino !== void 0 && placed?.ino === root.ino)
36122
+ return this.releaseSource(intent, from, to, mark.ino, rename.lock);
36123
+ }
36124
+ if (rename.privateCopy) {
36125
+ if (left) {
36126
+ const src = await this.locate(from, false);
36127
+ const dir = await this.locate(parentOf11(to), true);
36128
+ const copies = new Copies();
36129
+ await this.duplicate(
36130
+ src.handle,
36131
+ dir.handle,
36132
+ baseOf4(to),
36133
+ copies,
36134
+ ""
36135
+ );
36136
+ await this.commitPrivateCopy(from, to, root ?? { ino: inodeOf(from) }, intent, copies);
36137
+ } else await this.meta.update(intent, () => void 0);
36138
+ return;
36139
+ }
36140
+ await this.resumeCoordinatedCopy(intent, rename, left);
36141
+ }
36142
+ async resumeCoordinatedCopy(intent, rename, left) {
36143
+ const { from, to, replace, root } = rename;
36144
+ const copies = new Copies();
36145
+ if (left && replace && await this.real(to))
36146
+ await PLAIN3.rm.call(this, to, { recursive: true });
36147
+ if (left) {
36148
+ const source = await this.locate(from, false);
36149
+ const target = await this.locate(parentOf11(to), true);
36150
+ await this.copy(
36151
+ source.handle,
36152
+ target.handle,
36153
+ baseOf4(to),
36154
+ { copies }
36155
+ );
36156
+ this.forget(from);
36157
+ this.forget(to);
36158
+ }
36159
+ const mark = left ? vacatedAt(from) : void 0;
36160
+ if ((await this.meta.under(from)).some((entry) => !entry.vacated)) {
36161
+ await this.meta.move(
36162
+ from,
36163
+ to,
36164
+ (moved3) => ({
36165
+ ...occupied(moved3),
36166
+ ...root,
36167
+ ino: occupied(moved3).ino ?? root?.ino ?? inodeOf(from),
36168
+ path: to
36169
+ }),
36170
+ mark
36171
+ );
36172
+ } else if (mark) await this.meta.update(from, () => mark);
36173
+ if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock, copies.remaining);
36174
+ else await this.meta.update(intent, () => void 0);
36175
+ this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36176
+ }
35950
36177
  async finishRename(entry) {
35951
36178
  const [current] = await this.meta.under(entry.path);
35952
36179
  if (current?.rename === void 0) return;
35953
- const { from, to, replace, root, emptyBackup, cleanupOnly } = current.rename;
36180
+ const { from, to, root, emptyBackup, cleanupOnly, sourceCleanup } = current.rename;
36181
+ if (sourceCleanup !== void 0) return this.cleanSource(entry.path, from, sourceCleanup);
35954
36182
  if (emptyBackup) this.hiddenBackups.add(emptyBackup);
35955
36183
  if (emptyBackup && cleanupOnly) return this.cleanSwapIntent(entry.path, emptyBackup);
35956
36184
  const { promise, resolve: resolve2 } = Promise.withResolvers();
@@ -35970,59 +36198,7 @@ var OpfsFs = class {
35970
36198
  );
35971
36199
  return;
35972
36200
  }
35973
- const left = await this.real(from);
35974
- if (current.rename.privateCopy) {
35975
- if (left) {
35976
- const src = await this.locate(from, false);
35977
- const dir = await this.locate(parentOf11(to), true);
35978
- const copies = /* @__PURE__ */ new Map();
35979
- await this.duplicate(
35980
- src.handle,
35981
- dir.handle,
35982
- baseOf4(to),
35983
- copies,
35984
- ""
35985
- );
35986
- await this.commitPrivateCopy(
35987
- from,
35988
- to,
35989
- root ?? { ino: inodeOf(from) },
35990
- entry.path,
35991
- copies
35992
- );
35993
- } else await this.meta.update(entry.path, () => void 0);
35994
- return;
35995
- }
35996
- if (left && replace && await this.real(to))
35997
- await PLAIN3.rm.call(this, to, { recursive: true });
35998
- if (left) {
35999
- const source = await this.locate(from, false);
36000
- const target = await this.locate(parentOf11(to), true);
36001
- await this.copy(
36002
- source.handle,
36003
- target.handle,
36004
- baseOf4(to)
36005
- );
36006
- const [dir, name2] = await this.parent(from);
36007
- await this.inDir(dir, (parent) => parent.removeEntry(name2, { recursive: true }));
36008
- this.forget(from);
36009
- this.forget(to);
36010
- }
36011
- if ((await this.meta.under(from)).some((entry2) => !entry2.vacated)) {
36012
- await this.meta.move(
36013
- from,
36014
- to,
36015
- (moved3) => ({
36016
- ...occupied(moved3),
36017
- ...root,
36018
- ino: occupied(moved3).ino ?? root?.ino ?? inodeOf(from),
36019
- path: to
36020
- }),
36021
- void 0
36022
- );
36023
- }
36024
- await this.meta.update(entry.path, () => void 0);
36025
- this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36201
+ await this.resumeCopiedTree(entry.path, current.rename);
36026
36202
  } finally {
36027
36203
  this.renamingDirs.delete(barrier);
36028
36204
  resolve2();
@@ -36197,6 +36373,7 @@ var OpfsFs = class {
36197
36373
  if (await this.moveChild(handle, dir, name2)) return;
36198
36374
  return this.copyBytes(handle, dir, name2, options, rest2);
36199
36375
  }
36376
+ if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2));
36200
36377
  const target = await this.io(dir.getDirectoryHandle(name2, { create: true }));
36201
36378
  this.others++;
36202
36379
  for await (const child2 of handle.values()) {
@@ -36214,6 +36391,7 @@ var OpfsFs = class {
36214
36391
  await writable3.abort().catch(nothing2);
36215
36392
  throw err;
36216
36393
  }
36394
+ if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2, file));
36217
36395
  options.copies?.set(rest2, {
36218
36396
  before: options.copies.get(rest2)?.before ?? file.lastModified,
36219
36397
  made: made2
@@ -36395,6 +36573,7 @@ function byIntent(a, b) {
36395
36573
  return a.rename.at - b.rename.at;
36396
36574
  }
36397
36575
  var PLAIN3 = {
36576
+ lstat: OpfsFs.prototype.lstat,
36398
36577
  rm: OpfsFs.prototype.rm,
36399
36578
  realpath: OpfsFs.prototype.realpath
36400
36579
  };
@@ -36435,7 +36614,7 @@ var WRITES = [
36435
36614
  proto.createExclusive = function(...args) {
36436
36615
  if (this.privateRename) return this.privateOp("createExclusive", args, inner);
36437
36616
  if (this.amongPeers()) return this.peerOp("createExclusive", args, inner);
36438
- return this.alonePlain(inner, args);
36617
+ return this.alonePlain("createExclusive", inner, args);
36439
36618
  };
36440
36619
  }
36441
36620
  for (const [names2, op] of [
@@ -36451,7 +36630,7 @@ for (const [names2, op] of [
36451
36630
  if (op === "read") await this.settledRename(args[0]);
36452
36631
  if (this.amongPeers() || name2 === "writeSession")
36453
36632
  return await this.peerOp(name2, args, inner);
36454
- return await this.alonePlain(inner, args);
36633
+ return await this.alonePlain(name2, inner, args);
36455
36634
  } catch (err) {
36456
36635
  throw translate(err, String(args[0]), op, false);
36457
36636
  }
@@ -36461,13 +36640,13 @@ for (const [names2, op] of [
36461
36640
 
36462
36641
  // src/mount/medium.ts
36463
36642
  var EMPTY_ROOT = { kind: "directory", size: 0, mtime: 0, mode: 16877 };
36464
- var absent = () => fsError2("ENOMEDIUM", "No medium found");
36643
+ var absent2 = () => fsError2("ENOMEDIUM", "No medium found");
36465
36644
  function mediumSlot(lost, onLost) {
36466
36645
  let current;
36467
36646
  function wrap(pick) {
36468
36647
  return async (...args) => {
36469
36648
  const medium = current;
36470
- if (!medium) throw absent();
36649
+ if (!medium) throw absent2();
36471
36650
  try {
36472
36651
  return await pick(medium.handlers)(...args);
36473
36652
  } catch (err) {
@@ -36476,7 +36655,7 @@ function mediumSlot(lost, onLost) {
36476
36655
  current = void 0;
36477
36656
  onLost(medium.key);
36478
36657
  }
36479
- throw absent();
36658
+ throw absent2();
36480
36659
  }
36481
36660
  };
36482
36661
  }
@@ -45307,6 +45486,9 @@ var SqliteHandle = class _SqliteHandle {
45307
45486
  this.id = id2;
45308
45487
  this.name = name2;
45309
45488
  }
45489
+ async getUniqueId() {
45490
+ return String(this.id);
45491
+ }
45310
45492
  async isSameEntry(other) {
45311
45493
  return other instanceof _SqliteHandle && other.files === this.files && other.id === this.id;
45312
45494
  }
@@ -45553,7 +45735,19 @@ var Chunks = class {
45553
45735
  this.size = size;
45554
45736
  }
45555
45737
  };
45738
+ var identities = /* @__PURE__ */ new WeakMap();
45739
+ function entryId(handle) {
45740
+ let id2 = identities.get(handle);
45741
+ if (!id2) {
45742
+ id2 = crypto.randomUUID();
45743
+ identities.set(handle, id2);
45744
+ }
45745
+ return id2;
45746
+ }
45556
45747
  var MemoryFile = class {
45748
+ async getUniqueId() {
45749
+ return entryId(this);
45750
+ }
45557
45751
  kind = "file";
45558
45752
  name;
45559
45753
  parent;
@@ -45639,6 +45833,9 @@ var MemoryFile = class {
45639
45833
  }
45640
45834
  };
45641
45835
  var MemoryDirectory = class _MemoryDirectory {
45836
+ async getUniqueId() {
45837
+ return entryId(this);
45838
+ }
45642
45839
  kind = "directory";
45643
45840
  name;
45644
45841
  parent;