Skip to content

Fix data-loss bugs and make adopt write to the config - #2

Merged
youhide merged 1 commit into
mainfrom
fix/critical-bugs-and-adopt-config
Jul 24, 2026
Merged

Fix data-loss bugs and make adopt write to the config#2
youhide merged 1 commit into
mainfrom
fix/critical-bugs-and-adopt-config

Conversation

@youhide

@youhide youhide commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Four defects that either destroyed files or failed silently:

  • defaults.link without a backup: key disabled backups entirely (Go zero value), so force: true overwrote real files with no copy. The LinkDefaults fields are now *bool, absent means backup enabled, and a failed backup aborts the overwrite instead of proceeding.
  • Duplicate detection deleted any symlink in the target's directory pointing at the same source, so two config entries sharing a source destroyed each other on every run. It is now opt-in via remove_duplicates and never touches a declared target.
  • Runs exited 0 even when every link failed. Commands now end with failureError(), and SilenceUsage keeps runtime errors readable.
  • Template execution errors were swallowed, creating links with {{ .Hostnam }} in their names. Exec errors are now fatal; parse errors stay tolerated for configs holding a literal {{.

adopt now finishes the job: it takes several paths, mirrors each one's location inside the repo minus leading dots (~/.config/nvim -> config/nvim), and inserts the link entry into the config through a yaml.Node round-trip that preserves comments. It edits the raw file rather than the template-expanded copy, so {{ }} variables survive, and falls back to printing the entry when the config cannot be parsed or no profile section matches. Adds --to and --no-config.

Also: deterministic processing order (maps were iterated at random), failing pre_* hooks abort their section, a backup manifest so backup list shows real paths and dates, stale directory backups are cleared before recopying, a warning when there is no backup to restore, and --quiet no longer prints the summary.

Tests cover the destructive paths for the first time: createLink, duplicate handling, adopt, config insertion, unlink --restore and exit code propagation.

Four defects that either destroyed files or failed silently:

- defaults.link without a `backup:` key disabled backups entirely (Go
  zero value), so `force: true` overwrote real files with no copy. The
  LinkDefaults fields are now *bool, absent means backup enabled, and a
  failed backup aborts the overwrite instead of proceeding.
- Duplicate detection deleted any symlink in the target's directory
  pointing at the same source, so two config entries sharing a source
  destroyed each other on every run. It is now opt-in via
  `remove_duplicates` and never touches a declared target.
- Runs exited 0 even when every link failed. Commands now end with
  failureError(), and SilenceUsage keeps runtime errors readable.
- Template execution errors were swallowed, creating links with
  `{{ .Hostnam }}` in their names. Exec errors are now fatal; parse
  errors stay tolerated for configs holding a literal `{{`.

adopt now finishes the job: it takes several paths, mirrors each one's
location inside the repo minus leading dots (~/.config/nvim ->
config/nvim), and inserts the link entry into the config through a
yaml.Node round-trip that preserves comments. It edits the raw file
rather than the template-expanded copy, so `{{ }}` variables survive,
and falls back to printing the entry when the config cannot be parsed
or no profile section matches. Adds --to and --no-config.

Also: deterministic processing order (maps were iterated at random),
failing pre_* hooks abort their section, a backup manifest so
`backup list` shows real paths and dates, stale directory backups are
cleared before recopying, a warning when there is no backup to restore,
and --quiet no longer prints the summary.

Tests cover the destructive paths for the first time: createLink,
duplicate handling, adopt, config insertion, unlink --restore and exit
code propagation.
@youhide
youhide merged commit 11aa272 into main Jul 24, 2026
6 checks passed
@youhide
youhide deleted the fix/critical-bugs-and-adopt-config branch July 24, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant