@ai-ecoverse/slicc-kernel 1.60.1 → 1.60.2

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/README.md CHANGED
@@ -384,7 +384,7 @@ The proxy answers `200` with `Content-Type: application/vnd.slicc.raw-fetch`: a
384
384
 
385
385
  ## Filesystem
386
386
 
387
- `/` is the OPFS root. Each process mounts the top-level directories that exist when it starts (plus `/usr` and `/bin`), so files in them are shared by all processes and visible through the OPFS API as soon as the process that wrote them has closed them; `run` resolves only after that. `createKernel` creates `/tmp` and `/home` in OPFS, so they are shared too. Files directly in `/`, and directories created there after a process started, are OPFS as well, the same for Emscripten and WASI programs; only `/dev` and `/proc` live in each process's memory. An OPFS or IndexedDB failure that has no POSIX counterpart is `EIO`; its message names the DOM error and the operation (`lookup`, `read`, `write`, `commit` or `sidecar`), and the kernel worker logs the first of each kind to its console. File contents are buffered per open file and written back on close, `fsync` and exit; metadata operations (`mkdir`, `rename`, `rm`, …) go straight to OPFS. The kernel worker is the only writer.
387
+ `/` is the OPFS root. Each process mounts the top-level directories that exist when it starts (plus `/usr` and `/bin`), so files in them are shared by all processes and visible through the OPFS API as soon as the process that wrote them has closed them; `run` resolves only after that. `createKernel` creates `/tmp` and `/home` in OPFS, so they are shared too. Files directly in `/`, and directories created there after a process started, are OPFS as well, the same for Emscripten and WASI programs; only `/dev` and `/proc` live in each process's memory. A program's `mkdir` (WASI `path_create_directory`, Emscripten's `mkdir`) is exclusive, as on Linux: it fails with `EEXIST` when the name exists, and of several processes or threads making one name at once exactly one succeeds, so a directory works as a lock. Unlike Linux, a WASI program's `mkdir` under a missing directory makes the missing parents rather than failing with `ENOENT` (#380); a JS program's `ctx.fs.mkdir` makes parents too. An OPFS or IndexedDB failure that has no POSIX counterpart is `EIO`; its message names the DOM error and the operation (`lookup`, `read`, `write`, `commit` or `sidecar`), and the kernel worker logs the first of each kind to its console. File contents are buffered per open file and written back on close, `fsync` and exit; metadata operations (`mkdir`, `rename`, `rm`, …) go straight to OPFS. The kernel worker is the only writer.
388
388
 
389
389
  Directories are renamed with `FileSystemHandle.move()` where available, else by copy and delete.
390
390
 
@@ -7809,6 +7809,19 @@ function mkdirOptions(entry, mode = 511) {
7809
7809
  const parents = 511 & ~(entry.umask?.() ?? 18) | 192;
7810
7810
  return { recursive: true, owner: { ...owner, parents } };
7811
7811
  }
7812
+ async function mkdirExclusive(entry, path, mode) {
7813
+ const { fs } = entry;
7814
+ const { owner } = mkdirOptions(entry, mode);
7815
+ const own = owner ? { owner } : {};
7816
+ try {
7817
+ await fs.mkdir(path, own);
7818
+ } catch (err) {
7819
+ if (err?.code !== "ENOENT") throw err;
7820
+ const above = owner ? { owner: { ...owner, mode: owner.parents } } : {};
7821
+ await fs.mkdir(path.slice(0, path.lastIndexOf("/")) || "/", { recursive: true, ...above });
7822
+ await fs.mkdir(path, own);
7823
+ }
7824
+ }
7812
7825
  async function chown(entry, path, req) {
7813
7826
  const cred = entry.cred?.();
7814
7827
  if (!cred) {
@@ -7841,7 +7854,7 @@ async function run(entry, path, req) {
7841
7854
  case "readdir-stat":
7842
7855
  return json2(await readdirStat(fs, path));
7843
7856
  case "mkdir":
7844
- await fs.mkdir(path, mkdirOptions(entry, req.mode));
7857
+ await (req.exclusive ? mkdirExclusive(entry, path, req.mode) : fs.mkdir(path, mkdirOptions(entry, req.mode)));
7845
7858
  return done;
7846
7859
  case "rm":
7847
7860
  await fs.rm(path, { recursive: true });