@ai-ecoverse/slicc-kernel 1.29.1 → 1.29.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.
@@ -694,6 +694,22 @@ function createHelpers(Fs, ops) {
694
694
  function createNodeOps(h) {
695
695
  const { Fs, bridgeOf, call: call2, metadataCall, makeNode, statOf, childPath, flushNode, truncate } = h;
696
696
  const { ensureLoaded } = h;
697
+ const setTimes = (node, path, atime, mtime) => {
698
+ if (Fs.isLink(node.mode)) {
699
+ metadataCall(() => bridgeOf(node).lutimes(path, atime, mtime));
700
+ return;
701
+ }
702
+ flushNode(node);
703
+ metadataCall(() => bridgeOf(node).utimes(path, atime, mtime));
704
+ };
705
+ const timesOf = (node, attr2) => {
706
+ const mtime = toMs(attr2.mtime) ?? attr2.timestamp;
707
+ const atime = toMs(attr2.atime);
708
+ if (mtime !== void 0 && attr2.atime !== null) return [atime ?? mtime, mtime];
709
+ if (atime === void 0 && mtime === void 0) return void 0;
710
+ const st = statOf(node);
711
+ return [atime ?? st.atimeMs ?? st.mtimeMs ?? 0, mtime ?? st.mtimeMs ?? 0];
712
+ };
697
713
  return {
698
714
  getattr(node) {
699
715
  const st = statOf(node);
@@ -735,12 +751,8 @@ function createNodeOps(h) {
735
751
  if (attr2.size !== void 0 && attr2.size !== null && Fs.isFile(node.mode)) {
736
752
  truncate(node, attr2.size);
737
753
  }
738
- const mtime = toMs(attr2.mtime) ?? attr2.timestamp;
739
- if (mtime !== void 0) {
740
- const atime = toMs(attr2.atime) ?? mtime;
741
- flushNode(node);
742
- metadataCall(() => bridgeOf(node).utimes(path, atime, mtime));
743
- }
754
+ const times = timesOf(node, attr2);
755
+ if (times) setTimes(node, path, ...times);
744
756
  node.live.stat = void 0;
745
757
  },
746
758
  lookup(parent, name) {
@@ -1451,6 +1463,9 @@ function createSyncFsSabBridge(transport, opts = {}) {
1451
1463
  utimes: (path, atimeMs, mtimeMs) => {
1452
1464
  run({ op: "utimes", path, atimeMs, mtimeMs }, path);
1453
1465
  },
1466
+ lutimes: (path, atimeMs, mtimeMs) => {
1467
+ run({ op: "lutimes", path, atimeMs, mtimeMs }, path);
1468
+ },
1454
1469
  hold: (path, held) => {
1455
1470
  run({ op: "hold", path, mode: held ? 1 : 0 }, path);
1456
1471
  },
@@ -2267,6 +2282,32 @@ function wrapCloexecSyscalls(imports, glue, deps) {
2267
2282
  }
2268
2283
  }
2269
2284
  }
2285
+ function noFollowUtimes(imports, fs, glue) {
2286
+ for (const namespace of namespaces(imports)) {
2287
+ const key = Object.keys(namespace).find(
2288
+ (name) => glue !== void 0 && namespace[name] === glue || name === "__syscall_utimensat"
2289
+ );
2290
+ const utimensat = key === void 0 ? void 0 : namespace[key];
2291
+ if (key === void 0 || typeof utimensat !== "function") continue;
2292
+ namespace[key] = (dirfd, path, times, flags) => {
2293
+ const Fs = fs();
2294
+ const { utime, lookupPath, ErrnoError } = Fs ?? {};
2295
+ if (!Fs || !(flags & AT_SYMLINK_NOFOLLOW) || !utime || !lookupPath || !ErrnoError) {
2296
+ return utimensat(dirfd, path, times, flags);
2297
+ }
2298
+ Fs.utime = (at, atime, mtime) => {
2299
+ const { node } = lookupPath.call(Fs, at, { follow: false });
2300
+ if (!node.node_ops.setattr) throw new ErrnoError(EMSCRIPTEN_EPERM);
2301
+ node.node_ops.setattr(node, { atime, mtime });
2302
+ };
2303
+ try {
2304
+ return utimensat(dirfd, path, times, flags);
2305
+ } finally {
2306
+ Fs.utime = utime;
2307
+ }
2308
+ };
2309
+ }
2310
+ }
2270
2311
  function errnoOf(err) {
2271
2312
  const { errno: errno2, code: code2 } = err ?? {};
2272
2313
  if (typeof errno2 === "number") return errno2;
@@ -2515,7 +2556,7 @@ function useMounts(Fs, env = {}, live = false) {
2515
2556
  }
2516
2557
  };
2517
2558
  }
2518
- var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, DIR_MODE, LINK_MODE, O_ACCMODE, O_CREAT2, field, NAME;
2559
+ var O_CLOEXEC, FD_CLOEXEC, F_DUPFD, F_GETFD, F_SETFD, F_GETFL, F_DUPFD_CLOEXEC, tracked, IMPORT_NAMES, EBADF, AT_SYMLINK_NOFOLLOW, EMSCRIPTEN_EPERM, DIR_MODE, LINK_MODE, O_ACCMODE, O_CREAT2, field, NAME;
2519
2560
  var init_process_fds = __esm({
2520
2561
  "src/process/process-fds.ts"() {
2521
2562
  "use strict";
@@ -2540,6 +2581,8 @@ var init_process_fds = __esm({
2540
2581
  setitimer: "_setitimer_js"
2541
2582
  };
2542
2583
  EBADF = 8;
2584
+ AT_SYMLINK_NOFOLLOW = 256;
2585
+ EMSCRIPTEN_EPERM = 63;
2543
2586
  DIR_MODE = 16749;
2544
2587
  LINK_MODE = 41408;
2545
2588
  O_ACCMODE = 3;
@@ -3554,6 +3597,11 @@ async function runWasmProcess(init, port, deps = {}) {
3554
3597
  }
3555
3598
  });
3556
3599
  liveParent(imports, () => identify(transport, init).ppid);
3600
+ noFollowUtimes(
3601
+ imports,
3602
+ () => ownValue(module, "FS"),
3603
+ ownValue(module, "sliccSyscalls")?.utimensat
3604
+ );
3557
3605
  const glue = ownValue(module, "sliccFdImports");
3558
3606
  syncFsync(imports, () => ownValue(module, "FS"), glue);
3559
3607
  positionalIo(imports, {
@@ -3902,6 +3950,7 @@ function cachingBridge(bridge, now = () => performance.now()) {
3902
3950
  symlink: (target, link) => mutating(() => bridge.symlink(target, link)),
3903
3951
  chmod: (p, mode) => mutating(() => bridge.chmod(p, mode)),
3904
3952
  utimes: (p, a, m) => mutating(() => bridge.utimes(p, a, m)),
3953
+ lutimes: (p, a, m) => mutating(() => bridge.lutimes(p, a, m)),
3905
3954
  ...bridge.pread && bridge.pwrite && bridge.truncate ? {
3906
3955
  pread: bridge.pread.bind(bridge),
3907
3956
  pwrite: (p, at, bytes, transfer) => mutating(() => bridge.pwrite?.(p, at, bytes, transfer)),
@@ -5034,10 +5083,10 @@ var init_wasi_host = __esm({
5034
5083
  return {
5035
5084
  path_open: (dirfd, _lookup, p, l, oflags, rights, _inheriting, fdflags, out) => void mem.view().setUint32(out, fds.open(at(dirfd, p, l), oflags, rights, fdflags), true),
5036
5085
  path_filestat_get: (dirfd, lookup, p, l, out) => void this.writeFilestat(out, this.pathFilestat(at(dirfd, p, l), lookup)),
5037
- path_filestat_set_times: (dirfd, _lookup, p, l, atim, mtim, flags) => {
5086
+ path_filestat_set_times: (dirfd, lookup, p, l, atim, mtim, flags) => {
5038
5087
  const path = at(dirfd, p, l);
5039
5088
  fds.flushPath(path);
5040
- this.setTimes(path, atim, mtim, flags);
5089
+ this.setTimes(path, atim, mtim, flags, (lookup & LOOKUP_SYMLINK_FOLLOW) !== 0);
5041
5090
  },
5042
5091
  path_create_directory: (dirfd, p, l) => {
5043
5092
  const path = at(dirfd, p, l);
@@ -5270,15 +5319,20 @@ var init_wasi_host = __esm({
5270
5319
  const follow = (lookup & LOOKUP_SYMLINK_FOLLOW) !== 0;
5271
5320
  return filestatOf(path, follow ? this.o.fs.stat(path) : this.o.fs.lstat(path));
5272
5321
  }
5273
- setTimes(path, atim, mtim, flags) {
5322
+ setTimes(path, atim, mtim, flags, follow = true) {
5274
5323
  const now = Date.now();
5275
5324
  let current;
5276
- const kept = () => current ??= this.o.fs.stat(path).mtimeMs ?? now;
5277
- const pick = (set, setNow, value2) => flags & setNow ? now : flags & set ? Number(value2 / NS_PER_MS) : kept();
5278
- this.o.fs.utimes(
5325
+ const statOf = follow ? this.o.fs.stat.bind(this.o.fs) : this.o.fs.lstat.bind(this.o.fs);
5326
+ const kept = (field2) => {
5327
+ current ??= statOf(path);
5328
+ return current[field2] ?? current.mtimeMs ?? now;
5329
+ };
5330
+ const pick = (set, setNow, value2, field2) => flags & setNow ? now : flags & set ? Number(value2 / NS_PER_MS) : kept(field2);
5331
+ (follow ? this.o.fs.utimes : this.o.fs.lutimes).call(
5332
+ this.o.fs,
5279
5333
  path,
5280
- pick(FSTFLAGS.ATIM, FSTFLAGS.ATIM_NOW, atim),
5281
- pick(FSTFLAGS.MTIM, FSTFLAGS.MTIM_NOW, mtim)
5334
+ pick(FSTFLAGS.ATIM, FSTFLAGS.ATIM_NOW, atim, "atimeMs"),
5335
+ pick(FSTFLAGS.MTIM, FSTFLAGS.MTIM_NOW, mtim, "mtimeMs")
5282
5336
  );
5283
5337
  }
5284
5338
  readdir(fd, buf, len, cookie, usedPtr) {