feat(fs): add fs.tmpdir() and fs.tmpfile() for portable temp path handling #32

Closed
opened 2026-06-01 12:30:00 +02:00 by michael · 1 comment
Owner

Problem

There is no standardized way to create temporary files or directories
in the DAW ecosystem. Code that needs temp paths currently hardcodes
/tmp/ directly, which violates the no-hardcoded-tmp-prefix rule and
is not portable across OS installations.

Examples of current workarounds

-- core/commands/article.lua
local script_path = "/tmp/fragjan_check_" .. basename .. ".sh"
-- lib/daw/common/crypto.lua
local tmp = "/tmp/daw_hmac_msg_" .. os.time() .. "_" .. math.random(99999)

Goal

Add fs.tmpdir() and/or fs.tmpfile(prefix) to daw.common.fs
returning a OS-appropriate temp path, abstracting away /tmp/ hardcoding.

Acceptance Criteria

  • fs.tmpdir() returns a writable temp directory path for the current OS
  • fs.tmpfile(prefix) returns a unique temp file path with daw_ prefix
  • All DAW code using hardcoded /tmp/ migrated to use these functions
  • Works correctly on OpenBSD, Debian, Arch

Notes

Current workaround: suppress no-hardcoded-tmp-prefix with reference to
this issue. Migration of existing code (crypto.lua, base64.lua,
article.lua etc.) as separate follow-up once fs functions are available.

Related: DAW/daw-lua-common (fs.lua)

## Problem There is no standardized way to create temporary files or directories in the DAW ecosystem. Code that needs temp paths currently hardcodes `/tmp/` directly, which violates the no-hardcoded-tmp-prefix rule and is not portable across OS installations. ## Examples of current workarounds ``` -- core/commands/article.lua local script_path = "/tmp/fragjan_check_" .. basename .. ".sh" -- lib/daw/common/crypto.lua local tmp = "/tmp/daw_hmac_msg_" .. os.time() .. "_" .. math.random(99999) ``` ## Goal Add `fs.tmpdir()` and/or `fs.tmpfile(prefix)` to `daw.common.fs` returning a OS-appropriate temp path, abstracting away `/tmp/` hardcoding. ## Acceptance Criteria - [ ] `fs.tmpdir()` returns a writable temp directory path for the current OS - [ ] `fs.tmpfile(prefix)` returns a unique temp file path with daw_ prefix - [ ] All DAW code using hardcoded `/tmp/` migrated to use these functions - [ ] Works correctly on OpenBSD, Debian, Arch ## Notes Current workaround: suppress no-hardcoded-tmp-prefix with reference to this issue. Migration of existing code (crypto.lua, base64.lua, article.lua etc.) as separate follow-up once fs functions are available. Related: DAW/daw-lua-common (fs.lua)
Author
Owner

Implemented via mktemp -d / mktemp through sys:run() -- same
pattern as fs.abspath(). No prefix parameter, no hardcoded path
construction; the OS handles uniqueness and temp location.

55 tests passing on Lua 5.1 and 5.4.

Note: acceptance criteria mentioned a daw_ prefix -- dropped in
favour of plain mktemp output (e.g. /tmp/tmp.Nw3W6dOoeO).
Migration of existing hardcoded /tmp/ usage (crypto.lua, base64.lua,
article.lua) remains as separate follow-up.

Implemented via `mktemp -d` / `mktemp` through `sys:run()` -- same pattern as `fs.abspath()`. No prefix parameter, no hardcoded path construction; the OS handles uniqueness and temp location. 55 tests passing on Lua 5.1 and 5.4. Note: acceptance criteria mentioned a `daw_` prefix -- dropped in favour of plain `mktemp` output (e.g. `/tmp/tmp.Nw3W6dOoeO`). Migration of existing hardcoded `/tmp/` usage (crypto.lua, base64.lua, article.lua) remains as separate follow-up.
michael 2026-06-01 12:48:50 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#32
No description provided.