@ai-ecoverse/slicc-kernel 1.84.0 → 1.84.1

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
@@ -3022,6 +3022,9 @@ var MemoryMeta = class {
3022
3022
  async remove(paths) {
3023
3023
  for (const path of paths) this.entries.deleteTree(path);
3024
3024
  }
3025
+ absent(path) {
3026
+ return !this.entries.has(path);
3027
+ }
3025
3028
  async links(dir) {
3026
3029
  return [...this.entries.entries()].map(([, e]) => e).filter((entry) => entry.dir === dir);
3027
3030
  }
@@ -3470,7 +3473,14 @@ function sidecar(meta) {
3470
3473
  const guarded3 = (op) => (...args) => meta[op].apply(meta, args).catch((err) => {
3471
3474
  throw translate(err, pathOf(args), "sidecar", false);
3472
3475
  });
3473
- return Object.fromEntries(META_OPS.map((op) => [op, guarded3(op)]));
3476
+ const ops = Object.fromEntries(META_OPS.map((op) => [op, guarded3(op)]));
3477
+ if (meta.absent) ops.absent = meta.absent.bind(meta);
3478
+ const { removeFile } = meta;
3479
+ if (removeFile)
3480
+ ops.removeFile = (path) => removeFile.call(meta, path).catch((err) => {
3481
+ throw translate(err, path, "sidecar", false);
3482
+ });
3483
+ return ops;
3474
3484
  }
3475
3485
  function missing2(err) {
3476
3486
  const code = err?.code;
@@ -4163,6 +4173,7 @@ var OpfsFs = class {
4163
4173
  throw error;
4164
4174
  }
4165
4175
  this.refuse(found.path, true);
4176
+ if (options.file && found.handle?.kind === "directory") throw fsError("EISDIR", path);
4166
4177
  if (found.handle) {
4167
4178
  const [dir, name2] = await this.parent(found.path);
4168
4179
  try {
@@ -4173,8 +4184,19 @@ var OpfsFs = class {
4173
4184
  } catch (err) {
4174
4185
  throw translate(err, path);
4175
4186
  }
4176
- this.changed(found.path);
4187
+ const file = found.handle.kind === "file";
4188
+ if (!file || this.remote?.watched()) this.changed(found.path);
4189
+ else this.forget(found.path);
4177
4190
  this.movePending(found.path);
4191
+ if (file && this.meta.absent?.(found.path)) {
4192
+ this.touch(parentOf4(found.path));
4193
+ return;
4194
+ }
4195
+ if (file && this.meta.removeFile) {
4196
+ await this.meta.removeFile(found.path);
4197
+ this.touch(parentOf4(found.path));
4198
+ return;
4199
+ }
4178
4200
  }
4179
4201
  await this.meta.remove([found.path]);
4180
4202
  this.touch(parentOf4(found.path));
@@ -6999,6 +7021,10 @@ var MountTable = class {
6999
7021
  ...error ? { error } : {}
7000
7022
  });
7001
7023
  }
7024
+ under(path) {
7025
+ for (const mount of this.mounts.values()) if (within5(mount.target, path)) return true;
7026
+ return false;
7027
+ }
7002
7028
  locate(path) {
7003
7029
  let best;
7004
7030
  for (const mount of this.mounts.values()) {
@@ -7568,9 +7594,12 @@ var MountFs = class {
7568
7594
  }
7569
7595
  async rm(path, options = {}) {
7570
7596
  const found = this.at(path);
7597
+ if (!found && options.recursive && this.table.under(normalizePath(path)))
7598
+ return this.rmAround(normalizePath(path), options);
7571
7599
  if (!found) return this.base.rm(path, options);
7572
7600
  const { mount, rel: rel2 } = found;
7573
7601
  const real = normalizePath(path);
7602
+ if (rel2 === "/" && options.recursive) await this.rmEach(real, mount, rel2, options);
7574
7603
  if (rel2 === "/") throw errnoError("EBUSY", `${real} is a mount point`);
7575
7604
  this.writable(mount, real);
7576
7605
  await this.table.commitUnder(real);
@@ -7581,16 +7610,33 @@ var MountFs = class {
7581
7610
  if (options.force && err.code === "ENOENT") return;
7582
7611
  throw err;
7583
7612
  }
7613
+ if (options.file && attr2.kind === "directory") throw errnoError("EISDIR", real);
7584
7614
  this.table.forget(mount, real);
7585
7615
  if (attr2.kind === "directory" && options.recursive) {
7586
- for (const entry of await this.table.readdir(mount, real, rel2)) {
7587
- await this.rm(`${real}/${entry.name}`, { recursive: true, force: options.force ?? false });
7588
- }
7616
+ await this.rmEach(real, mount, rel2, { recursive: true, force: options.force ?? false });
7589
7617
  this.table.forget(mount, real);
7590
7618
  }
7591
7619
  await mount.conn.call({ op: attr2.kind === "directory" ? "rmdir" : "unlink", path: rel2 });
7592
7620
  this.table.forget(mount, real);
7593
7621
  }
7622
+ async rmEach(real, mount, rel2, options) {
7623
+ let first;
7624
+ for (const entry of await this.table.readdir(mount, real, rel2)) {
7625
+ await this.rm(joinName(real, entry.name), options).catch((err) => {
7626
+ first ??= err;
7627
+ });
7628
+ }
7629
+ if (first) throw first;
7630
+ }
7631
+ async rmAround(path, options) {
7632
+ let first;
7633
+ for (const name2 of await this.base.readdir(path)) {
7634
+ await this.rm(joinName(path, name2), options).catch((err) => {
7635
+ first ??= err;
7636
+ });
7637
+ }
7638
+ throw first ?? errnoError("EBUSY", `${path} holds a mount point`);
7639
+ }
7594
7640
  async rename(from, to) {
7595
7641
  const a = this.at(from);
7596
7642
  const b = this.at(to);
@@ -7894,8 +7940,7 @@ async function run(entry, path, req) {
7894
7940
  await fs.link(path, fs.resolvePath(cwd, req.arg2 ?? ""), req.mode === 1);
7895
7941
  return done;
7896
7942
  case "unlink":
7897
- if ((await fs.lstat(path)).isDirectory) throw syncError("EISDIR", path);
7898
- await fs.rm(path);
7943
+ await fs.rm(path, { file: true });
7899
7944
  return done;
7900
7945
  case "rmdir":
7901
7946
  if (!(await fs.lstat(path)).isDirectory) throw syncError("ENOTDIR", path);
@@ -8129,6 +8174,26 @@ async function dispatchSyncFs(req) {
8129
8174
  return toErrno(err);
8130
8175
  }
8131
8176
  }
8177
+ var DENIED = /* @__PURE__ */ new Set(["EACCES", "EPERM"]);
8178
+ async function rmPermitted(entry, path, req, refused2) {
8179
+ const st = await entry.fs.lstat(path).catch(() => void 0);
8180
+ if (!st?.isDirectory) return refused2;
8181
+ const unlisted = await guarded(entry, path, { ...req, op: "readdir" });
8182
+ if (unlisted) return unlisted;
8183
+ const names = await entry.fs.readdir(path).catch(() => void 0);
8184
+ if (!names) return refused2;
8185
+ let first;
8186
+ for (const name2 of names) {
8187
+ const child = await dispatchOne(entry, {
8188
+ ...req,
8189
+ path: joinName(path, name2)
8190
+ });
8191
+ if (!child.ok) first ??= child;
8192
+ }
8193
+ if (first) return first;
8194
+ const again = await guarded(entry, path, req);
8195
+ return again ?? await run(entry, path, req);
8196
+ }
8132
8197
  async function dispatchOne(entry, req) {
8133
8198
  const { fs, cwd } = entry;
8134
8199
  try {
@@ -8138,6 +8203,9 @@ async function dispatchOne(entry, req) {
8138
8203
  if (req.op === "access") return await accessOp(entry, path, req);
8139
8204
  if (req.op === "hold") return await holdOp(entry, path, req);
8140
8205
  const refused2 = await guarded(entry, path, req);
8206
+ if (refused2 && req.op === "rm" && !refused2.ok && DENIED.has(refused2.errno)) {
8207
+ return await rmPermitted(entry, path, req, refused2);
8208
+ }
8141
8209
  if (refused2) return refused2;
8142
8210
  if (req.op === "statfs") return json2(await usageAt(entry, path) ?? await storageUsage());
8143
8211
  if (entry.revoked?.(path)) return { ok: false, errno: "EIO", message: `${path} was unmounted` };