fix: create the config directory in inlyne config open - #473
Open
mmclinton wants to merge 2 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Command
inlyne config openfails on a fresh install, beforeinlyne viewhas ever been run:The editor opens fine. It's the write at the end that fails.
config opentolerates a missing config file (it falls back to the embedded defaults) but not a missing config directory.create_dir_allonly ever ran insideConfig::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_allinmain.rs, this replacesConfig::create_default_configwithConfig::write_to_file(path, contents), one writer that creates the config directory, used by both startup andconfig 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_filealready 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 openarm itself isn't unit-tested. It drives an interactive editor, and faking that seemed disproportionate here. I verified it by hand against a scratchXDG_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 viewon 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 dropsPathBuf(unused here, so clippy rejects keeping it) while refactor: preferconfig.tomloverinlyne.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_systemandconfig openend up usingsystem_path()andwrite_to_filetogether as intended.Happy to do the rebase whenever it's useful.
Not addressed here
One thing from #471 this deliberately leaves alone:
edit::Builderruns 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