-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
askpass: Fix cli path when executed in a remote server #39475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
askpass: Fix cli path when executed in a remote server #39475
Conversation
…utable itself Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
|
lgtm zed cli helper now works within WSL |
maxbrunsfeld
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcocondrache Thanks so much for tracking this down. Nice work.
I would love to solve this in a way that doesn't rely on checking the filename of the current exe.
Here's one way to fix it that I think is cleaner. Let me know if this makes sense to you:
- We should put back the
--askpassargument in the main editor on linux and macOS. - There should be a static variable in
ask_pass.rscalledASKPASS_PROGRAM(aPathBuf) - the path to the program that should be invoked for askpass. By default,ASKPASS_PROGRAMshould be initialized to thecurrent_exe(). On mac and Linux, and in the remote server, it should just be left that way. - The
askpassmodule should have a public setter function calledset_askpass_programthat can override theASKPASS_PROGRAM. We should only call that function on Windows, inzed::main(passing in the path to the CLI).
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
|
@maxbrunsfeld, thanks for the feedback! That makes perfect sense, and it's a cleaner approach. I will make the changes immediately |
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
|
@maxbrunsfeld I’ve updated the PR with the changes. I moved the logic for turning a path into a shell-safe string into the I’m also not too sure about the For testing, I can only try things out on macOS. I’ll give it a spin there, but unfortunately I won’t be much help on Linux or Windows 😞 |
| } | ||
| } | ||
|
|
||
| pub fn set_askpass_program(path: std::path::PathBuf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: conventionally in Zed we use a fn init() function for initialization of globals related to a given module. That function also resides closer to the top of a file.
| pub fn set_askpass_program(path: std::path::PathBuf) { | |
| pub fn init(path: std::path::PathBuf) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling it init might be misleading in this case, since it only runs on Windows. Making it run unconditionally could also introduce security concerns - on Unix platforms, current_exe should be called right before use to avoid potential privilege escalation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, we can leave it as is then.
crates/askpass/src/askpass.rs
Outdated
|
|
||
| pub fn set_askpass_program(path: std::path::PathBuf) { | ||
| if ASKPASS_PROGRAM.set(path).is_err() { | ||
| panic!("askpass program has already been set"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could prolly be a debug_panic. We don't want to bring the whole app down, because - while multiple distinct values for ASKPASS_PROGRAM don't make sense - panicking turns a benign bug into a hard crash, even if you don't end up using any remoting functionalities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that's super right. I missed the debug_panic macro
crates/util/src/paths.rs
Outdated
|
|
||
| /// Try to make a shell-safe representation of the path. | ||
| /// | ||
| /// For Unix, the path is escaped to be safe for POSIX shells |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a doc comment on the trait method itself, not on it's implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the methods of this trait have the doc comment on the implementations. Should i move all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that'd be best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the doc comments to the trait definition
crates/util/src/util.rs
Outdated
| .to_string()) | ||
| } | ||
|
|
||
| /// Returns a shell escaped path for the zed cli executable, this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: is this doc comment outdated? The returned path is no longer shell-escaped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, i've missed that
crates/util/src/paths.rs
Outdated
| // As of writing, this can only be fail if the path contains a null byte, which shouldn't be possible | ||
| // but shlex has annotated the error as #[non_exhaustive] so we can't make it a compile error if other | ||
| // errors are introduced in the future :( | ||
| Ok(shlex::try_quote(path_str)?.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Ok(shlex::try_quote(path_str)?.to_string()) | |
| Ok(shlex::try_quote(path_str)?.into()) |
I'm not sure if that'll compile from the get-go, but to_string can be slower than String::from. Not that it matters though, so feel free to disregard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good catch. The method returns Cow, so into() could indeed be faster. I've made the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, in that case you can even go the extra mile and use into_owned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. Done
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
osiewicz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Will give it a go with other platforms before merging.
|
Thanks so much for the follow ups @marcocondrache |
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
|
@maxbrunsfeld @osiewicz thank you for the support! |
|
I've tested this on Windows -> Linux and Mac -> Linux SSH scenarios. In both cases it fixed git usage. |
The author has applied Max's feedback + I've manually tested the code.
|
/cherry-pick v0.207.x |
Closes #39469 Closes #39438 Closes #39458 I'm not able to test it, i would appreciate if somebody could do it. I think this bug was present also for SSH remote projects Release Notes: - Fixed an issue where zed bin was not found in remote servers for askpass --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
…s#39475) Closes zed-industries#39469 Closes zed-industries#39438 Closes zed-industries#39458 I'm not able to test it, i would appreciate if somebody could do it. I think this bug was present also for SSH remote projects Release Notes: - Fixed an issue where zed bin was not found in remote servers for askpass --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Closes #39469
Closes #39438
Closes #39458
I'm not able to test it, i would appreciate if somebody could do it. I think this bug was present also for SSH remote projects
Release Notes: