Repository navigation
Conversation
The shell expands ~ in command-line arguments, but values read from config.yaml were passed to path.resolve as-is, so `user-data-dir: ~/.config/code-server-data` resolved to `<cwd>/~/.config/code-server-data`. Fixes coder#7051
4 tasks done
This branch has not been deployed
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.
Fixes #7051
Summary
Expand a leading
~in path options (such asuser-data-dirandextensions-dir) so they work inconfig.yamlthe same way they do on the command line.Problem
The shell expands
~in command-line arguments, but nothing expands it in values read from the config file. Withthe value reaches
path.resolveas-is (src/node/cli.ts#L469) and is resolved against the current working directory. Depending on where code-server is started, the result is<cwd>/~/.config/code-server-dataor/~/.config/..., which leads to errors like:Solution
As suggested in the issue ("it would be nice if we manually expand it when we read the config"), path options now go through a small
expandTildehelper beforepath.resolve:~→ the home directory~/foo(or~\fooon Windows) →<home>/foo~user/...and a~in the middle of a path, is left unchangedBecause the expansion happens in
parse, it covers every option markedpath: true(user-data-dir,extensions-dir,builtin-extensions-dir,cert,cert-key,socket,i18n), whether it comes from the CLI or the config file. CLI values are already expanded by the shell, so the change is a no-op for them.Changes
src/node/util.tsexpandTilde()src/node/cli.tsexpandTilde()beforepath.resolve()for path optionstest/unit/node/util.test.tsexpandTilde()test/unit/node/cli.test.tsparseConfigFileexpands~inuser-data-dirandextensions-dirBefore / After
config.yaml:user-data-dir(started from/srv)/srv/~/.config/code-server-data/home/<user>/.config/code-server-dataHow to test
user-data-dir: ~/.config/code-server-datain~/.config/code-server/config.yaml.cd /tmp && code-server~/.config/code-server-datain your home and that no/tmp/~directory was created.Testing done
util.test.tsandcli.test.tscliandutilunit test suites: 144/144 passingexpandTildeis a no-op, so it covers the bugprettier --checkandeslintclean on the changed files~\branch is covered only by thepath.sepcheck)Notes for reviewers
~userexpansion is intentionally not supported; it would need a user database lookup and isn't what the issue asks for._) aren't path options and are unchanged.