gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit028ed776028ed776Records: mission 001 continuation S1bmre028ed776/plugins/fs/server.hl

6.8 KB

  1. file(String path) {
  2. return __native("fs.file", path)
  3. }
  4. readFile(String path) {
  5. return __native("fs.read_file", path)
  6. }
  7. \* `readFile`, but a path that is not there answers null instead of failing: for what
  8. another process may delete between a probe and the read (the shared build cache). *\
  9. tryReadFile(String path) {
  10. return __native("fs.try_read_file", path)
  11. }
  12. \* Read a whole file as Bytes (ticket #88): every byte as it is on disk,
  13. nothing decoded — the way back for what writeFile stored from a Bytes. *\
  14. readBytes(String path, offset, length) {
  15. if (offset == null && length == null) {
  16. return toBytes(__native("fs.read_file", path))
  17. }
  18. return toBytes(__native("fs.read_range", path, offset, length))
  19. }
  20. \* Part of a file, without reading the rest (#233): `readBytes(path, offset, length)`
  21. gives at most `length` bytes starting at byte `offset`, as Bytes, for answering an
  22. HTTP Range request from a big file. An offset at or past the end of the file gives an
  23. empty Bytes; a length that runs past the end gives the shorter rest. Offset and length
  24. must both be given, as whole numbers of zero or more; otherwise it is an Error event,
  25. like a missing file is. `readBytes(path)` with no numbers is the whole file, as before.
  26. `stat(path)` asks about a path without reading it: an object with `size` (bytes),
  27. `mtime` and `ctime` (milliseconds since the epoch, the form `changeTime` answers in)
  28. and `type` ("file", "directory" or "other", the words listDir uses). A path that is
  29. not there answers null, as `changeTime` does. Symlinks are followed. *\
  30. stat(String path) {
  31. return __native("fs.stat", path)
  32. }
  33. \* Name the file every path read, listed or probed is appended to (one line,
  34. `r|l|e <path>`), or stop with null — the build cache's record of what a
  35. build depends on (326 rung 12). *\
  36. traceReads(path) {
  37. return __native("fs.trace", path)
  38. }
  39. \* The SHA-256 of a file's bytes, 64 hex digits, or null when it cannot be
  40. read; `textDigest`, of a text's. Hashed natively (the build cache). *\
  41. fileDigest(String path) {
  42. return __native("fs.digest", path)
  43. }
  44. textDigest(String text) {
  45. return __native("fs.digest_text", text)
  46. }
  47. \* The path's last status change (ctime) in milliseconds since the epoch, or null
  48. when it is not there (#195): what the build cache compares with the moment a
  49. build began. *\
  50. changeTime(String path) {
  51. return __native("fs.change_time", path)
  52. }
  53. listDir(String path) {
  54. return __native("fs.list_dir", path)
  55. }
  56. \* Does this path exist? (mission 077) The one call in hl:fs that cannot fail:
  57. it answers true/false, never an Error event — probing a path is a question,
  58. not an operation. Relative paths resolve against the SCRIPT's directory like
  59. every other hl:fs path. *\
  60. exists(String path) {
  61. return __native("fs.exists", path)
  62. }
  63. \* Watch a directory tree for changes (the dev-reload bell): an ordinary
  64. event-loop source — register it and every save arrives as an event.
  65. __native("eventloop.register", watch("."), "changed")
  66. on changed(ev) { … ev.name … }
  67. `exclude` (2026-08-30) names directories the descent must NOT enter — a
  68. path string, or a list of them. Omit it and the whole tree is watched, as
  69. it always was. The paths are compared RESOLVED (relative ones against the
  70. script's directory, like every hl:fs path) and normalised, so `./sessions`,
  71. `sessions` and `var/../sessions` are the same directory, and a sibling
  72. named `sessions-old` is NOT inside `sessions`.
  73. watch(".", "./sessions")
  74. watch(".", ["./sessions", "/var/cache/app"])
  75. A program that writes to a directory it also watches needs this: without
  76. it the only escape was that the walker skips dot-directories (which it
  77. still does — `.git` is the reason), i.e. renaming the directory. *\
  78. watch(String path, exclude) {
  79. return __native("fs.watch", path, exclude)
  80. }
  81. \* Write a whole file, ATOMICALLY (2026-08-28). Everything above this line
  82. reads; hl:fs could report a file's `chmod` and never set one, which is why
  83. nothing in this language could persist anything until now.
  84. The write goes to a sibling temp file, is fsynced, and is then renamed over
  85. the target — so a concurrent reader sees the whole OLD file or the whole NEW
  86. one, never a half of either. That matters more than it sounds: the first
  87. caller is the session store, and a truncated session file does not read as
  88. an error, it reads as a logged-out user.
  89. `mode` defaults to 0600 — a file this program wrote, for this program. Pass
  90. one to loosen it; nothing here consults the umask on your behalf.
  91. `contents` is a String or a Bytes (ticket #88): a Bytes is written raw,
  92. byte for byte — an uploaded image stays an image. *\
  93. writeFile(
  94. String path
  95. contents \\ a String or a Bytes
  96. Number mode
  97. ) {
  98. if (hlTypeName(contents) == 'Bytes') {
  99. return __native("fs.write_file_hex", path, contents.hex(), mode)
  100. }
  101. return __native("fs.write_file", path, contents, mode)
  102. }
  103. \* Append to a file — the log's shape, not the session store's (2026-09-27, a
  104. creator ask after routger's two). Opened O_APPEND, never truncated: the file
  105. is created (at `mode`, default 0600, same as writeFile) if it is not there
  106. yet, and every call after that lands its bytes after whatever is already on
  107. disk. `writeFile`'s atomicity is a RENAME over a temp file — there is no
  108. "old" or "new" whole file to swap here, since an append MUTATES the one
  109. that is already there — but O_APPEND carries its own, narrower guarantee:
  110. the kernel positions a single write() at the CURRENT end of file and
  111. performs it as one operation, so two processes each appending one line
  112. never interleave their bytes mid-line, and a reader never sees a torn
  113. append. That is what "a single write of a line lands whole" buys — call it
  114. once per line (or per record) you want that guarantee for.
  115. `contents` is a String or a Bytes (ticket #88), same as writeFile: a Bytes
  116. is appended raw, byte for byte. *\
  117. appendFile(
  118. String path
  119. contents \\ a String or a Bytes
  120. Number mode
  121. ) {
  122. if (hlTypeName(contents) == 'Bytes') {
  123. return __native("fs.append_file_hex", path, contents.hex(), mode)
  124. }
  125. return __native("fs.append_file", path, contents, mode)
  126. }
  127. \* Make a directory and every missing parent. Already-there is SUCCESS: the
  128. caller wants the directory to exist, not to be the one who created it.
  129. `mode` defaults to 0700. *\
  130. mkDir(String path, Number mode) {
  131. return __native("fs.mk_dir", path, mode)
  132. }
  133. \* Delete a file or an empty directory. IDEMPOTENT: true when the path is gone on return, and a path
  134. that was already gone counts. A sweep must not fail because something else
  135. deleted the file first. *\
  136. remove(String path) {
  137. return __native("fs.remove", path)
  138. }
  139. \* The canonical absolute path of `path` (symlinks resolved, `.`/`..` folded;
  140. realpath(3)), or null when it is not there. `realPath('/proc/self/exe')` is
  141. the running binary. *\
  142. realPath(String path) {
  143. return __native("fs.real_path", path)
  144. }

Branches

Latest commits

  • 028ed776Records: mission 001 continuation S1bmre
  • 1838d7e8Records: S1 startedmre
  • a43fca3fRecords: mission 001 decided pointsmre
  • 41773828Records: statusmre
  • a82c0805Records: mission 001 brief (Style form)mre
  • a4bce6d1Records: ticket push subscriptionmre
  • 14abde3bjukebox: records: Atlas's records moved to worldapi-conductor/archivemre
  • 0433e9a8jukebox: records: gitoria remote added and pushedmre
  • 1722d707jukebox: records: repo creation handed to Gitoriamre
  • b42e7dfbjukebox: conductor records (CONDUCTOR.md, STATUS.md), old STATUS archivedmre
  • 1b0d0bc1jukebox: a startup error prints its message before exit 1 (hybriel#247)mre
  • b19c478bjukebox JB18 (jukebox#17): onto Hybriel set-day31 (b287cd82, contains the SIGPIPE fix 6d2ca454): plugins/core and plugins/web re-vendored, bin/ from the set; a client that closes /stream while it is written no longer kills the server (90 aborted streams survived, the old bin died with exit 141 on the first)mre
  • 73867a2ejukebox#2: Style blocks in the language's nested form (rules named after the View's own elements, pseudo-classes nested, merged duplicates); the same CSS rules, the pages look the samemre
  • 06c548d6jukebox JB15: report, log linemre
  • 980859cbjukebox JB15 (jukebox#15): the now-playing overlay on a short screen (tablet or phone on its side) gave the queue 12 to 100 px because the big cover took the room; the cover now shrinks with the screen height and goes away under 41rem, the queue keeps 3+ rows; gate tests/jb15.mjs at 8 sizesmre
  • 9efc40ffjukebox#12 #14: Grok session 1793246574527-181160mre
  • 7d58b36ejukebox JB13 (jukebox#13): Next and Previous ask for the songs after / before the current song's id in the current order, not for place + 1; gate tests/jb13.mjs checks Next with the queue down to one song after the order changedmre
  • 51358794jukebox JB14 (jukebox#14): the Songs screen opens sorted the way it was left (kept on the server in storage/ui.json), the sort control shows the sort the rows really have (selected options, autocomplete off); gate tests/jb14.mjsmre
  • cc68a063jukebox JB13 (jukebox#13): a tapped song plays the song that was tapped, found by its id in the list as it is now (not by its row number, which counted plays move); the queue goes on from its place there, the rows refresh on the tap; gate tests/jb13.mjs (songs by plays, favourites)mre
  • 88d3d5c1jukebox JB12b (jukebox#12): the scroll handle is big (2.75rem x 4rem, accent colour, grip) and drawn on every device, no media query; native bar hidden; gate tests/touch.mjs checks the drawn width with and without touchmre