axodotdev / axodotdev/cargo-dist
Installer can clobber local profile configuration
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 149
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 32
Description
Context:
The current logic for `add_install_dir_to_path` will write to the first file name in the list given to it if none of the files exist:
https://github.com/axodotdev/cargo-dist/blob/b9c9a515f50af6ceeb2e012bef847829cdeb7893/cargo-dist/templates/installer/installer.sh.j2#L465-L472
`add_install_dir_to_path` is called three times, with different file names:
https://github.com/axodotdev/cargo-dist/blob/b9c9a515f50af6ceeb2e012bef847829cdeb7893/cargo-dist/templates/installer/installer.sh.j2#L398-L403
Each call will therefore write at least one file (`.profile`, `.bash_profile`, `.zshrc`), regardless of which other files exist.
---
Issue:
In my case, I use `bash` and put all my configuration in `.profile`. `bash` will only load `.profile` if a `.bash_profile` does not exist, so the current behaviour of the installer effectively clobbers my local profile.
---
Possible solution:
Assuming this is undesired behaviour rather than an unsupported configuration at my end (though correct me if I'm wrong), this could be improved by making a single call to `add_install_dir_to_path`:
```sh
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".profile .bash_profile .bash_login .bashrc .zshrc .zshenv"
if [ $? = 1 ]; then
# ...
fi
```
This would have the effect of creating `~/.profile` if none of the files exist. As a lowest common denominator this seems like a reasonable choice.
Contributor guide
Research direction
Start in cargo-dist/templates/installer/installer.sh.j2, reading add_install_dir_to_path around lines 465-472 and its three call sites around lines 398-403. Check the generated installer with existing and missing profile files; done means it does not create or clobber an unrelated profile file while still configuring PATH.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- devops, release
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100