Repository navigation
feat(core): add the file operations Node fs needs to Environment files - #64378
rekram1-node wants to merge 2 commits into
Conversation
…es, links, realpath and statfs to Environment files, and full stat metadata
There was a problem hiding this comment.
The change looks sound, with one problem in the GNU exec driver. On Linux, test/environment.test.ts passes 47/47 (including the GNU exec suite), the workspace tests pass, and typecheck:tsc passes in core.
Public API: unchanged. FileInfo's new optional fields, FilesystemInfo and the new FilesImpl operations are internal to @opencode/core, and nothing outside core implements FilesImpl.
One concern: in the GNU exec driver, symlink and link call ln without -T. When the destination is an existing directory (or a symlink to one), ln creates the link inside it and succeeds, while the local driver (Node) fails with EEXIST. Details are in the inline comments.
| [String(atimeMs / 1_000), String(mtimeMs / 1_000)], | ||
| ), | ||
| symlink: (target, path) => | ||
| run(path, `ln -s -- "$2" "$1"`, [target]).pipe(Effect.flatMap((result) => complete(path, result))), |
There was a problem hiding this comment.
When path is an existing directory, or a symlink to one, ln -s -- target dir creates dir/<basename of target> and exits 0. The local driver (fs.symlink) fails with EEXIST instead. I checked with coreutils 9.7: in a directory with d/, ln -s -- f d created d/f -> f. ln -sT -- "$2" "$1" (--no-target-directory) makes it fail the same way Node does.
Same problem for hard links: when path is an existing directory, ln -- "$1" "$2" links into it instead of failing like fs.link. ln -T fixes it here too.
There was a problem hiding this comment.
The earlier point is addressed: the GNU exec driver now uses ln -sT / ln -T, the memory driver also refuses an existing destination, and the conformance check covers both calls failing onto an existing directory. test/environment.test.ts passes 47/47 on Linux, including the GNU exec suite, and typecheck:tsc passes in core. Public API unchanged. No new concerns.
Issue for this PR
None.
Type of change
What does this PR do?
Environment.Files, the file layer every tool goes through, gains the operations Node'sfsneeds that it can't build from read/write/list today, andstatreports the rest of POSIX stat. This is groundwork for Code Mode'sfs(#61186) to cover the whole API. Nothing calls the new operations yet, so behavior doesn't change.interface FilesImpl { read, write, stat, list, remove, move, mkdir + append(path, bytes) // add to the end, create when missing + writeAt(path, bytes, offset) // positional write, no truncation (pwrite) + truncate(path, length) + chmod(path, mode) + chown(path, uid, gid, follow) // follow: false is lchown + utimes(path, atimeMs, mtimeMs, follow) // follow: false is lutimes + symlink(target, path) readlink(path) realpath(path) link(existing, path) + statfs(path) } FileInfo { type, size, mtimeMs + dev?, ino?, mode?, nlink?, uid?, gid?, rdev?, blksize?, blocks?, atimeMs?, ctimeMs?, birthtimeMs? }The new
FileInfofields are optional, so nothing that builds or reads one has to change.Each implementation gets them:
fscall.writeAtopens withO_RDWR | O_CREATso bytes outside the range stay.cat >>,dd oflag=seek_bytes conv=notrunc,truncate -s,chmod,chown [-h],touch -c [-h] -a/-m -d @t,ln [-s],readlink,realpath -e,stat -f.statasks for every field in one call. Times from GNUstatare whole seconds, asmtimeMsalready was.symlinkhelper, which tests already used, is now the interface method. A hard link is a copy there, since it keeps no link counts.How did you verify your code works?
test/lib/environment-conformance.tsruns the same checks against all three implementations. New checks cover the stat fields, append, positional writes past the end (zero-filled), truncation both ways, chmod and utimes read back through stat, chown, symlink/readlink/realpath/link with their NotFound and WrongKind cases, and statfs. The existing "stat matches the info read returns" check now leaves out the access time, which reading can move.test/environment.test.ts: 32 pass on macOS (the GNU suite is Linux-only), and all 47 pass on Linux with GNU coreutils 9.4, including the GNU exec suite.bun typecheckin core, app, cli, server, sdk and plugin, andbun run checkfrom the root.Screenshots / recordings
Not a UI change.
Checklist