Skip to content

fix: create the config directory in inlyne config open - #473

Open
mmclinton wants to merge 2 commits into
Inlyne-Project:mainfrom
mmclinton:fix/config-open-missing-dir
Open

fix: create the config directory in inlyne config open#473
mmclinton wants to merge 2 commits into
Inlyne-Project:mainfrom
mmclinton:fix/config-open-missing-dir

Conversation

@mmclinton

@mmclinton mmclinton commented Aug 3, 2026

Copy link
Copy Markdown

Problem

Command inlyne config open fails on a fresh install, before inlyne view has ever been run:

$ XDG_CONFIG_HOME=$(mktemp -d) inlyne config open
Error: No such file or directory (os error 2)

The editor opens fine. It's the write at the end that fails. config open tolerates a missing config file (it falls back to the embedded defaults) but not a missing config directory. create_dir_all only ever ran inside Config::create_default_config, which this code path never calls, so the directory gets created as a side effect of viewing a file and never otherwise.

Anyone who configures the viewer before first using it hits this; anyone who views a file first never sees it again. This is how I noticed it, developing related PRs.

Fix

Rather than adding a second create_dir_all in main.rs, this replaces Config::create_default_config with Config::write_to_file(path, contents), one writer that creates the config directory, used by both startup and config open. Two places that each had to remember to create the directory is what caused this in the first place.

Both failure modes now name the path that failed, matching what load_from_file already does for reads.

I split it into two commits: the refactor (no behavior change at the existing call site), then the one-line fix.

Tests

Three unit tests over write_to_file: writing into a missing directory (the regression test), overwriting an existing file, and writing the defaults so they load back.

The config open arm itself isn't unit-tested. It drives an interactive editor, and faking that seemed disproportionate here. I verified it by hand against a scratch XDG_CONFIG_HOME: the failure above on the pre-fix binary, then exit 0 with the defaults written verbatim, and an edit round-tripping back to the file. inlyne view on a fresh config home still creates the default config.

Note on #472

Independent of #472 — neither depends on the other, and either can merge first. GitHub will flag whichever lands second, so to save you the guesswork: I merged the two locally and the rebase is two mechanical edits.

  • mod tests — both branches append their own tests at the same spot. Keep both blocks.
  • use std::path::… — this branch drops PathBuf (unused here, so clippy rejects keeping it) while refactor: prefer config.toml over inlyne.toml #472 adds uses of it. Restore it to the import.

With those applied the merged tree is green: 66 tests, clippy, and fmt all pass, and load_from_system and config open end up using system_path() and write_to_file together as intended.

Happy to do the rebase whenever it's useful.

Not addressed here

One thing from #471 this deliberately leaves alone: edit::Builder runs with .disable_cleanup(true), so on a write failure the user's edits survive in a temp file whose path is never printed. That's a separate defect from the missing directory and I'd rather not widen this PR. Happy to file it separately if you think it's worth fixing.

Closes #471

mmc added 2 commits August 2, 2026 17:58
`create_dir_all` only ever ran inside `create_default_config`, so every other
code path that writes the config file has to remember to create the config
directory itself. Replace it with a single `write_to_file` that does both, so
there is one place that has to get this right rather than one per caller.

Failures now name the path that could not be created or written, matching
what `load_from_file` already does for reads.
`config open` tolerated a missing config file but not a missing config
directory, so it failed with a bare `No such file or directory (os error 2)`
for anyone who configured the viewer before ever using it to view a file:

    $ XDG_CONFIG_HOME=$(mktemp -d) inlyne config open
    Error: No such file or directory (os error 2)

The editor opened fine; only the write at the end failed. Viewing a file
creates the directory as a side effect, which is why the bug is invisible
after first use.

Closes Inlyne-Project#471
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.

inlyne config open fails when the config directory doesn't exist

1 participant