fix(shell): create parent dir before appending to rcfiles#3712
fix(shell): create parent dir before appending to rcfiles#3712
Conversation
|
|
||
| fn update_rcs(&self) -> Vec<PathBuf> { | ||
| self.rcfiles() | ||
| // The first rcfile takes precedence. |
There was a problem hiding this comment.
This doesn't obviously make sense to me. Why is this necessary? At the very least deserves some more comments on why we're doing this.
There was a problem hiding this comment.
@djc Sure! The snippet below explains the differences between .rcfiles() and .update_rcs().
rustup/src/cli/self_update/shell.rs
Lines 91 to 96 in 3fcd562
The problem with the current code is that, we have two rc paths in fish, one (p1) being the fallback of the other (p0).
rustup/src/cli/self_update/shell.rs
Lines 218 to 230 in 3fcd562
The issue here is, according to the current implementation, if both paths are valid, then we'll create and append to both of them. (It's okay to check both paths for cleanup, but that's another story.)
rustup/src/cli/self_update/unix.rs
Lines 88 to 93 in f6dbe2e
This is the expected behavior in some cases, but clearly not for fish due to this fallback relationship. I've found some similar code in the Zsh support (note the .take(1)):
rustup/src/cli/self_update/shell.rs
Lines 186 to 191 in f6dbe2e
rustup/src/cli/self_update/shell.rs
Lines 193 to 205 in f6dbe2e
There was a problem hiding this comment.
So should we change update_rcs() to yield PathBuf instead of Vec<PathBuf>? It seems conceptually confusing to do this only for some shells -- do we update all rcs for Bash?
Anyway, I guess this change is fine, but let's add some comments to explain the logic.
This way of writing it avoids the cloned(), and thus seems cleaner to me:
match self.rcfiles().into_iter().next() {
Some(path) => vec![path],
None => vec![],
}What do you think?
There was a problem hiding this comment.
So should we change
update_rcs()to yieldPathBufinstead ofVec<PathBuf>? It seems conceptually confusing to do this only for some shells -- do we update all rcs forBash?
@djc I'm not a bash expert, but at least the implementation is a bit more complex with Bash indeed, which seems to consider what exists on the current file system as a file and what doesn't.
rustup/src/cli/self_update/shell.rs
Lines 138 to 152 in f6dbe2e
... a quick blame points to #2387. @workingjubilee maybe you can provide more context on this one?
There was a problem hiding this comment.
This way of writing it avoids the
cloned(), and thus seems cleaner to me:match self.rcfiles().into_iter().next() { Some(path) => vec![path], None => vec![], }What do you think?
@djc Done.
There was a problem hiding this comment.
@workingjubilee Thanks for your quick response! Apart from what you said above, we are particularly curious about why update_rcs is plural 👀
There was a problem hiding this comment.
We also originally did not handle fish at all.
... and that's exactly why we need this context to evaluate our fish support implementation :]
There was a problem hiding this comment.
Why would it be singular?
There was a problem hiding this comment.
It was just my intuition that it wouldn't make sense to "update" multiple RC files per shell? It seems like if we want to make the rustup proxies work in fish, it would be enough if we update one file? So in that sense update_rcs() -> Vec<PathBuf> should be more like update_rc() -> PathBuf?
(I'm not big on shell customization so my understanding might be wrong.)
There was a problem hiding this comment.
@djc While imprecise on technical terms, my remarks in #3256 (comment) remain an accurate summary of the actual situation. In short: No. Not at all. That requires knowledge of not only the OS, not only the shell (and we don't actually know that), but the specific version and distribution of the software.
|
@djc I guess we shouldn't be blocking the inclusion on a reply. I'm merging this now. |
Fixes #3706,
addressing https://rust-lang.github.io/rust-clippy/master/#/ineffective_open_options at the same time(superseded by #3713).Concerns
It's better to test the CI build in a container or something before actually merging this PR.(Tested on Ubuntu 22.04.4 LTS x86_64.)