Fixes the [MED] write-path-safety issue: managed LICENSE / LICENSES/<id>.txt files were written via os.Stat + temp-file + os.Rename with no symlink check. If the target was a deliberate symlink (e.g. LICENSE -> LICENSES/MIT.txt), os.Rename replaced the link with a regular file, silently breaking it.
Changes
AtomicWrite now os.Lstats the target. If it is a symlink it refuses with a sentinel errSymlinkTarget and writes nothing, leaving the link and its target untouched. For a regular file, Lstat returns the same mode bits as Stat, so mode preservation is unchanged.
The refusal message contains "refusing to write", so the CLI's existing isWriteRefusal mapping classifies it as a write refusal (exit code 3) rather than a generic internal error.
writeManaged propagates a symlink refusal as a returned error (so it reaches License/Apply -> writeOrInternalError); all other write failures remain recorded per-file (fr.Err) so one bad path does not abort the run, matching prior behavior.
Scope
Source-file headers are unaffected (enumerate already skips symlinks). This change is specifically the license-file write path, plus the shared AtomicWrite guard.
Tests (TDD, red -> green)
TestAtomicWriteRefusesSymlink: symlinked target is refused; Lstat still reports a symlink; link destination and target content unchanged.
TestWriteManagedRefusesSymlink / TestLicenseRefusesSymlinkTarget: the managed/public write path surfaces the refusal as a returned error.
TestCmd...symlinked LICENSE is refused with the write-refused exit code: asserts exit code 3 via the CLI.
Normal (non-symlink) write + idempotency remain green.
## Summary
Fixes the [MED] write-path-safety issue: managed `LICENSE` / `LICENSES/<id>.txt` files were written via `os.Stat` + temp-file + `os.Rename` with **no symlink check**. If the target was a deliberate symlink (e.g. `LICENSE -> LICENSES/MIT.txt`), `os.Rename` replaced the link with a regular file, silently breaking it.
## Changes
- `AtomicWrite` now `os.Lstat`s the target. If it is a symlink it refuses with a sentinel `errSymlinkTarget` and writes nothing, leaving the link and its target untouched. For a regular file, `Lstat` returns the same mode bits as `Stat`, so mode preservation is unchanged.
- The refusal message contains `"refusing to write"`, so the CLI's existing `isWriteRefusal` mapping classifies it as a **write refusal (exit code 3)** rather than a generic internal error.
- `writeManaged` propagates a symlink refusal as a returned error (so it reaches `License`/`Apply` -> `writeOrInternalError`); all other write failures remain recorded per-file (`fr.Err`) so one bad path does not abort the run, matching prior behavior.
## Scope
Source-file headers are unaffected (enumerate already skips symlinks). This change is specifically the license-file write path, plus the shared `AtomicWrite` guard.
## Tests (TDD, red -> green)
- `TestAtomicWriteRefusesSymlink`: symlinked target is refused; `Lstat` still reports a symlink; link destination and target content unchanged.
- `TestWriteManagedRefusesSymlink` / `TestLicenseRefusesSymlinkTarget`: the managed/public write path surfaces the refusal as a returned error.
- `TestCmd...symlinked LICENSE is refused with the write-refused exit code`: asserts exit code 3 via the CLI.
- Normal (non-symlink) write + idempotency remain green.
## Gate
- `gofmt -l .`: clean
- `go vet ./...`: clean
- `go test ./... -race`: pass
- coverage gate: 100%
- `golangci-lint run`: 0 issues
Closes #33
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Fixes the [MED] write-path-safety issue: managed
LICENSE/LICENSES/<id>.txtfiles were written viaos.Stat+ temp-file +os.Renamewith no symlink check. If the target was a deliberate symlink (e.g.LICENSE -> LICENSES/MIT.txt),os.Renamereplaced the link with a regular file, silently breaking it.Changes
AtomicWritenowos.Lstats the target. If it is a symlink it refuses with a sentinelerrSymlinkTargetand writes nothing, leaving the link and its target untouched. For a regular file,Lstatreturns the same mode bits asStat, so mode preservation is unchanged."refusing to write", so the CLI's existingisWriteRefusalmapping classifies it as a write refusal (exit code 3) rather than a generic internal error.writeManagedpropagates a symlink refusal as a returned error (so it reachesLicense/Apply->writeOrInternalError); all other write failures remain recorded per-file (fr.Err) so one bad path does not abort the run, matching prior behavior.Scope
Source-file headers are unaffected (enumerate already skips symlinks). This change is specifically the license-file write path, plus the shared
AtomicWriteguard.Tests (TDD, red -> green)
TestAtomicWriteRefusesSymlink: symlinked target is refused;Lstatstill reports a symlink; link destination and target content unchanged.TestWriteManagedRefusesSymlink/TestLicenseRefusesSymlinkTarget: the managed/public write path surfaces the refusal as a returned error.TestCmd...symlinked LICENSE is refused with the write-refused exit code: asserts exit code 3 via the CLI.Gate
gofmt -l .: cleango vet ./...: cleango test ./... -race: passgolangci-lint run: 0 issuesCloses #33
🤖 Generated with Claude Code