feat(fs): add abspath to resolve relative paths #31

Closed
opened 2026-05-31 05:30:56 +02:00 by michael · 1 comment
Owner

Goal

Add fs.abspath(path) to daw.common.fs to resolve relative paths
to absolute paths without requiring callers to depend on lfs directly.

Background

DAW/fragjan#102 requires walking upward from a directory to find .fragjan.
The upward walk in core/detect.find_project_root needs an absolute path
as starting point. Currently there is no fs.abspath -- callers would have
to use lfs.currentdir() directly, leaking an lfs dependency into modules
that should not need it.

Requirements

  • fs.abspath(path) resolves a relative path against lfs.currentdir()
  • Absolute paths are returned unchanged
  • Returns: absolute path string, nil | nil, err string

Acceptance Criteria

  • fs.abspath(path) implemented in daw/common/fs.lua
  • Relative path resolved against lfs.currentdir()
  • Absolute path returned unchanged
  • Tests added in test/test_fs.lua
  • DAW/fragjan#102 (flexible scan targets -- direct consumer of this function)
## Goal Add `fs.abspath(path)` to `daw.common.fs` to resolve relative paths to absolute paths without requiring callers to depend on `lfs` directly. ## Background DAW/fragjan#102 requires walking upward from a directory to find `.fragjan`. The upward walk in `core/detect.find_project_root` needs an absolute path as starting point. Currently there is no `fs.abspath` -- callers would have to use `lfs.currentdir()` directly, leaking an lfs dependency into modules that should not need it. ## Requirements - `fs.abspath(path)` resolves a relative path against `lfs.currentdir()` - Absolute paths are returned unchanged - Returns: absolute path string, nil | nil, err string ## Acceptance Criteria - [ ] `fs.abspath(path)` implemented in `daw/common/fs.lua` - [ ] Relative path resolved against `lfs.currentdir()` - [ ] Absolute path returned unchanged - [ ] Tests added in `test/test_fs.lua` ## Related - DAW/fragjan#102 (flexible scan targets -- direct consumer of this function)
Author
Owner

Implementation

  • fs.abspath(path) added to fs.lua in the Query block after read_attrs
  • Resolves paths via realpath through daw.common.sys:run() -- no direct io.*
  • daw.common.sys loaded at module level via pcall (consistent with lfs pattern)
  • Absolute paths (starting with /) pass through unchanged
  • Returns nil, err if path does not exist (realpath exits non-zero)
  • 4 tests added in test/test_fs.lua
  • daw.common.sys mapping added to test/dev-module-map.lua

Notes

  • realpath available on all target platforms (OpenBSD 7.1+, Debian, Arch)
  • Non-existing paths correctly return an error -- expected behaviour for DAW/fragjan#102
## Implementation - `fs.abspath(path)` added to `fs.lua` in the Query block after `read_attrs` - Resolves paths via `realpath` through `daw.common.sys:run()` -- no direct `io.*` - `daw.common.sys` loaded at module level via `pcall` (consistent with `lfs` pattern) - Absolute paths (starting with `/`) pass through unchanged - Returns `nil, err` if path does not exist (realpath exits non-zero) - 4 tests added in `test/test_fs.lua` - `daw.common.sys` mapping added to `test/dev-module-map.lua` ## Notes - `realpath` available on all target platforms (OpenBSD 7.1+, Debian, Arch) - Non-existing paths correctly return an error -- expected behaviour for DAW/fragjan#102
michael 2026-05-31 06:39:03 +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#31
No description provided.