@ai-ecoverse/slicc-kernel 1.185.0 → 1.186.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.
@@ -1446,9 +1446,9 @@ function permOf(st, link2) {
1446
1446
  ...link2 !== void 0 ? { link: link2 } : {}
1447
1447
  };
1448
1448
  }
1449
- function permits(cred, perm, want2, directory = true) {
1450
- const mode = perm.mode ?? (directory ? 493 : 420);
1451
- if (cred.euid === 0) return (want2 & X_OK) === 0 || directory || (mode & 73) !== 0;
1449
+ function permits(cred, perm, want2, directory2 = true) {
1450
+ const mode = perm.mode ?? (directory2 ? 493 : 420);
1451
+ if (cred.euid === 0) return (want2 & X_OK) === 0 || directory2 || (mode & 73) !== 0;
1452
1452
  const shift = cred.euid === perm.uid ? 6 : inGroup(cred, perm.gid) ? 3 : 0;
1453
1453
  return (mode >> shift & want2) === want2;
1454
1454
  }
@@ -1521,9 +1521,9 @@ async function walk(fs, cred, path, follow2, links) {
1521
1521
  }
1522
1522
  return { path: at, perm: await perms.at(at) };
1523
1523
  }
1524
- async function present(fs, path, directory) {
1524
+ async function present(fs, path, directory2) {
1525
1525
  const st = await fs.lstat(path).catch(() => void 0);
1526
- return st !== void 0 && (!directory || st.isDirectory);
1526
+ return st !== void 0 && (!directory2 || st.isDirectory);
1527
1527
  }
1528
1528
  async function finalOf(fs, walked, want2, options) {
1529
1529
  const perm = walked.perm;
@@ -1544,8 +1544,8 @@ async function access(fs, cred, path, want2, options = {}) {
1544
1544
  return { path, perm: void 0, missing: true };
1545
1545
  }
1546
1546
  if (!walked.perm) return { ...walked, missing: true };
1547
- const [perm, directory] = await finalOf(fs, walked, want2, options);
1548
- if (want2 === 0 || permits(cred, perm, want2, directory)) return walked;
1547
+ const [perm, directory2] = await finalOf(fs, walked, want2, options);
1548
+ if (want2 === 0 || permits(cred, perm, want2, directory2)) return walked;
1549
1549
  if (await present(fs, walked.path, false)) return { ...walked, denied: walked.path };
1550
1550
  return { ...walked, missing: true };
1551
1551
  }
@@ -4673,7 +4673,7 @@ function satisfies(version, range2) {
4673
4673
  }
4674
4674
 
4675
4675
  // src/version.ts
4676
- var KERNEL_VERSION = true ? "1.185.0" : "0.0.0-dev";
4676
+ var KERNEL_VERSION = true ? "1.186.1" : "0.0.0-dev";
4677
4677
  var OS_RELEASE = "6.0.0-slicc";
4678
4678
  function procVersion() {
4679
4679
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -7847,14 +7847,14 @@ var BIN_ENTRY = /\/bin\/[^/]+$/;
7847
7847
  function missing2(err) {
7848
7848
  return err?.code === "ENOENT";
7849
7849
  }
7850
- function synthetic(directory, path) {
7850
+ function synthetic(directory2, path) {
7851
7851
  const epoch2 = /* @__PURE__ */ new Date(0);
7852
7852
  return {
7853
- isFile: !directory,
7854
- isDirectory: directory,
7853
+ isFile: !directory2,
7854
+ isDirectory: directory2,
7855
7855
  isSymbolicLink: false,
7856
7856
  size: 0,
7857
- mode: (directory ? S_IFDIR : S_IFREG) | 493,
7857
+ mode: (directory2 ? S_IFDIR : S_IFREG) | 493,
7858
7858
  mtime: epoch2,
7859
7859
  atime: epoch2,
7860
7860
  ctime: epoch2,
@@ -8965,14 +8965,14 @@ var FsWatchers = class {
8965
8965
  this.watchers.delete(watcher);
8966
8966
  };
8967
8967
  }
8968
- typedWatch(root, recursive, alias, directory = recursive) {
8968
+ typedWatch(root, recursive, alias, directory2 = recursive) {
8969
8969
  const main = normalizePath(root);
8970
8970
  const other = alias === void 0 ? main : normalizePath(alias);
8971
8971
  const watch = {
8972
8972
  roots: other === main ? [main] : [main, other],
8973
8973
  names: /* @__PURE__ */ new Map(),
8974
8974
  recursive,
8975
- directory,
8975
+ directory: directory2,
8976
8976
  notes: [],
8977
8977
  overflowed: false,
8978
8978
  ended: false,
@@ -11430,7 +11430,7 @@ function view(target, overrides) {
11430
11430
  }
11431
11431
 
11432
11432
  // src/mount/protocol.ts
11433
- var DRIVER_PROTOCOL = [1, 3];
11433
+ var DRIVER_PROTOCOL = [1, 4];
11434
11434
  function driverVersionError(theirs) {
11435
11435
  const major = Array.isArray(theirs) ? theirs[0] : void 0;
11436
11436
  if (major === DRIVER_PROTOCOL[0]) return void 0;
@@ -11860,7 +11860,7 @@ function statOf2(attr2, path, mount) {
11860
11860
  ino: attr2.ino ?? inodeOf(path),
11861
11861
  ...!inodeless(mount, attr2) && attr2.nlink !== void 0 ? { nlink: attr2.nlink } : {},
11862
11862
  dev: mount.dev,
11863
- ...readonly(mount) ? { readonly: true } : {},
11863
+ ...readonly(mount) || attr2.readonly === true ? { readonly: true } : {},
11864
11864
  ...mount.maxFile > 0 ? { maxFile: mount.maxFile } : {},
11865
11865
  ...mount.caps.ranges ? { ranged: true } : {},
11866
11866
  ...mount.caps.links ? { linkable: true } : {},
@@ -12315,17 +12315,17 @@ var MountFs = class _MountFs {
12315
12315
  ...owner
12316
12316
  });
12317
12317
  }
12318
- async driverOwner(found, real2, owner, directory) {
12318
+ async driverOwner(found, real2, owner, directory2) {
12319
12319
  const { mount, rel: rel2 } = found;
12320
12320
  if (!owner || !mount.owners || !mount.caps.owners) return void 0;
12321
12321
  const dir = parentOf7(real2);
12322
- const above = statOf2(await this.table.getattr(mount, dir, parentOf7(rel2)), dir, mount);
12323
- const setgid = (above.mode & S_ISGID3) !== 0;
12322
+ const above2 = statOf2(await this.table.getattr(mount, dir, parentOf7(rel2)), dir, mount);
12323
+ const setgid = (above2.mode & S_ISGID3) !== 0;
12324
12324
  let mode = owner.mode;
12325
- if (directory && setgid) mode = (mode ?? 493) | S_ISGID3;
12325
+ if (directory2 && setgid) mode = (mode ?? 493) | S_ISGID3;
12326
12326
  return {
12327
12327
  uid: owner.uid,
12328
- gid: setgid ? above.gid : owner.gid,
12328
+ gid: setgid ? above2.gid : owner.gid,
12329
12329
  ...mode !== void 0 ? { mode } : {}
12330
12330
  };
12331
12331
  }
@@ -12850,6 +12850,9 @@ var MountFs = class _MountFs {
12850
12850
  this.writable(a.mount, normalizePath(to));
12851
12851
  if (a.mount.caps.links) await this.lstat(from);
12852
12852
  if (!a.mount.caps.links) {
12853
+ if ((await this.lstat(parentOf7(to)).catch(() => void 0))?.readonly) {
12854
+ throw errnoError("EROFS", to);
12855
+ }
12853
12856
  throw errnoError("EPERM", `${from}: this file system has no hard links`);
12854
12857
  }
12855
12858
  await this.table.commitUnder(from);
@@ -13279,10 +13282,7 @@ async function run(entry, path, req) {
13279
13282
  await fs.rm(path, { file: true });
13280
13283
  return done;
13281
13284
  case "rmdir":
13282
- if (!(await fs.lstat(path)).isDirectory) throw syncError("ENOTDIR", path);
13283
- if ((await fs.readdir(path)).length > 0) throw syncError("ENOTEMPTY", path);
13284
- await fs.rm(path, { recursive: true });
13285
- return done;
13285
+ return rmdir(fs, path);
13286
13286
  case "symlink":
13287
13287
  await fs.symlink(req.arg2 ?? "", path, ownerFor(entry));
13288
13288
  return done;
@@ -13565,6 +13565,14 @@ async function copyOp(entry, path, req) {
13565
13565
  entry.fresh?.(to);
13566
13566
  return done;
13567
13567
  }
13568
+ async function rmdir(fs, path) {
13569
+ const st = await fs.lstat(path);
13570
+ if (!st.isDirectory) throw syncError("ENOTDIR", path);
13571
+ if (st.readonly) throw syncError("EROFS", path);
13572
+ if ((await fs.readdir(path)).length > 0) throw syncError("ENOTEMPTY", path);
13573
+ await fs.rm(path, { recursive: true });
13574
+ return done;
13575
+ }
13568
13576
  async function createExclusive(fs, path, owner) {
13569
13577
  if (fs.createExclusive) return fs.createExclusive(path, owner);
13570
13578
  if (await fs.lstat(path).then(
@@ -30573,7 +30581,7 @@ var OpfsFs = class {
30573
30581
  async owned(stat, path, entry) {
30574
30582
  return this.owners ? { ...stat, ...await this.ownerAt(path, entry) } : stat;
30575
30583
  }
30576
- async newFields(path, owner, directory) {
30584
+ async newFields(path, owner, directory2) {
30577
30585
  if (!this.owners || !owner) return void 0;
30578
30586
  const entries = await this.meta.get(chain(path));
30579
30587
  const self = entries.pop();
@@ -30582,19 +30590,19 @@ var OpfsFs = class {
30582
30590
  const parentGid = (ownOf(parent) ?? inherit(entries.slice(0, -1))).gid;
30583
30591
  const want2 = { uid: owner.uid, gid: setgid ? parentGid : owner.gid };
30584
30592
  let mode = owner.mode === void 0 ? void 0 : owner.mode & PERM_MASK;
30585
- if (directory && setgid) mode = (mode ?? 493) | S_ISGID4;
30593
+ if (directory2 && setgid) mode = (mode ?? 493) | S_ISGID4;
30586
30594
  const fields = {};
30587
- if (mode !== void 0 && mode !== (this.mode(path, directory, void 0) & PERM_MASK)) {
30595
+ if (mode !== void 0 && mode !== (this.mode(path, directory2, void 0) & PERM_MASK)) {
30588
30596
  fields.mode = mode;
30589
30597
  }
30590
30598
  if (self) fields.heir = void 0;
30591
30599
  if (ownOf(self) || !sameOwner(want2, inherit(entries))) Object.assign(fields, want2);
30592
30600
  return Object.keys(fields).length > 0 ? fields : void 0;
30593
30601
  }
30594
- async stampNew(path, owner, directory) {
30595
- const owned4 = await this.newFields(path, owner, directory);
30602
+ async stampNew(path, owner, directory2) {
30603
+ const owned4 = await this.newFields(path, owner, directory2);
30596
30604
  if (owner?.socket && owner.fifo) throw new Error("a new node is a socket or a FIFO, not both");
30597
- const kind = directory ? void 0 : owner?.socket ? "socket" : owner?.fifo ? "fifo" : void 0;
30605
+ const kind = directory2 ? void 0 : owner?.socket ? "socket" : owner?.fifo ? "fifo" : void 0;
30598
30606
  const unique = kind === "fifo" ? { ino: inodeOf(`${path}\0${crypto.randomUUID()}`) } : {};
30599
30607
  const fields = kind ? { ...owned4, ...unique, [kind]: true } : owned4;
30600
30608
  if (fields) await this.meta.update(path, (entry) => ({ ...occupied(entry), path, ...fields }));
@@ -30940,9 +30948,9 @@ var OpfsFs = class {
30940
30948
  }
30941
30949
  return { path: `/${done4.join("/")}`, hops };
30942
30950
  }
30943
- mode(path, directory, meta) {
30944
- const fallback = directory || EXECUTABLE.test(path) ? 493 : 420;
30945
- const type = directory ? S_IFDIR2 : meta?.socket ? S_IFSOCK : meta?.fifo ? S_IFIFO : S_IFREG3;
30951
+ mode(path, directory2, meta) {
30952
+ const fallback = directory2 || EXECUTABLE.test(path) ? 493 : 420;
30953
+ const type = directory2 ? S_IFDIR2 : meta?.socket ? S_IFSOCK : meta?.fifo ? S_IFIFO : S_IFREG3;
30946
30954
  return type | (meta?.mode ?? fallback);
30947
30955
  }
30948
30956
  id = crypto.randomUUID();
@@ -31066,27 +31074,27 @@ var OpfsFs = class {
31066
31074
  return this.glanced(handle) ?? this.glance(handle);
31067
31075
  }
31068
31076
  async statOf(path, handle, meta, touched) {
31069
- const directory = handle.kind === "directory";
31070
- const file = directory ? void 0 : await this.snapshot(handle);
31077
+ const directory2 = handle.kind === "directory";
31078
+ const file = directory2 ? void 0 : await this.snapshot(handle);
31071
31079
  const modified = file?.lastModified ?? 0;
31072
31080
  const kept = meta?.mtimeMs !== void 0 && meta.mtimeFor === modified ? meta.mtimeMs : modified;
31073
31081
  const mtime = touched ?? kept;
31074
- const socket = !directory && meta?.socket === true;
31075
- const fifo = !directory && meta?.fifo === true;
31082
+ const socket = !directory2 && meta?.socket === true;
31083
+ const fifo = !directory2 && meta?.fifo === true;
31076
31084
  return {
31077
- isFile: !directory && !socket && !fifo,
31078
- isDirectory: directory,
31085
+ isFile: !directory2 && !socket && !fifo,
31086
+ isDirectory: directory2,
31079
31087
  isSymbolicLink: false,
31080
31088
  ...socket ? { isSocket: true } : {},
31081
31089
  ...fifo ? { isFifo: true } : {},
31082
31090
  size: file?.size ?? 0,
31083
- mode: this.mode(path, directory, meta),
31091
+ mode: this.mode(path, directory2, meta),
31084
31092
  mtime: new Date(mtime),
31085
31093
  atime: new Date(meta?.atimeMs ?? mtime),
31086
31094
  ctime: new Date(Math.max(touched ?? meta?.ctimeMs ?? mtime, modified)),
31087
31095
  ino: meta?.ino ?? inodeOf(path),
31088
31096
  ...meta?.fid !== void 0 ? { fid: meta.fid } : {},
31089
- ...this.ranged && !directory ? { ranged: true } : {}
31097
+ ...this.ranged && !directory2 ? { ranged: true } : {}
31090
31098
  };
31091
31099
  }
31092
31100
  linkStat(entry) {
@@ -31526,20 +31534,20 @@ var OpfsFs = class {
31526
31534
  if (!missing5(err)) throw err;
31527
31535
  }
31528
31536
  if (found) {
31529
- const directory = found.handle?.kind === "directory";
31530
- if (directory) return;
31537
+ const directory2 = found.handle?.kind === "directory";
31538
+ if (directory2) return;
31531
31539
  throw fsError("ENOTDIR", path);
31532
31540
  }
31533
31541
  const [entry] = await this.meta.get([path]);
31534
31542
  if (entry?.link !== void 0) throw fsError("EEXIST", path);
31535
31543
  const { owner } = options;
31536
31544
  const mode = owner?.parents;
31537
- const above = owner && {
31545
+ const above2 = owner && {
31538
31546
  uid: owner.uid,
31539
31547
  gid: owner.gid,
31540
31548
  ...mode !== void 0 ? { mode, parents: mode } : {}
31541
31549
  };
31542
- await this.mkdir(parentOf9(path), { recursive: true, ...above ? { owner: above } : {} });
31550
+ await this.mkdir(parentOf9(path), { recursive: true, ...above2 ? { owner: above2 } : {} });
31543
31551
  const parent = await this.locate(parentOf9(path), true);
31544
31552
  if (parent.handle?.kind !== "directory") throw fsError("ENOTDIR", path);
31545
31553
  const made2 = resolvePath(parent.path, baseOf3(path));
@@ -32362,8 +32370,8 @@ var OpfsFs = class {
32362
32370
  const found = await this.locate(path, true);
32363
32371
  this.refuse(found.path);
32364
32372
  const [known] = await this.meta.get([found.path]);
32365
- const directory = found.handle?.kind === "directory";
32366
- if ((this.mode(found.path, directory, known) & PERM_MASK) === (mode & PERM_MASK)) return;
32373
+ const directory2 = found.handle?.kind === "directory";
32374
+ if ((this.mode(found.path, directory2, known) & PERM_MASK) === (mode & PERM_MASK)) return;
32367
32375
  const ctimeMs = Date.now();
32368
32376
  await this.meta.update(found.path, (entry) => ({
32369
32377
  ...entry,
@@ -32415,9 +32423,9 @@ var OpfsFs = class {
32415
32423
  const known = listed.get(dir);
32416
32424
  if (known !== void 0) return known;
32417
32425
  const listing = (async () => {
32418
- const above = dir === "/" ? void 0 : await list(parentOf9(dir));
32419
- if (above === null) return null;
32420
- const handle = dir === "/" ? this.root : above?.get(baseOf3(dir));
32426
+ const above2 = dir === "/" ? void 0 : await list(parentOf9(dir));
32427
+ if (above2 === null) return null;
32428
+ const handle = dir === "/" ? this.root : above2?.get(baseOf3(dir));
32421
32429
  if (handle?.kind !== "directory") return void 0;
32422
32430
  this.calls++;
32423
32431
  const children3 = /* @__PURE__ */ new Map();
@@ -33552,9 +33560,10 @@ function openInProcess(spec, ports = messageChannel) {
33552
33560
  const driver = spec[IN_PROCESS_DRIVER];
33553
33561
  if (!driver) return void 0;
33554
33562
  const { port1, port2 } = ports();
33555
- driver.served?.(
33556
- serveFilesystem(port2, driver.handlers, driver.capabilities ?? {}, { owned: true })
33557
- );
33563
+ const served2 = serveFilesystem(port2, driver.handlers, driver.capabilities ?? {}, {
33564
+ owned: true
33565
+ });
33566
+ driver.served?.(served2);
33558
33567
  return {
33559
33568
  port: port1,
33560
33569
  dispose: () => {
@@ -37541,9 +37550,9 @@ var Launcher = class {
37541
37550
  const report = (message3) => stderr(encoder10.encode(`${message3}
37542
37551
  `));
37543
37552
  if (!planned) {
37544
- const directory = await this.directory(file, this.fs.resolvePath(cwd, file));
37545
- report(`${file}: ${directory ? "Is a directory" : "command not found"}`);
37546
- const status2 = directory ? NOT_EXECUTABLE : NOT_FOUND;
37553
+ const directory2 = await this.directory(file, this.fs.resolvePath(cwd, file));
37554
+ report(`${file}: ${directory2 ? "Is a directory" : "command not found"}`);
37555
+ const status2 = directory2 ? NOT_EXECUTABLE : NOT_FOUND;
37547
37556
  return { status: status2, stdout: concat7(out), stderr: concat7(err) };
37548
37557
  }
37549
37558
  const fds = new FdTable();
@@ -41781,12 +41790,41 @@ function unrefTimer(timer) {
41781
41790
  return timer;
41782
41791
  }
41783
41792
  var MAX_IO = 1024 * 1024;
41793
+ var MAX_LINKS8 = 40;
41784
41794
  var ATTR_TTL = 1e3;
41785
41795
  var BUFFER_BYTES = 1024 * 1024;
41786
41796
  var FILL_STEP = 512 * 1024;
41787
41797
  var TYPE_BITS = { file: 32768, directory: 16384, symlink: 40960, fifo: 4096 };
41788
41798
  var kindOf2 = (st) => st.isDirectory ? "directory" : st.isSymbolicLink ? "symlink" : "file";
41789
41799
  var codeOf9 = (err) => err?.code;
41800
+ var READ_ONLY_MOUNTS = "SELECT root FROM _vfs_mounts WHERE mode = 'read-only'";
41801
+ function workspaceReadOnlyRoots(db) {
41802
+ try {
41803
+ return db.all(READ_ONLY_MOUNTS).map((row) => row.root).filter((root) => typeof root === "string" && root.startsWith("/"));
41804
+ } catch {
41805
+ return [];
41806
+ }
41807
+ }
41808
+ function readOnlyOf(fs, options) {
41809
+ const option = options.readOnly;
41810
+ if (typeof option === "function") return option;
41811
+ if (option) return () => option;
41812
+ const db = options.db ?? fs.db;
41813
+ return db && typeof db.all === "function" ? () => workspaceReadOnlyRoots(db) : () => [];
41814
+ }
41815
+ var atOrBelow = (path, root) => root === "/" || path === root || path.startsWith(`${root}/`);
41816
+ var above = (path, root) => path !== root && root.startsWith(path === "/" ? "/" : `${path}/`);
41817
+ var parentOf12 = (path) => path.slice(0, path.lastIndexOf("/")) || "/";
41818
+ var joinPath = (dir, name2) => dir === "/" ? `/${name2}` : `${dir}/${name2}`;
41819
+ function normalized(path) {
41820
+ const parts2 = [];
41821
+ for (const name2 of path.split("/")) {
41822
+ if (name2 === "" || name2 === ".") continue;
41823
+ if (name2 === "..") parts2.pop();
41824
+ else parts2.push(name2);
41825
+ }
41826
+ return `/${parts2.join("/")}`;
41827
+ }
41790
41828
  function attrOf2(st) {
41791
41829
  const kind = kindOf2(st);
41792
41830
  const perms = kind === "symlink" ? 511 : st.mode & 4095;
@@ -41947,11 +41985,57 @@ var DriverState = class {
41947
41985
  oldest;
41948
41986
  tail = Promise.resolve();
41949
41987
  behind;
41950
- constructor(fs, root, buffer, behind) {
41988
+ readOnly;
41989
+ dirs = /* @__PURE__ */ new Map();
41990
+ constructor(fs, root, buffer, behind, readOnly) {
41951
41991
  this.fs = fs;
41952
41992
  this.root = root;
41953
41993
  this.buffer = buffer;
41954
41994
  this.behind = behind;
41995
+ this.readOnly = readOnly;
41996
+ }
41997
+ async readonlyAt(at) {
41998
+ return this.below(at, atOrBelow);
41999
+ }
42000
+ async below(at, hits) {
42001
+ const roots = this.readOnly();
42002
+ if (roots.length === 0) return false;
42003
+ if (roots.some((root) => hits(at, root))) return true;
42004
+ if (at === "/") return false;
42005
+ const real2 = joinPath(await this.realDir(parentOf12(at)), at.slice(at.lastIndexOf("/") + 1));
42006
+ return real2 !== at && roots.some((root) => hits(real2, root));
42007
+ }
42008
+ async refuseBelow(at, path) {
42009
+ if (await this.below(at, atOrBelow)) throw fsError2("EROFS", path);
42010
+ }
42011
+ async refuseOver(at, path) {
42012
+ const over = (real2, root) => atOrBelow(real2, root) || above(real2, root);
42013
+ if (await this.below(at, over)) throw fsError2("EROFS", path);
42014
+ }
42015
+ forgetDirs() {
42016
+ this.dirs.clear();
42017
+ }
42018
+ realDir(dir, hops = 0) {
42019
+ if (dir === "/") return Promise.resolve("/");
42020
+ if (hops > 0) return this.resolveDir(dir, hops);
42021
+ let real2 = this.dirs.get(dir);
42022
+ if (!real2) {
42023
+ real2 = this.resolveDir(dir, hops).catch(() => dir);
42024
+ this.dirs.set(dir, real2);
42025
+ }
42026
+ return real2;
42027
+ }
42028
+ async resolveDir(dir, hops) {
42029
+ const parent = await this.realDir(parentOf12(dir), hops);
42030
+ const at = joinPath(parent, dir.slice(dir.lastIndexOf("/") + 1));
42031
+ const st = await this.fs.lstat(at).catch(() => void 0);
42032
+ if (!st?.isSymbolicLink) return at;
42033
+ if (hops >= MAX_LINKS8) throw fsError2("ELOOP", dir);
42034
+ const target = await this.fs.readlink(at);
42035
+ return this.realDir(
42036
+ normalized(target.startsWith("/") ? target : `${parent}/${target}`),
42037
+ hops + 1
42038
+ );
41955
42039
  }
41956
42040
  writing(path) {
41957
42041
  return [...this.handles.values()].some((o) => o.path === path && o.drafting);
@@ -42085,7 +42169,8 @@ var DriverState = class {
42085
42169
  mode: 32768 | (draft?.mode ?? 420)
42086
42170
  };
42087
42171
  const attr2 = attrOf2(st);
42088
- return draft ? { ...attr2, size: draft.size, mtime: Date.now() } : attr2;
42172
+ const ro = await this.readonlyAt(at) ? { readonly: true } : {};
42173
+ return draft ? { ...attr2, size: draft.size, mtime: Date.now(), ...ro } : { ...attr2, ...ro };
42089
42174
  }
42090
42175
  async readdir(path) {
42091
42176
  const at = this.full(path);
@@ -42134,6 +42219,8 @@ var DriverState = class {
42134
42219
  const pending = !st && this.drafts.get(at)?.created === true;
42135
42220
  if ((st || pending) && flags2.exclusive) throw fsError2("EEXIST", path);
42136
42221
  if (st?.isDirectory && flags2.write) throw fsError2("EISDIR", path);
42222
+ if (!st && !pending && !flags2.create) throw fsError2("ENOENT", path);
42223
+ if (flags2.write || flags2.truncate || !st && !pending) await this.refuseBelow(at, path);
42137
42224
  let drafting = false;
42138
42225
  if (pending) {
42139
42226
  drafting = true;
@@ -42175,6 +42262,7 @@ var DriverState = class {
42175
42262
  }
42176
42263
  async rmdir(path) {
42177
42264
  const at = this.full(path);
42265
+ await this.refuseBelow(at, path);
42178
42266
  const st = await this.fs.lstat(at);
42179
42267
  if (!st.isDirectory) throw fsError2("ENOTDIR", path);
42180
42268
  if (path === "/") throw fsError2("EBUSY", "the root of a mount");
@@ -42184,6 +42272,7 @@ var DriverState = class {
42184
42272
  }
42185
42273
  async unlink(path) {
42186
42274
  const at = this.full(path);
42275
+ await this.refuseBelow(at, path);
42187
42276
  const draft = this.drafts.get(at);
42188
42277
  if (draft && !this.writing(at)) {
42189
42278
  this.drafts.delete(at);
@@ -42199,18 +42288,42 @@ var DriverState = class {
42199
42288
  async rename(from, to) {
42200
42289
  const a = this.full(from);
42201
42290
  const b = this.full(to);
42291
+ await this.refuseOver(a, from);
42292
+ await this.refuseOver(b, to);
42202
42293
  await this.finishUnder(a);
42203
42294
  await this.finishUnder(b);
42204
42295
  await this.fs.rename(a, b);
42205
42296
  }
42206
42297
  async link(from, to) {
42207
42298
  const a = this.full(from);
42299
+ await this.refuseBelow(this.full(to), to);
42208
42300
  await this.finish(a);
42209
42301
  if (!this.fs.link) throw fsError2("EPERM", "this file system has no hard links");
42210
42302
  await this.fs.link(a, this.full(to));
42211
42303
  }
42304
+ async mkdir(path) {
42305
+ const at = this.full(path);
42306
+ await this.refuseBelow(at, path);
42307
+ await this.finish(at);
42308
+ if (this.readOnly().some((root) => above(at, root))) {
42309
+ await this.fs.lstat(at).then(
42310
+ () => {
42311
+ throw fsError2("EEXIST", path);
42312
+ },
42313
+ () => void 0
42314
+ );
42315
+ }
42316
+ await this.fs.mkdir(at);
42317
+ }
42318
+ async symlink(target, path) {
42319
+ const at = this.full(path);
42320
+ await this.refuseBelow(at, path);
42321
+ await this.finish(at);
42322
+ await this.fs.symlink(target, at);
42323
+ }
42212
42324
  async setattr(path, change) {
42213
42325
  const at = this.full(path);
42326
+ await this.refuseBelow(at, path);
42214
42327
  if (change.size !== void 0) await this.truncateTo(at, change.size);
42215
42328
  if (change.mode === void 0) return;
42216
42329
  const mode = change.mode & 4095;
@@ -42222,15 +42335,25 @@ var DriverState = class {
42222
42335
  }
42223
42336
  }
42224
42337
  };
42338
+ async function directory(fs, path) {
42339
+ try {
42340
+ return (await fs.stat(path)).isDirectory;
42341
+ } catch (err) {
42342
+ if (codeOf9(err) === "ENOENT") return false;
42343
+ throw err;
42344
+ }
42345
+ }
42225
42346
  function workspaceDriver(fs, options = {}) {
42226
42347
  const root = (options.root ?? "/").replace(/\/+$/, "");
42227
42348
  const state = new DriverState(
42228
42349
  fs,
42229
42350
  root,
42230
42351
  options.bufferBytes ?? BUFFER_BYTES,
42231
- writeBehindOf(options.writeBehind)
42352
+ writeBehindOf(options.writeBehind),
42353
+ readOnlyOf(fs, options)
42232
42354
  );
42233
42355
  const serial = (work) => state.serial(work);
42356
+ const changing = (work) => serial(() => work().finally(() => state.forgetDirs()));
42234
42357
  let served2;
42235
42358
  const capabilities = {
42236
42359
  symlinks: true,
@@ -42249,9 +42372,12 @@ function workspaceDriver(fs, options = {}) {
42249
42372
  served: (next3) => {
42250
42373
  served2 = next3;
42251
42374
  },
42252
- invalidate: (paths) => served2?.invalidate(paths ?? true),
42375
+ invalidate: (paths) => {
42376
+ state.forgetDirs();
42377
+ served2?.invalidate(paths ?? true);
42378
+ },
42253
42379
  mount: () => serial(async () => {
42254
- if (root) await fs.mkdir(root, { recursive: true });
42380
+ if (root && !await directory(fs, root)) await fs.mkdir(root, { recursive: true });
42255
42381
  return void 0;
42256
42382
  }),
42257
42383
  getattr: (path) => serial(() => state.getattr(path)),
@@ -42260,18 +42386,12 @@ function workspaceDriver(fs, options = {}) {
42260
42386
  read: (fh, offset, size) => serial(() => state.read(fh, offset, size)),
42261
42387
  write: (fh, offset, bytes) => serial(() => state.write(fh, offset, bytes)),
42262
42388
  release: (fh) => serial(() => state.release(fh)),
42263
- mkdir: (path) => serial(async () => {
42264
- await state.finish(state.full(path));
42265
- await fs.mkdir(state.full(path));
42266
- }),
42267
- rmdir: (path) => serial(() => state.rmdir(path)),
42268
- unlink: (path) => serial(() => state.unlink(path)),
42269
- rename: (from, to) => serial(() => state.rename(from, to)),
42389
+ mkdir: (path) => changing(() => state.mkdir(path)),
42390
+ rmdir: (path) => changing(() => state.rmdir(path)),
42391
+ unlink: (path) => changing(() => state.unlink(path)),
42392
+ rename: (from, to) => changing(() => state.rename(from, to)),
42270
42393
  ...fs.link ? { link: (from, to) => serial(() => state.link(from, to)) } : {},
42271
- symlink: (target, path) => serial(async () => {
42272
- await state.finish(state.full(path));
42273
- await fs.symlink(target, state.full(path));
42274
- }),
42394
+ symlink: (target, path) => changing(() => state.symlink(target, path)),
42275
42395
  readlink: (path) => serial(async () => {
42276
42396
  if (state.drafts.get(state.full(path))?.created) throw fsError2("EINVAL", path);
42277
42397
  return fs.readlink(state.full(path));
@@ -42535,7 +42655,11 @@ function sliccBackend(options) {
42535
42655
  const kernel = await options.kernel();
42536
42656
  const held = holdersOf(kernel);
42537
42657
  await held.get(mountPoint)?.();
42538
- const driver = workspaceDriver(host.fs, { root, writeBehind: options.writeBehind ?? true });
42658
+ const driver = workspaceDriver(host.fs, {
42659
+ root,
42660
+ writeBehind: options.writeBehind ?? true,
42661
+ ...host.db ? { db: host.db } : {}
42662
+ });
42539
42663
  const client2 = await attachKernel(
42540
42664
  await kernel.connect(options.user !== void 0 ? { user: options.user } : {}),
42541
42665
  { locks: null }
@@ -42890,6 +43014,8 @@ export {
42890
43014
  compiledTlsEngine,
42891
43015
  createCloudflareKernel,
42892
43016
  fetchTransport,
43017
+ fsError2 as fsError,
43018
+ inProcessMount,
42893
43019
  isSqliteRoot,
42894
43020
  memoryRoot,
42895
43021
  sliccBackend,