@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.
package/dist/node.js CHANGED
@@ -7789,7 +7789,7 @@ function satisfies(version, range2) {
7789
7789
  }
7790
7790
 
7791
7791
  // src/version.ts
7792
- var KERNEL_VERSION = true ? "1.196.31" : "0.0.0-dev";
7792
+ var KERNEL_VERSION = true ? "1.196.33" : "0.0.0-dev";
7793
7793
  var OS_RELEASE = "6.0.0-slicc";
7794
7794
  function procVersion() {
7795
7795
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -11095,14 +11095,14 @@ function withCommandDirs(fs, names2, userDir = async () => void 0, owners = fals
11095
11095
  }
11096
11096
  return target?.path;
11097
11097
  }
11098
- const absent2 = (err) => {
11098
+ const absent3 = (err) => {
11099
11099
  if (missing3(err)) return EMPTY2;
11100
11100
  throw err;
11101
11101
  };
11102
11102
  async function content(path, err) {
11103
11103
  if (!missing3(err) || !(await linked2(path))?.isFile) throw err;
11104
11104
  const target = await redirected2(path);
11105
- return target === void 0 ? EMPTY2 : fs.readFileBuffer(target).catch(absent2);
11105
+ return target === void 0 ? EMPTY2 : fs.readFileBuffer(target).catch(absent3);
11106
11106
  }
11107
11107
  const ranged2 = rangedOps(fs);
11108
11108
  async function stat(path, real) {
@@ -11179,7 +11179,7 @@ function withCommandDirs(fs, names2, userDir = async () => void 0, owners = fals
11179
11179
  pread: (path, offset, length2, version) => ranged2.pread(path, offset, length2, version).catch(async (err) => {
11180
11180
  const target = missing3(err) ? await redirected2(path) : void 0;
11181
11181
  if (target === void 0) throw err;
11182
- return ranged2.pread(target, offset, length2).catch(absent2);
11182
+ return ranged2.pread(target, offset, length2).catch(absent3);
11183
11183
  })
11184
11184
  } : {}
11185
11185
  };
@@ -11244,9 +11244,9 @@ function withEtcFiles(fs, files) {
11244
11244
  const text = files.get(path)?.();
11245
11245
  return text === void 0 ? void 0 : new TextEncoder().encode(text);
11246
11246
  };
11247
- const absent2 = (path) => fs.lstat(path).then(() => false, missing4);
11247
+ const absent3 = (path) => fs.lstat(path).then(() => false, missing4);
11248
11248
  const follow2 = linkFollower(fs, files);
11249
- const listedAbsent = async (path) => files.has(path) && await absent2(path) ? bytesOf5(path) : void 0;
11249
+ const listedAbsent = async (path) => files.has(path) && await absent3(path) ? bytesOf5(path) : void 0;
11250
11250
  const fallback = (path, make) => async (err) => {
11251
11251
  const at = missing4(err) ? await follow2(path) : void 0;
11252
11252
  const bytes = at === void 0 ? void 0 : await listedAbsent(at);
@@ -11258,10 +11258,10 @@ function withEtcFiles(fs, files) {
11258
11258
  const own = {
11259
11259
  stat: (path) => fs.stat(path).catch(fallback(path, (b, at) => statOf(at, b))),
11260
11260
  lstat: (path) => fs.lstat(path).catch(fallback(path, (b, at) => statOf(at, b))),
11261
- exists: async (path) => await fs.exists(path) || files.has(path) && await absent2(path),
11261
+ exists: async (path) => await fs.exists(path) || files.has(path) && await absent3(path),
11262
11262
  ...fs.createExclusive ? {
11263
11263
  createExclusive: async (path, owner) => {
11264
- if (files.has(path) && await absent2(path)) throw fsError("EEXIST", path);
11264
+ if (files.has(path) && await absent3(path)) throw fsError("EEXIST", path);
11265
11265
  return fs.createExclusive.call(
11266
11266
  fs,
11267
11267
  path,
@@ -12464,11 +12464,11 @@ var FsWatchers = class {
12464
12464
  }
12465
12465
  },
12466
12466
  rm: reshaping(async (path, options) => {
12467
- const absent2 = options?.force === true && await fs.lstat(path).then(
12467
+ const absent3 = options?.force === true && await fs.lstat(path).then(
12468
12468
  () => false,
12469
12469
  () => true
12470
12470
  );
12471
- if (absent2) return fs.rm(path, options);
12471
+ if (absent3) return fs.rm(path, options);
12472
12472
  const retire = await retiring?.(path);
12473
12473
  await removing(path, options);
12474
12474
  await retire?.();
@@ -16044,8 +16044,8 @@ var DEV_PROBES = /* @__PURE__ */ new Set([
16044
16044
  ]);
16045
16045
  async function devsOf(entry, req, result) {
16046
16046
  if (req.devs !== true || !DEV_PROBES.has(req.op)) return result;
16047
- const absent2 = result.ok ? result.kind === "json" && result.json === false : result.errno === "ENOENT";
16048
- if (!absent2) return result;
16047
+ const absent3 = result.ok ? result.kind === "json" && result.json === false : result.errno === "ENOENT";
16048
+ if (!absent3) return result;
16049
16049
  const dev = await devTarget(entry, req, entry.fs.resolvePath(entry.cwd, req.path));
16050
16050
  if (dev === void 0) return result;
16051
16051
  return result.ok ? json2({ dev }) : { ...result, dev };
@@ -28806,13 +28806,27 @@ function words2(value2) {
28806
28806
  }
28807
28807
  return [...value2];
28808
28808
  }
28809
- function variables(value2) {
28810
- if (typeof value2 !== "object" || value2 === null) return {};
28811
- return Object.fromEntries(
28812
- Object.entries(value2).filter(
28813
- ([name2, v]) => typeof v === "string" && /^[^=\0]+$/.test(name2) && !v.includes("\0")
28814
- )
28815
- );
28809
+ var SUDO_ENV_MAX = 4096;
28810
+ var SUDO_ENV_BYTES = 1024 * 1024;
28811
+ function sudoVariables(value2, term) {
28812
+ const input = typeof value2 === "object" && value2 !== null ? value2 : {};
28813
+ const env = /* @__PURE__ */ Object.create(null);
28814
+ let count3 = 0;
28815
+ let budget = SUDO_ENV_BYTES;
28816
+ const fits = (name2, text) => {
28817
+ if (++count3 > SUDO_ENV_MAX || name2.length + text.length + 2 > budget) return false;
28818
+ budget -= storedSize(name2) + storedSize(text) + 2;
28819
+ return budget >= 0;
28820
+ };
28821
+ for (const name2 in input) {
28822
+ if (!Object.hasOwn(input, name2)) continue;
28823
+ const entry = input[name2];
28824
+ if (!fits(name2, typeof entry === "string" ? entry : "")) return void 0;
28825
+ if (typeof entry === "string" && /^[^=\0]+$/.test(name2) && !entry.includes("\0"))
28826
+ env[name2] = entry;
28827
+ }
28828
+ if (term !== void 0 && env.TERM !== term && !fits("TERM", term)) return void 0;
28829
+ return env;
28816
28830
  }
28817
28831
  var ESCAPES = { " ": "\\t", "\n": "\\n", "\r": "\\r" };
28818
28832
  function clipboardLine(text) {
@@ -30799,12 +30813,17 @@ var WasmProcess = class _WasmProcess {
30799
30813
  async sudo(req, cancelled) {
30800
30814
  const { sudo } = this.options;
30801
30815
  if (!sudo) throw new KernelError("ENOSYS");
30816
+ const args = words2(req.args);
30817
+ const term = typeof req.term === "string" ? req.term : void 0;
30818
+ const submitted = sudoVariables(req.env, term);
30819
+ if (submitted === void 0)
30820
+ return { errno: "E2BIG", error: "sudo: the submitted environment is too large" };
30802
30821
  const call = {
30803
30822
  op: "proc-sudo",
30804
- args: words2(req.args),
30823
+ args,
30805
30824
  cwd: typeof req.cwd === "string" && req.cwd.startsWith("/") ? req.cwd : "/",
30806
- ...typeof req.term === "string" ? { term: req.term } : {},
30807
- env: variables(req.env)
30825
+ ...term !== void 0 ? { term } : {},
30826
+ env: submitted
30808
30827
  };
30809
30828
  const answer2 = await sudo(
30810
30829
  call,
@@ -33933,6 +33952,44 @@ var PrivateRename = class {
33933
33952
  }
33934
33953
  };
33935
33954
 
33955
+ // src/fs/rename-cleanup.ts
33956
+ function cleanupId(handle) {
33957
+ return handle.getUniqueId?.();
33958
+ }
33959
+ async function copiedEntry(handle, path, file) {
33960
+ const id2 = await cleanupId(handle);
33961
+ return {
33962
+ path,
33963
+ kind: handle.kind,
33964
+ ...id2 !== void 0 && { id: id2 },
33965
+ ...file && { size: file.size, mtime: file.lastModified }
33966
+ };
33967
+ }
33968
+ function absent(err) {
33969
+ return err.name === "NotFoundError";
33970
+ }
33971
+ async function removeOne(parent, name2, rest2, entries) {
33972
+ const entry = entries.get(rest2);
33973
+ if (!entry) return;
33974
+ try {
33975
+ const handle = entry.kind === "file" ? await parent.getFileHandle(name2) : await parent.getDirectoryHandle(name2);
33976
+ if (entry.id !== void 0 && await cleanupId(handle) !== entry.id) return;
33977
+ if (handle.kind === "file") {
33978
+ const file = await handle.getFile();
33979
+ if (file.lastModified !== entry.mtime || file.size !== entry.size) return;
33980
+ } else {
33981
+ for await (const child2 of handle.keys())
33982
+ await removeOne(handle, child2, rest2 + "/" + child2, entries);
33983
+ }
33984
+ await parent.removeEntry(name2);
33985
+ } catch (err) {
33986
+ if (!absent(err) && err.name !== "TypeMismatchError") throw err;
33987
+ }
33988
+ }
33989
+ function removeCopied(parent, name2, manifest) {
33990
+ return removeOne(parent, name2, "", new Map(manifest.map((entry) => [entry.path, entry])));
33991
+ }
33992
+
33936
33993
  // src/fs/opfs.ts
33937
33994
  var S_IFDIR2 = 16384;
33938
33995
  var S_IFREG3 = 32768;
@@ -33977,6 +34034,9 @@ var PRIVATE_COPY = /* @__PURE__ */ Symbol("private-copy");
33977
34034
  var PRIVATE_NATIVE = /* @__PURE__ */ Symbol("private-native");
33978
34035
  var ACK_SAMPLES = 4096;
33979
34036
  var INTENT_POLL_MS = 5;
34037
+ var Copies = class extends Map {
34038
+ remaining = [];
34039
+ };
33980
34040
  function needsCopy(handle, swap) {
33981
34041
  return swap || handle.kind === "directory" && !movable(handle);
33982
34042
  }
@@ -34493,6 +34553,7 @@ var OpfsFs = class {
34493
34553
  return view(this, { rejectLinks: true });
34494
34554
  }
34495
34555
  refuse(path, holding = false) {
34556
+ this.reserveWrite(path, holding);
34496
34557
  if (isProtected(this.guarded, path) || holding && holdsProtected(this.guarded, path)) {
34497
34558
  throw fsError("EROFS", path);
34498
34559
  }
@@ -34704,6 +34765,7 @@ var OpfsFs = class {
34704
34765
  return this.lookups - seen.op < lookups && performance.now() - seen.at < GLANCE_CAP_MS;
34705
34766
  }
34706
34767
  async handle(path) {
34768
+ if (this.sourceReservation(path)) throw fsError("ENOENT", path);
34707
34769
  this.lookups++;
34708
34770
  if (split2(path).length === 0) return this.root;
34709
34771
  const cached = this.files.get(path);
@@ -35387,6 +35449,9 @@ var OpfsFs = class {
35387
35449
  const name2 = baseOf4(link2.path);
35388
35450
  if (!children3.has(name2)) children3.set(name2, link2);
35389
35451
  }
35452
+ for (const source of this.pendingSources.values()) {
35453
+ if (parentOf11(source) === found.path) children3.delete(baseOf4(source));
35454
+ }
35390
35455
  for (const backup of this.hiddenBackups) {
35391
35456
  if (parentOf11(backup) === found.path) children3.delete(baseOf4(backup));
35392
35457
  }
@@ -35566,7 +35631,7 @@ var OpfsFs = class {
35566
35631
  );
35567
35632
  }
35568
35633
  async removalParentId(path) {
35569
- const parent = await this.lstat(parentOf11(path));
35634
+ const parent = await PLAIN3.lstat.call(this, parentOf11(path));
35570
35635
  return parent.isDirectory ? `${parent.dev ?? 0}:${parent.ino}` : void 0;
35571
35636
  }
35572
35637
  async removePhysical(path, recursive) {
@@ -35725,7 +35790,7 @@ var OpfsFs = class {
35725
35790
  return this.privateCopy(source, parent, destination, target?.handle, moving);
35726
35791
  const place = async () => {
35727
35792
  this.forget(destination);
35728
- const copies = /* @__PURE__ */ new Map();
35793
+ const copies = new Copies();
35729
35794
  const root = { ino: inodeOf(source.path), ...moving };
35730
35795
  const owned4 = lock ? { lock } : {};
35731
35796
  hooks.notify?.();
@@ -35744,18 +35809,23 @@ var OpfsFs = class {
35744
35809
  if (first) await this.rollBack(staged2, source.path, [first, second]);
35745
35810
  throw err;
35746
35811
  });
35747
- if (swap) await this.rm(destination);
35812
+ if (swap) await PLAIN3.rm.call(this, destination);
35748
35813
  if (second) await this.intend({ from: staged2, to: destination, root, ...owned4 }, second);
35749
35814
  await this.meta.move(source.path, destination, carry, left);
35750
35815
  this.movePending(source.path, destination);
35751
- if (!moved2) await this.removePhysical(source.path, true);
35752
- if (first) await this.meta.update(first, () => void 0);
35816
+ if (!moved2 && first)
35817
+ await this.releaseSource(first, source.path, destination, left.ino, lock, copies.remaining);
35818
+ else if (first) await this.meta.update(first, () => void 0);
35753
35819
  if (swap) {
35754
35820
  const hidden = await dir.getDirectoryHandle(staging);
35821
+ copies.remaining = [];
35755
35822
  const placed = await this.place(hidden, dir, name2, copies, copying);
35756
- if (!placed) await dir.removeEntry(staging, { recursive: true });
35823
+ if (!placed && second) {
35824
+ const mark = vacatedAt(staged2);
35825
+ await this.meta.update(staged2, () => mark);
35826
+ await this.releaseSource(second, staged2, destination, mark.ino, lock, copies.remaining);
35827
+ } else if (second) await this.meta.update(second, () => void 0);
35757
35828
  }
35758
- if (second) await this.meta.update(second, () => void 0);
35759
35829
  await this.restamp(destination, copies);
35760
35830
  this.changed(source.path, destination);
35761
35831
  this.touch(Date.now(), parentOf11(source.path), parent.path);
@@ -35974,6 +36044,10 @@ var OpfsFs = class {
35974
36044
  const left = (await this.meta.under(RENAMES2)).filter((entry) => entry.rename?.lock === move.lock).sort(byIntent);
35975
36045
  for (const entry of left) await this.finishRename(entry);
35976
36046
  });
36047
+ for (const entry of await this.meta.under(RENAMES2)) {
36048
+ if (entry.rename?.lock === move.lock && entry.rename.sourceCleanup !== void 0)
36049
+ this.syncSourceReservation(entry.path, entry.rename.from);
36050
+ }
35977
36051
  this.peerMoves.delete(move.lock);
35978
36052
  for (const [from, to] of move.trees) {
35979
36053
  this.forget(from);
@@ -36001,9 +36075,10 @@ var OpfsFs = class {
36001
36075
  }
36002
36076
  aloneCalls = 0;
36003
36077
  aloneDrain;
36004
- async alonePlain(inner, args) {
36078
+ async alonePlain(name2, inner, args) {
36005
36079
  this.aloneCalls++;
36006
36080
  try {
36081
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
36007
36082
  return await inner.apply(this, args);
36008
36083
  } finally {
36009
36084
  this.aloneCalls--;
@@ -36034,6 +36109,7 @@ var OpfsFs = class {
36034
36109
  for (const at of paths) checked.push(...await this.peerSettled(at, listing, removing));
36035
36110
  if (!checked.some((at) => this.peerAt(at, listing, removing))) break;
36036
36111
  }
36112
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
36037
36113
  const busy = { paths: checked, removing, release: () => void 0 };
36038
36114
  const done4 = () => {
36039
36115
  this.inflight.delete(busy);
@@ -36064,6 +36140,7 @@ var OpfsFs = class {
36064
36140
  let sessionOwnsAdmission = false;
36065
36141
  let native = false;
36066
36142
  try {
36143
+ if (this.pendingSources.size) await this.reservedOp(name2, args);
36067
36144
  if (name2 === "writeSession") {
36068
36145
  const session = await inner.apply(inside2, args);
36069
36146
  sessionOwnsAdmission = true;
@@ -36122,7 +36199,7 @@ var OpfsFs = class {
36122
36199
  const handle = source.handle;
36123
36200
  const dir = parent.handle;
36124
36201
  const name2 = baseOf4(to);
36125
- const copies = /* @__PURE__ */ new Map();
36202
+ const copies = new Copies();
36126
36203
  const [entry] = await this.meta.get([source.path]);
36127
36204
  const root = { ino: occupied(entry).ino ?? inodeOf(source.path), ...owner };
36128
36205
  if (target?.kind === "directory" && movable(target) && movable(handle)) {
@@ -36175,16 +36252,19 @@ var OpfsFs = class {
36175
36252
  async commitPrivateCopy(from, to, root, intent, copies, emptyBackup) {
36176
36253
  const { ino, ...owner } = root;
36177
36254
  const entries = await this.meta.get([from, to]);
36178
- if (!entries[0]?.vacated || entries[1]?.ino !== ino) {
36255
+ let mark = entries[0];
36256
+ if (!mark?.vacated || entries[1]?.ino !== ino) {
36257
+ mark = vacatedAt(from);
36179
36258
  await this.meta.move(
36180
36259
  from,
36181
36260
  to,
36182
36261
  (entry) => ({ ...occupied(entry), ...owner, ino, path: to, ctimeMs: Date.now() }),
36183
- vacatedAt(from)
36262
+ mark
36184
36263
  );
36185
36264
  }
36265
+ if (!emptyBackup)
36266
+ await this.releaseSource(intent, from, to, mark.ino, void 0, copies.remaining);
36186
36267
  this.movePending(from, to);
36187
- if (!emptyBackup) await this.removePhysical(from, true);
36188
36268
  await this.restamp(to, copies);
36189
36269
  this.changed(from, to);
36190
36270
  this.touch(Date.now(), parentOf11(from), parentOf11(to));
@@ -36192,16 +36272,102 @@ var OpfsFs = class {
36192
36272
  await this.intend({ from, to, root, emptyBackup, cleanupOnly: true }, intent);
36193
36273
  return this.cleanSwapIntent(intent, emptyBackup);
36194
36274
  }
36195
- await this.meta.update(intent, () => void 0);
36275
+ }
36276
+ async sourceId(path) {
36277
+ const [dir, name2] = await this.parent(path);
36278
+ const parent = await this.dir(dir);
36279
+ let handle;
36280
+ try {
36281
+ handle = await this.child(parent, name2, "directory");
36282
+ } catch (err) {
36283
+ if (err.name !== "TypeMismatchError") throw err;
36284
+ handle = await this.child(parent, name2, "file");
36285
+ }
36286
+ return cleanupId(handle);
36287
+ }
36288
+ async releaseSource(intent, from, to, id2, lock, copiedEntries) {
36289
+ this.syncSourceReservation(intent, from);
36290
+ const physicalSource = copiedEntries?.find((entry) => entry.path === "")?.id;
36291
+ await this.intend(
36292
+ {
36293
+ from,
36294
+ to,
36295
+ sourceCleanup: id2,
36296
+ ...lock && { lock },
36297
+ ...physicalSource && { physicalSource },
36298
+ ...copiedEntries && { copiedEntries }
36299
+ },
36300
+ intent
36301
+ );
36302
+ await this.cleanSource(intent, from, id2);
36303
+ }
36304
+ async cleanSource(intent, from, id2) {
36305
+ const remove = async () => {
36306
+ const [current] = await this.meta.under(intent);
36307
+ if (current?.rename?.sourceCleanup === id2) {
36308
+ const [reservation] = await (this.meta.fresh ?? this.meta.get).call(this.meta, [from]);
36309
+ if (reservation?.vacated && reservation.ino === id2) {
36310
+ try {
36311
+ const expected = current.rename.physicalSource;
36312
+ if (expected === void 0 || await this.sourceId(from) === expected) {
36313
+ const [dir, name2] = await this.parent(from);
36314
+ await this.inDir(
36315
+ dir,
36316
+ (parent) => current.rename?.copiedEntries ? removeCopied(parent, name2, current.rename.copiedEntries) : parent.removeEntry(name2)
36317
+ );
36318
+ }
36319
+ } catch (err) {
36320
+ if (!missing6(err) && err.name !== "NotFoundError") return;
36321
+ }
36322
+ await this.meta.update(
36323
+ from,
36324
+ (current2) => current2?.vacated && current2.ino === reservation.ino ? vacatedAt(from) : current2
36325
+ );
36326
+ }
36327
+ await this.meta.update(intent, () => void 0);
36328
+ }
36329
+ this.syncSourceReservation(intent);
36330
+ };
36331
+ this.syncSourceReservation(intent, from);
36332
+ if (this.locks) await this.locks.request(this.lockPrefix + intent, remove);
36333
+ else await remove();
36196
36334
  }
36197
36335
  async duplicate(handle, parent, name2, copies, rest2) {
36198
36336
  if (handle.kind === "file") return this.copyBytes(handle, parent, name2, { copies }, rest2);
36337
+ copies.remaining.push(await copiedEntry(handle, rest2));
36199
36338
  const dir = await this.io(parent.getDirectoryHandle(name2, { create: true }));
36200
36339
  this.others++;
36201
36340
  for await (const child2 of handle.values())
36202
36341
  await this.duplicate(child2, dir, child2.name, copies, rest2 + "/" + child2.name);
36203
36342
  }
36204
36343
  hiddenBackups = /* @__PURE__ */ new Set();
36344
+ pendingSources = /* @__PURE__ */ new Map();
36345
+ syncSourceReservation(intent, from) {
36346
+ const path = from ?? this.pendingSources.get(intent);
36347
+ if (from === void 0) this.pendingSources.delete(intent);
36348
+ else this.pendingSources.set(intent, from);
36349
+ if (path) this.forget(path);
36350
+ }
36351
+ async reservedOp(name2, args) {
36352
+ const touched = name2 === "symlink" ? args.slice(1, 2) : args.slice(0, PAIRED.has(name2) ? 2 : 1);
36353
+ for (const [intent, source] of this.pendingSources) {
36354
+ const [entry] = await this.meta.under(intent);
36355
+ if (entry?.rename?.sourceCleanup === void 0) this.syncSourceReservation(intent);
36356
+ else if (!READS.includes(name2) && touched.some((p) => {
36357
+ const at = normalizePath(p);
36358
+ return within11(at, source) || REMOVALS2.has(name2) && (at === "/" || within11(source, at));
36359
+ }))
36360
+ throw fsError("EBUSY", source);
36361
+ }
36362
+ }
36363
+ sourceReservation(path, ancestor = false) {
36364
+ for (const source of this.pendingSources.values())
36365
+ if (within11(path, source) || ancestor && within11(source, path)) return source;
36366
+ return void 0;
36367
+ }
36368
+ reserveWrite(path, ancestor = false) {
36369
+ if (this.sourceReservation(path, ancestor)) throw fsError("EBUSY", path);
36370
+ }
36205
36371
  renamingDirs = /* @__PURE__ */ new Set();
36206
36372
  intents = 0;
36207
36373
  async intend(rename, at = `${RENAMES2}/${crypto.randomUUID()}`) {
@@ -36262,7 +36428,7 @@ var OpfsFs = class {
36262
36428
  }
36263
36429
  if (!left) {
36264
36430
  if ((await this.swapEntry(to))?.kind !== "directory") throw fsError("EIO", to);
36265
- return this.commitPrivateCopy(from, to, root, intent, /* @__PURE__ */ new Map(), backup);
36431
+ return this.commitPrivateCopy(from, to, root, intent, new Copies(), backup);
36266
36432
  }
36267
36433
  const staged2 = await this.swapEntry(backup);
36268
36434
  if (staged2) {
@@ -36275,10 +36441,72 @@ var OpfsFs = class {
36275
36441
  }
36276
36442
  await this.dropSwapIntent(intent, backup);
36277
36443
  }
36444
+ async resumeCopiedTree(intent, rename) {
36445
+ const { from, to, root } = rename;
36446
+ const left = await this.real(from);
36447
+ if (left && root) {
36448
+ const [mark, placed] = await this.meta.get([from, to]);
36449
+ if (mark?.vacated && mark.ino !== void 0 && placed?.ino === root.ino)
36450
+ return this.releaseSource(intent, from, to, mark.ino, rename.lock);
36451
+ }
36452
+ if (rename.privateCopy) {
36453
+ if (left) {
36454
+ const src = await this.locate(from, false);
36455
+ const dir = await this.locate(parentOf11(to), true);
36456
+ const copies = new Copies();
36457
+ await this.duplicate(
36458
+ src.handle,
36459
+ dir.handle,
36460
+ baseOf4(to),
36461
+ copies,
36462
+ ""
36463
+ );
36464
+ await this.commitPrivateCopy(from, to, root ?? { ino: inodeOf(from) }, intent, copies);
36465
+ } else await this.meta.update(intent, () => void 0);
36466
+ return;
36467
+ }
36468
+ await this.resumeCoordinatedCopy(intent, rename, left);
36469
+ }
36470
+ async resumeCoordinatedCopy(intent, rename, left) {
36471
+ const { from, to, replace, root } = rename;
36472
+ const copies = new Copies();
36473
+ if (left && replace && await this.real(to))
36474
+ await PLAIN3.rm.call(this, to, { recursive: true });
36475
+ if (left) {
36476
+ const source = await this.locate(from, false);
36477
+ const target = await this.locate(parentOf11(to), true);
36478
+ await this.copy(
36479
+ source.handle,
36480
+ target.handle,
36481
+ baseOf4(to),
36482
+ { copies }
36483
+ );
36484
+ this.forget(from);
36485
+ this.forget(to);
36486
+ }
36487
+ const mark = left ? vacatedAt(from) : void 0;
36488
+ if ((await this.meta.under(from)).some((entry) => !entry.vacated)) {
36489
+ await this.meta.move(
36490
+ from,
36491
+ to,
36492
+ (moved2) => ({
36493
+ ...occupied(moved2),
36494
+ ...root,
36495
+ ino: occupied(moved2).ino ?? root?.ino ?? inodeOf(from),
36496
+ path: to
36497
+ }),
36498
+ mark
36499
+ );
36500
+ } else if (mark) await this.meta.update(from, () => mark);
36501
+ if (mark) await this.releaseSource(intent, from, to, mark.ino, rename.lock, copies.remaining);
36502
+ else await this.meta.update(intent, () => void 0);
36503
+ this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36504
+ }
36278
36505
  async finishRename(entry) {
36279
36506
  const [current] = await this.meta.under(entry.path);
36280
36507
  if (current?.rename === void 0) return;
36281
- const { from, to, replace, root, emptyBackup, cleanupOnly } = current.rename;
36508
+ const { from, to, root, emptyBackup, cleanupOnly, sourceCleanup } = current.rename;
36509
+ if (sourceCleanup !== void 0) return this.cleanSource(entry.path, from, sourceCleanup);
36282
36510
  if (emptyBackup) this.hiddenBackups.add(emptyBackup);
36283
36511
  if (emptyBackup && cleanupOnly) return this.cleanSwapIntent(entry.path, emptyBackup);
36284
36512
  const { promise, resolve: resolve2 } = Promise.withResolvers();
@@ -36298,59 +36526,7 @@ var OpfsFs = class {
36298
36526
  );
36299
36527
  return;
36300
36528
  }
36301
- const left = await this.real(from);
36302
- if (current.rename.privateCopy) {
36303
- if (left) {
36304
- const src = await this.locate(from, false);
36305
- const dir = await this.locate(parentOf11(to), true);
36306
- const copies = /* @__PURE__ */ new Map();
36307
- await this.duplicate(
36308
- src.handle,
36309
- dir.handle,
36310
- baseOf4(to),
36311
- copies,
36312
- ""
36313
- );
36314
- await this.commitPrivateCopy(
36315
- from,
36316
- to,
36317
- root ?? { ino: inodeOf(from) },
36318
- entry.path,
36319
- copies
36320
- );
36321
- } else await this.meta.update(entry.path, () => void 0);
36322
- return;
36323
- }
36324
- if (left && replace && await this.real(to))
36325
- await PLAIN3.rm.call(this, to, { recursive: true });
36326
- if (left) {
36327
- const source = await this.locate(from, false);
36328
- const target = await this.locate(parentOf11(to), true);
36329
- await this.copy(
36330
- source.handle,
36331
- target.handle,
36332
- baseOf4(to)
36333
- );
36334
- const [dir, name2] = await this.parent(from);
36335
- await this.inDir(dir, (parent) => parent.removeEntry(name2, { recursive: true }));
36336
- this.forget(from);
36337
- this.forget(to);
36338
- }
36339
- if ((await this.meta.under(from)).some((entry2) => !entry2.vacated)) {
36340
- await this.meta.move(
36341
- from,
36342
- to,
36343
- (moved2) => ({
36344
- ...occupied(moved2),
36345
- ...root,
36346
- ino: occupied(moved2).ino ?? root?.ino ?? inodeOf(from),
36347
- path: to
36348
- }),
36349
- void 0
36350
- );
36351
- }
36352
- await this.meta.update(entry.path, () => void 0);
36353
- this.remote?.emit({ paths: [], trees: [], moved: { from, to } });
36529
+ await this.resumeCopiedTree(entry.path, current.rename);
36354
36530
  } finally {
36355
36531
  this.renamingDirs.delete(barrier);
36356
36532
  resolve2();
@@ -36525,6 +36701,7 @@ var OpfsFs = class {
36525
36701
  if (await this.moveChild(handle, dir, name2)) return;
36526
36702
  return this.copyBytes(handle, dir, name2, options, rest2);
36527
36703
  }
36704
+ if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2));
36528
36705
  const target = await this.io(dir.getDirectoryHandle(name2, { create: true }));
36529
36706
  this.others++;
36530
36707
  for await (const child2 of handle.values()) {
@@ -36542,6 +36719,7 @@ var OpfsFs = class {
36542
36719
  await writable3.abort().catch(nothing2);
36543
36720
  throw err;
36544
36721
  }
36722
+ if (options.copies) options.copies.remaining.push(await copiedEntry(handle, rest2, file));
36545
36723
  options.copies?.set(rest2, {
36546
36724
  before: options.copies.get(rest2)?.before ?? file.lastModified,
36547
36725
  made: made2
@@ -36723,6 +36901,7 @@ function byIntent(a, b) {
36723
36901
  return a.rename.at - b.rename.at;
36724
36902
  }
36725
36903
  var PLAIN3 = {
36904
+ lstat: OpfsFs.prototype.lstat,
36726
36905
  rm: OpfsFs.prototype.rm,
36727
36906
  realpath: OpfsFs.prototype.realpath
36728
36907
  };
@@ -36763,7 +36942,7 @@ var WRITES = [
36763
36942
  proto.createExclusive = function(...args) {
36764
36943
  if (this.privateRename) return this.privateOp("createExclusive", args, inner);
36765
36944
  if (this.amongPeers()) return this.peerOp("createExclusive", args, inner);
36766
- return this.alonePlain(inner, args);
36945
+ return this.alonePlain("createExclusive", inner, args);
36767
36946
  };
36768
36947
  }
36769
36948
  for (const [names2, op] of [
@@ -36779,7 +36958,7 @@ for (const [names2, op] of [
36779
36958
  if (op === "read") await this.settledRename(args[0]);
36780
36959
  if (this.amongPeers() || name2 === "writeSession")
36781
36960
  return await this.peerOp(name2, args, inner);
36782
- return await this.alonePlain(inner, args);
36961
+ return await this.alonePlain(name2, inner, args);
36783
36962
  } catch (err) {
36784
36963
  throw translate(err, String(args[0]), op, false);
36785
36964
  }
@@ -36789,13 +36968,13 @@ for (const [names2, op] of [
36789
36968
 
36790
36969
  // src/mount/medium.ts
36791
36970
  var EMPTY_ROOT = { kind: "directory", size: 0, mtime: 0, mode: 16877 };
36792
- var absent = () => fsError2("ENOMEDIUM", "No medium found");
36971
+ var absent2 = () => fsError2("ENOMEDIUM", "No medium found");
36793
36972
  function mediumSlot(lost, onLost) {
36794
36973
  let current;
36795
36974
  function wrap(pick) {
36796
36975
  return async (...args) => {
36797
36976
  const medium = current;
36798
- if (!medium) throw absent();
36977
+ if (!medium) throw absent2();
36799
36978
  try {
36800
36979
  return await pick(medium.handlers)(...args);
36801
36980
  } catch (err) {
@@ -36804,7 +36983,7 @@ function mediumSlot(lost, onLost) {
36804
36983
  current = void 0;
36805
36984
  onLost(medium.key);
36806
36985
  }
36807
- throw absent();
36986
+ throw absent2();
36808
36987
  }
36809
36988
  };
36810
36989
  }
@@ -44003,7 +44182,19 @@ var Chunks = class {
44003
44182
  this.size = size;
44004
44183
  }
44005
44184
  };
44185
+ var identities = /* @__PURE__ */ new WeakMap();
44186
+ function entryId(handle) {
44187
+ let id2 = identities.get(handle);
44188
+ if (!id2) {
44189
+ id2 = crypto.randomUUID();
44190
+ identities.set(handle, id2);
44191
+ }
44192
+ return id2;
44193
+ }
44006
44194
  var MemoryFile = class {
44195
+ async getUniqueId() {
44196
+ return entryId(this);
44197
+ }
44007
44198
  kind = "file";
44008
44199
  name;
44009
44200
  parent;
@@ -44089,6 +44280,9 @@ var MemoryFile = class {
44089
44280
  }
44090
44281
  };
44091
44282
  var MemoryDirectory = class _MemoryDirectory {
44283
+ async getUniqueId() {
44284
+ return entryId(this);
44285
+ }
44092
44286
  kind = "directory";
44093
44287
  name;
44094
44288
  parent;