Respect Windows directory sturucter in Windows (wslconfig file location).
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
Re-opening #6783 as it was closed by the bot after being ignored for a year.
Currently, WSL2 expects to find `.wslconfig` in `%USERPROFILE%/.wslconfig`. On Windows, this is an inappropriate location to put tooling configuration files, and the filename convention is a Linux one that doesn't make sense on Windows.
On Windows, the appropriate (well documented) location for machine level configuration is `%PROGRAMDATA%/company/product/*` and the appropriate location for user level configuration is `%APPDATA%/company/product/*`. Since this is already in a per-user directory, I'll assume that user level configuration is desired in which case this configuration file should live in `%APPDATA%/Microsoft/wsl2/config.ini`. The file extension here is valuable as it indicates to text editors how to syntax highlight.
I understand that in Linux it historically has been acceptable (not really true anymore with `XGD_CONFIG`) to just dump config files in `$HOME` with a leading `.` so they are hidden by default, but that is very much not the Windows convention. The `%USERPROFILE%` directory is meant to store files the user explicitly puts there, like documents they have saved, personal photos, downloads, etc. It is not meant to be a dumping ground for every application's configuration files. On top of that, the leading `.` character causes problems in some windows applications (such as Windows explorer) and it does not serve the purpose of hiding the file from listing. Finally, lacking a file extension means that most text editors (e.g., VSCode) will not know how to handle syntax highlighting and auto-completion so working with the file is more painful than necessary.
Unfortunately, since WSL has launched with this a migration plan is necessary. My recommendation is to do the following:
1. Start looking for configuration first in `%APPDATA%/Microsoft/wsl2/config.ini`, and fallback to looking in `%USERPROFILE%/.wslconfig` if that is not found.
1. On startup, if a file is found in both locations warn the user and use the new location.
1. Give a warning to users (not sure where it would be appropriate to surface this) that the `.wslconfig` file location will be changing in the future with a link to this issue or some docs on the subject.
1. On startup, if no file is found in the new location but one is found in the old location, move the file prior to reading it.
1. Stop looking in the old location and delete the handling of the migration and old lookup code.
The above steps don't have to be completed at the same time, they could be done over a series of updates spanning as much time as you are comfortable with. Step 1 could be done today with little impact on any existing users and minor impact on public facing documentation so I recommend getting started with that ASAP so WSL2 is a good Windows citizen and deal with the migration strategy and deprecation steps later.
```none
Windows build number: `Microsoft Windows [Version 10.0.19042.867]`
Your Distribution version: `Release: 20.04`
Whether the issue is on WSL 2 and/or WSL 1: WSL2
```
Contributor guide
Research direction
Start by tracing where WSL2 reads .wslconfig during startup and how configuration warnings are surfaced. Compare that lookup with the requested %APPDATA%/Microsoft/wsl2/config.ini and legacy %USERPROFILE%/.wslconfig paths. Done means the new location is preferred, the fallback and migration behavior are defined, and the user-facing warning or documentation path is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100