@ai-ecoverse/slicc-kernel 1.117.4 → 1.118.0

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.
@@ -870,22 +870,54 @@ var RemoteWatch = class {
870
870
  mine = [];
871
871
  seq = 0;
872
872
  pruned = 0;
873
+ joined;
874
+ met;
875
+ quiet;
873
876
  constructor(name2, options = {}) {
874
877
  this.name = name2;
875
878
  this.locks = options.locks === void 0 ? lockManager() : options.locks ?? void 0;
876
879
  this.channel = new BroadcastChannel(name2);
877
880
  this.channel.onmessage = ({ data }) => this.receive(data);
878
881
  this.channel.unref?.();
879
- void this.locks?.request(this.lockOf(this.tab), () => new Promise(() => {
880
- }));
882
+ const granted2 = new Promise((resolve2) => {
883
+ void this.locks?.request(this.lockOf(this.tab), () => {
884
+ resolve2();
885
+ return new Promise(() => {
886
+ });
887
+ });
888
+ if (!this.locks) resolve2();
889
+ });
890
+ this.joined = granted2.then(() => this.join());
881
891
  this.channel.postMessage({ hello: this.tab });
882
892
  }
893
+ async join() {
894
+ if (!this.locks) return;
895
+ const prefix = `${this.name}:`;
896
+ const mine = this.lockOf(this.tab);
897
+ const held = ((await this.locks.query()).held ?? []).map((lock) => lock.name ?? "");
898
+ if (!held.some((name2) => name2.startsWith(prefix) && name2 !== mine) || this.peers.size > 0)
899
+ return;
900
+ await new Promise((resolve2) => {
901
+ const timer = setTimeout(resolve2, ANNOUNCE_WAIT_MS);
902
+ this.met = () => {
903
+ clearTimeout(timer);
904
+ resolve2();
905
+ };
906
+ });
907
+ }
908
+ async peered() {
909
+ await this.joined;
910
+ return this.peers.size > 0;
911
+ }
883
912
  lockOf(tab) {
884
913
  return `${this.name}:${tab}`;
885
914
  }
886
915
  receive(data) {
887
916
  if (data.hello !== void 0) this.greeted(data.hello);
888
- if (data.here !== void 0 && data.to === this.tab) this.peers.add(data.here);
917
+ if (data.here !== void 0 && data.to === this.tab) {
918
+ this.peers.add(data.here);
919
+ this.met?.();
920
+ }
889
921
  if (data.tab !== void 0 && data.paths !== void 0) this.announced(data);
890
922
  if (data.ack !== void 0 && data.to === this.tab && data.from !== void 0) {
891
923
  this.acked(data.ack, data.from);
@@ -894,8 +926,12 @@ var RemoteWatch = class {
894
926
  }
895
927
  greeted(peer) {
896
928
  this.peers.add(peer);
897
- this.channel.postMessage({ here: this.tab, to: peer });
898
- if (this.mine.length > 0) void this.announce(this.mine);
929
+ const answer = () => {
930
+ this.channel.postMessage({ here: this.tab, to: peer });
931
+ if (this.mine.length > 0) void this.announce(this.mine);
932
+ };
933
+ if (this.quiet) void this.quiet().then(answer, answer);
934
+ else answer();
899
935
  }
900
936
  announced({ tab, paths, seq: seq2 }) {
901
937
  const from = tab;
@@ -1155,6 +1191,7 @@ var OpfsFs = class {
1155
1191
  this.lockPrefix = `slicc-excl:${channel ?? ""}:`;
1156
1192
  this.channel = channel === void 0 ? void 0 : new BroadcastChannel(channel);
1157
1193
  this.remote = channel === void 0 ? void 0 : new RemoteWatch(`${channel}:watch`);
1194
+ if (this.remote) this.remote.quiet = () => this.quiet();
1158
1195
  if (this.channel) {
1159
1196
  const remote = this.remote;
1160
1197
  meta.listen?.(
@@ -1298,8 +1335,24 @@ var OpfsFs = class {
1298
1335
  throw fsError("EROFS", path);
1299
1336
  }
1300
1337
  }
1338
+ unlocked = 0;
1339
+ idle = [];
1340
+ async alone(op) {
1341
+ this.unlocked++;
1342
+ try {
1343
+ return await op();
1344
+ } finally {
1345
+ this.unlocked--;
1346
+ if (this.unlocked === 0) for (const done4 of this.idle.splice(0)) done4();
1347
+ }
1348
+ }
1349
+ quiet() {
1350
+ if (this.unlocked === 0) return Promise.resolve();
1351
+ return new Promise((resolve2) => this.idle.push(resolve2));
1352
+ }
1301
1353
  async locked(physicalPath, op) {
1302
1354
  if (!this.locks) return op();
1355
+ if (this.remote && !await this.remote.peered()) return this.alone(op);
1303
1356
  const key = `${this.lockPrefix}${physicalPath}`;
1304
1357
  let result;
1305
1358
  await this.locks.request(key, async () => {
@@ -6311,7 +6364,7 @@ function satisfies(version, range2) {
6311
6364
  }
6312
6365
 
6313
6366
  // src/version.ts
6314
- var KERNEL_VERSION = true ? "1.117.4" : "0.0.0-dev";
6367
+ var KERNEL_VERSION = true ? "1.118.0" : "0.0.0-dev";
6315
6368
  var OS_RELEASE = "6.0.0-slicc";
6316
6369
  function procVersion() {
6317
6370
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -8815,6 +8868,7 @@ function withCommandDirs(fs, names, userDir = async () => void 0, owners = false
8815
8868
  readlink: (path) => fs.readlink(path),
8816
8869
  ...fs.realpath ? { realpath: fs.realpath.bind(fs) } : {},
8817
8870
  ...fs.chown ? { chown: fs.chown.bind(fs) } : {},
8871
+ ...fs.createExclusive ? { createExclusive: fs.createExclusive.bind(fs) } : {},
8818
8872
  ...fs.ancestry ? { ancestry: fs.ancestry.bind(fs) } : {},
8819
8873
  ...fs.hasOwner ? { hasOwner: fs.hasOwner.bind(fs) } : {},
8820
8874
  chmod: (path, mode) => fs.chmod(path, mode),
@@ -9114,6 +9168,7 @@ var FsWatchers = class {
9114
9168
  };
9115
9169
  const overrides = {
9116
9170
  writeFile: content(fs.writeFile.bind(fs)),
9171
+ ...fs.createExclusive ? { createExclusive: content(fs.createExclusive.bind(fs)) } : {},
9117
9172
  mkdir: async (path, options) => {
9118
9173
  const created3 = [];
9119
9174
  if (options?.recursive) {
@@ -9765,7 +9820,7 @@ var FifoTable = class {
9765
9820
  };
9766
9821
 
9767
9822
  // src/mount/protocol.ts
9768
- var DRIVER_PROTOCOL = [1, 2];
9823
+ var DRIVER_PROTOCOL = [1, 3];
9769
9824
  function driverVersionError(theirs) {
9770
9825
  const major = Array.isArray(theirs) ? theirs[0] : void 0;
9771
9826
  if (major === DRIVER_PROTOCOL[0]) return void 0;
@@ -10077,11 +10132,12 @@ function inodeless(mount, attr2) {
10077
10132
  }
10078
10133
  function statOf(attr2, path, mount) {
10079
10134
  const mtime = new Date(attr2.mtime);
10080
- const fallback = attr2.kind === "directory" ? 16877 : attr2.kind === "symlink" ? 41471 : 33188;
10135
+ const fallback = attr2.kind === "directory" ? 16877 : attr2.kind === "symlink" ? 41471 : attr2.kind === "fifo" ? 4516 : 33188;
10081
10136
  return {
10082
10137
  isFile: attr2.kind === "file",
10083
10138
  isDirectory: attr2.kind === "directory",
10084
10139
  isSymbolicLink: attr2.kind === "symlink",
10140
+ ...attr2.kind === "fifo" ? { isFifo: true } : {},
10085
10141
  size: attr2.size,
10086
10142
  mode: attr2.mode ?? fallback,
10087
10143
  mtime,
@@ -10624,7 +10680,7 @@ var MountFs = class _MountFs {
10624
10680
  }
10625
10681
  const { mount, rel: rel2 } = found;
10626
10682
  this.writable(mount, real);
10627
- if (owner?.fifo) throw errnoError("EPERM", `${real}: this mount has no FIFOs`);
10683
+ if (owner?.fifo) return this.mkfifo(found, real, owner);
10628
10684
  const bytes = typeof content === "string" ? new TextEncoder().encode(content) : content;
10629
10685
  if (mount.maxFile > 0 && bytes.length > mount.maxFile) {
10630
10686
  throw errnoError(
@@ -10641,6 +10697,18 @@ var MountFs = class _MountFs {
10641
10697
  }
10642
10698
  }
10643
10699
  }
10700
+ async mkfifo(found, real, owner) {
10701
+ const { mount, rel: rel2 } = found;
10702
+ if (!mount.caps.fifos) throw errnoError("EPERM", `${real}: this mount has no FIFOs`);
10703
+ const made2 = await this.driverOwner(found, real, owner, false);
10704
+ await this.table.commit(real);
10705
+ this.table.forget(mount, real);
10706
+ try {
10707
+ await mount.conn.call({ op: "mkfifo", path: rel2, ...made2 });
10708
+ } finally {
10709
+ this.table.forget(mount, real);
10710
+ }
10711
+ }
10644
10712
  async writeWhole(mount, real, rel2, bytes, owner) {
10645
10713
  await this.table.commit(real);
10646
10714
  this.table.forget(mount, real);
@@ -10810,6 +10878,23 @@ var MountFs = class _MountFs {
10810
10878
  throw err;
10811
10879
  }
10812
10880
  }
10881
+ async createExclusive(path, owner, redirects = 0) {
10882
+ const exclusive = this.base.createExclusive?.bind(this.base);
10883
+ if (!this.at(path) && exclusive) {
10884
+ return this.based(
10885
+ [path],
10886
+ redirects,
10887
+ () => exclusive(path, owner),
10888
+ ([to], n) => this.createExclusive(to, owner, n)
10889
+ );
10890
+ }
10891
+ const there = await this.lstat(path).then(
10892
+ () => true,
10893
+ () => false
10894
+ );
10895
+ if (there) throw errnoError("EEXIST", path);
10896
+ await this.writeFile(path, new Uint8Array(0), owner);
10897
+ }
10813
10898
  async lstat(path, redirects = 0) {
10814
10899
  const found = this.at(path);
10815
10900
  if (!found) {
@@ -17046,7 +17131,10 @@ var VfsNodes = class {
17046
17131
  return this.onEntry(path, async () => {
17047
17132
  const node = this.byPath.get(path);
17048
17133
  const held = node ? await node.serial(async () => node.holds()) : false;
17049
- if (held || await present2(this.fs, path)) throw fsError("EEXIST", path);
17134
+ if (held) throw fsError("EEXIST", path);
17135
+ const exclusive = this.fs.createExclusive;
17136
+ if (exclusive) return exclusive.call(this.fs, path, owner);
17137
+ if (await present2(this.fs, path)) throw fsError("EEXIST", path);
17050
17138
  await this.fs.writeFile(path, new Uint8Array(0), owner);
17051
17139
  });
17052
17140
  }
@@ -20808,6 +20896,9 @@ async function dispatch(h, req) {
20808
20896
  case "link":
20809
20897
  if (!h.link) throw fsError2("EPERM", "this file system has no hard links");
20810
20898
  return h.link(req.from, req.to);
20899
+ case "mkfifo":
20900
+ if (!h.mkfifo) throw fsError2("EPERM", "this file system has no FIFOs");
20901
+ return ownerOf2(req) ? h.mkfifo(req.path, ownerOf2(req)) : h.mkfifo(req.path);
20811
20902
  case "symlink":
20812
20903
  if (!h.symlink) throw fsError2("EPERM", "this file system has no symlinks");
20813
20904
  return ownerOf2(req) ? h.symlink(req.target, req.path, ownerOf2(req)) : h.symlink(req.target, req.path);
@@ -21977,7 +22068,7 @@ function owned3(node, change) {
21977
22068
  function attr(node) {
21978
22069
  return {
21979
22070
  kind: node.kind,
21980
- size: node.kind === "file" ? node.data.size : node.kind === "symlink" ? node.target.length : 4096,
22071
+ size: node.kind === "file" ? node.data.size : node.kind === "symlink" ? node.target.length : node.kind === "fifo" ? 0 : 4096,
21981
22072
  mtime: node.mtime,
21982
22073
  atime: node.atime,
21983
22074
  mode: node.mode,
@@ -22026,6 +22117,7 @@ function tmpfs() {
22026
22117
  const existing = dir.children.get(name2);
22027
22118
  if (existing && flags2.exclusive) throw fsError2("EEXIST", path);
22028
22119
  if (existing?.kind === "directory" && flags2.write) throw fsError2("EISDIR", path);
22120
+ if (existing?.kind === "fifo") throw fsError2("ENXIO", path);
22029
22121
  if (existing) return existing;
22030
22122
  if (!flags2.create) throw fsError2("ENOENT", path);
22031
22123
  const node = make("file", 33188, dir, flags2.owner);
@@ -22070,6 +22162,11 @@ function tmpfs() {
22070
22162
  handle(fh);
22071
22163
  handles.delete(fh);
22072
22164
  },
22165
+ async mkfifo(path, owner) {
22166
+ const { dir, name: name2 } = parent(path);
22167
+ if (dir.children.has(name2)) throw fsError2("EEXIST", path);
22168
+ place(dir, name2, make("fifo", 4516, dir, owner));
22169
+ },
22073
22170
  async mkdir(path, owner) {
22074
22171
  const { dir, name: name2 } = parent(path);
22075
22172
  if (dir.children.has(name2)) throw fsError2("EEXIST", path);
@@ -24451,6 +24548,7 @@ var Launcher = class {
24451
24548
  {
24452
24549
  symlinks: true,
24453
24550
  links: true,
24551
+ fifos: true,
24454
24552
  chmod: true,
24455
24553
  owners: true,
24456
24554
  linkTimes: true,