@ai-ecoverse/slicc-kernel 1.36.0 → 1.37.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.
@@ -691,7 +691,7 @@ function createHelpers(Fs, ops) {
691
691
  if (s.ranged) call2(() => s.ranged?.flush());
692
692
  else {
693
693
  const bytes = s.data.slice(0, s.len);
694
- call2(() => bridgeOf(node).writeFile(liveNodePath(node), bytes));
694
+ call2(() => bridgeOf(node).writeFile(liveNodePath(node), bytes, true));
695
695
  }
696
696
  s.dirty = false;
697
697
  s.stat = void 0;
@@ -920,6 +920,12 @@ function createStreamOps(h) {
920
920
  }
921
921
  }
922
922
  };
923
+ const opened = (node, on) => {
924
+ try {
925
+ bridgeOf(node).hold?.(liveNodePath(node), on, true);
926
+ } catch {
927
+ }
928
+ };
923
929
  return {
924
930
  open(stream) {
925
931
  if (!Fs.isFile(stream.node.mode)) return;
@@ -927,6 +933,7 @@ function createStreamOps(h) {
927
933
  if (s.openCount === 0 && !s.orphan) {
928
934
  const bridge = bridgeOf(stream.node);
929
935
  s.ranges = !!(bridge.pread && bridge.pwrite && bridge.truncate && statOf(stream.node).ranged);
936
+ rangedOf(stream.node);
930
937
  }
931
938
  if ((stream.flags & 3) !== 0) {
932
939
  try {
@@ -939,6 +946,7 @@ function createStreamOps(h) {
939
946
  }
940
947
  }
941
948
  stream.node.live.openCount++;
949
+ if (stream.node.live.openCount === 1) opened(stream.node, true);
942
950
  held(stream, 1);
943
951
  },
944
952
  dup(stream) {
@@ -964,6 +972,7 @@ function createStreamOps(h) {
964
972
  s.len = 0;
965
973
  s.loaded = false;
966
974
  held(stream, -1);
975
+ opened(node, false);
967
976
  }
968
977
  },
969
978
  read(stream, buffer, offset, length, position) {
@@ -1053,7 +1062,7 @@ function flushLiveVfs(Fs, plugin) {
1053
1062
  if (s.ranged) s.ranged.flush();
1054
1063
  else {
1055
1064
  const bytes = s.data.slice(0, s.len);
1056
- node.mount.opts.bridge.writeFile(liveNodePath(node), bytes);
1065
+ node.mount.opts.bridge.writeFile(liveNodePath(node), bytes, true);
1057
1066
  }
1058
1067
  s.dirty = false;
1059
1068
  } catch (err) {
@@ -1490,8 +1499,8 @@ function createSyncFsSabBridge(transport, opts = {}) {
1490
1499
  }
1491
1500
  return {
1492
1501
  readFile: (path) => bytes({ op: "read", path }, path),
1493
- writeFile: (path, data) => {
1494
- run({ op: "write", path, body: data }, path);
1502
+ writeFile: (path, data, open) => {
1503
+ run({ op: "write", path, body: data, ...open ? { mode: 1 } : {} }, path);
1495
1504
  },
1496
1505
  stat: (path) => {
1497
1506
  const s = parseSyncFsStat(json({ op: "stat", path }, path));
@@ -1558,8 +1567,8 @@ function createSyncFsSabBridge(transport, opts = {}) {
1558
1567
  lutimes: (path, atimeMs, mtimeMs) => {
1559
1568
  run({ op: "lutimes", path, atimeMs, mtimeMs }, path);
1560
1569
  },
1561
- hold: (path, held) => {
1562
- run({ op: "hold", path, mode: held ? 1 : 0 }, path);
1570
+ hold: (path, held, open) => {
1571
+ run({ op: "hold", path, mode: (held ? 1 : 0) | (open ? 2 : 0) }, path);
1563
1572
  },
1564
1573
  statfs: (path = "/") => parseSyncFsUsage(json({ op: "statfs", path }, path)),
1565
1574
  pread: (path, offset, length, version) => bytes({ op: "pread", path, offset, length, ...version ? { version } : {} }, path),
@@ -4301,7 +4310,7 @@ function cachingBridge(bridge, now = () => performance.now()) {
4301
4310
  return false;
4302
4311
  }
4303
4312
  },
4304
- writeFile: (p, bytes) => mutating(() => bridge.writeFile(p, bytes)),
4313
+ writeFile: (p, bytes, open) => mutating(() => bridge.writeFile(p, bytes, open)),
4305
4314
  mkdir: (p) => mutating(() => bridge.mkdir(p)),
4306
4315
  rm: (p) => mutating(() => bridge.rm(p)),
4307
4316
  rename: (from, to) => mutating(() => bridge.rename(from, to)),
@@ -4311,6 +4320,7 @@ function cachingBridge(bridge, now = () => performance.now()) {
4311
4320
  chmod: (p, mode) => mutating(() => bridge.chmod(p, mode)),
4312
4321
  utimes: (p, a, m) => mutating(() => bridge.utimes(p, a, m)),
4313
4322
  lutimes: (p, a, m) => mutating(() => bridge.lutimes(p, a, m)),
4323
+ ...bridge.hold ? { hold: bridge.hold.bind(bridge) } : {},
4314
4324
  ...bridge.pread && bridge.pwrite && bridge.truncate ? {
4315
4325
  pread: bridge.pread.bind(bridge),
4316
4326
  pwrite: (p, at, bytes, transfer) => mutating(() => bridge.pwrite?.(p, at, bytes, transfer)),
@@ -4455,7 +4465,7 @@ var init_wasi_files = __esm({
4455
4465
  if (this.ranged) this.ranged.flush();
4456
4466
  else if (!this.data) return;
4457
4467
  else if (this.whole || !this.fs.pwrite)
4458
- this.fs.writeFile(this.path, this.data.slice(0, this.length));
4468
+ this.fs.writeFile(this.path, this.data.slice(0, this.length), true);
4459
4469
  else this.fs.pwrite(this.path, this.from, this.data.slice(this.from, this.to), true);
4460
4470
  this.dirty = false;
4461
4471
  this.whole = false;
@@ -4828,7 +4838,10 @@ var init_wasi_fds = __esm({
4828
4838
  this.table.set(fd, { type: "kernel", kind: "file", nonblock: false, append: e.file.append });
4829
4839
  }
4830
4840
  for (const file of promoted.keys()) {
4831
- if (--file.buffer.opens <= 0) this.buffers.delete(file.path);
4841
+ if (--file.buffer.opens <= 0) {
4842
+ this.buffers.delete(file.path);
4843
+ this.letGo(file.buffer);
4844
+ }
4832
4845
  }
4833
4846
  }
4834
4847
  snapshot() {
@@ -4896,9 +4909,12 @@ var init_wasi_fds = __esm({
4896
4909
  if (e.type !== "file" || --e.file.refs > 0) return;
4897
4910
  const { buffer } = e.file;
4898
4911
  buffer.flush();
4899
- if (--buffer.opens === 0 && this.buffers.get(buffer.path) === buffer) {
4900
- this.buffers.delete(buffer.path);
4901
- }
4912
+ if (--buffer.opens > 0) return;
4913
+ if (this.buffers.get(buffer.path) === buffer) this.buffers.delete(buffer.path);
4914
+ this.letGo(buffer);
4915
+ }
4916
+ letGo(buffer) {
4917
+ this.fs.hold?.(buffer.path, false, true);
4902
4918
  }
4903
4919
  kind(fd, e) {
4904
4920
  if (!e.kind) {
@@ -4989,6 +5005,7 @@ var init_wasi_fds = __esm({
4989
5005
  const ranged = st.ranged ? st.size : void 0;
4990
5006
  buffer = new FileBuffer(this.fs, path, empty, st.maxFile, ranged, st.version);
4991
5007
  this.buffers.set(path, buffer);
5008
+ this.fs.hold?.(path, true, true);
4992
5009
  }
4993
5010
  buffer.opens++;
4994
5011
  return new LocalFile(buffer, readable, writable, (fdflags & FDFLAGS.APPEND) !== 0);