Refine macOS/LogAlias platform tuning, fix a real WithRoot bug found on Windows
Platform tuning:
- macOS Desktop's RuntimeDir() now prefers $TMPDIR (the OS-managed,
per-user ephemeral directory NSTemporaryDirectory() returns) over
the previous ~/Library/Application Support/<App>/Runtime placeholder.
- Resolver.EnsureLogAlias() creates the optional LogAliasDir() symlink
to LogDir(), idempotently, leaving any pre-existing entry alone.
Verified the SHGetKnownFolderPath fallback (knownfolders_windows.go)
on a real Windows host for the first time: with APPDATA/LOCALAPPDATA/
PROGRAMDATA all unset, it correctly resolves the real known folders.
go vet's one unsafeptr finding there is a documented, permanent,
unavoidable characteristic of this raw-syscall pattern, not a bug.
That same real-Windows run surfaced a genuine, previously-invisible
bug: WithRoot assumed root's own address family always matched the
*simulated* platform's, which silently broke (mixed separators, or an
outright invalid mid-path drive letter) whenever the real host's
native family differed from what WithPlatform was simulating -- e.g.
WithPlatform("linux") with WithRoot(t.TempDir()) on a real Windows
host. This was invisible on macOS/Linux, where t.TempDir() happens to
already share the simulated Unix family.
Fixed applyRoot (now applyRootRebase) to decompose the resolved path
into segments and re-join them onto root using root's own family,
inferred from its content like JoinDirFile already does, not from the
simulated platform. Two call sites chaining onto an already-rooted
value (logDirUnix, darwin.go's State/Runtime fallback) switched from a
hardcoded unixJoin to JoinDirFile for the same reason. core/config's
working-directory layer had the identical bug one level up; fixed via
a new paths.JoinDirFileFamily.
TODO.md/ARCHITECTURE.md/README.md updated accordingly; core/TODO.md's
remaining items are now all explicitly out-of-scope or deliberately
deprioritized, not open work.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6b5324ad3
commit
da2ec85381
13 files changed
+515
-70
No files matched your search
@@ -108,6 +108,7 @@ native GUI app) uses `~/Library/...`:
|
||||
~/Library/Application Support/<App>/State
|
||||
~/Library/Caches/<App>
|
||||
~/Library/Logs/<App>
|
||||
$TMPDIR/<App> (Runtime -- see below)
|
||||
```
|
||||
|
||||
### Windows
|
||||
@@ -138,7 +139,18 @@ machine-local override layer. Data/State/Cache/Log/Runtime live under
|
||||
Unix, without an explicit override and without `XDG_RUNTIME_DIR` set, it
|
||||
returns `paths.ErrRuntimeDirUnavailable` -- callers decide what to do.
|
||||
Windows and macOS always resolve a runtime directory (no equivalent
|
||||
"may legitimately not exist" case there).
|
||||
"may legitimately not exist" case there); macOS Desktop resolves it from
|
||||
`$TMPDIR` (see ARCHITECTURE.md), the same OS-managed ephemeral directory
|
||||
`NSTemporaryDirectory()` returns.
|
||||
|
||||
### LogAliasDir
|
||||
|
||||
`LogAliasDir()` resolves the optional Unix convenience symlink target
|
||||
`~/.local/log/<app>` (spec section 39) without touching the filesystem,
|
||||
same as every other `*Dir()` method. `EnsureLogAlias()` creates the
|
||||
actual `LogDir()` symlink there if nothing exists yet, and is a no-op
|
||||
`EnsureLogDir()` equivalent on Windows/macOS Desktop, where the two
|
||||
already coincide.
|
||||
|
||||
### Explain / doctor
|
||||
|
||||
@@ -155,10 +167,19 @@ existence/permission checks.
|
||||
Every platform code path is a plain function of an injectable
|
||||
`Environment` (env vars) and an injectable platform string
|
||||
(`paths.WithPlatform("windows")`), not `runtime.GOOS`/`os.Getenv`
|
||||
directly -- see ARCHITECTURE.md's "Platform simulation" section for why,
|
||||
directly -- see ARCHITECTURE.md's "Platform strategy" section for why,
|
||||
and the package's own tests for how Windows/macOS/FreeBSD path logic is
|
||||
verified while running on any host.
|
||||
|
||||
Combine `WithPlatform` with `WithRoot(t.TempDir())` to also sandbox real
|
||||
filesystem I/O (`Ensure*`, `FindFile`, `Explain`) while simulating a
|
||||
different platform's path *logic* than the host actually running the
|
||||
test. `root` there is always in the real host's native address family
|
||||
(whatever `t.TempDir()` returns), which need not match the simulated
|
||||
platform's family -- `WithRoot` handles that mismatch correctly (see
|
||||
ARCHITECTURE.md's "WithRoot: root's family is the real host's"), so the
|
||||
combination is always safe to use.
|
||||
|
||||
## core/config: finding and layering configuration files
|
||||
|
||||
```go
|
||||
|
||||
Reference in new issue
Block a user