Skip to content

Commit 52804bf

Browse files
committed
cli: allow passing direct path to the vscode cli in --install-dir
Fixes microsoft#164622
1 parent ac05245 commit 52804bf

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

cli/src/desktop/version_manager.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ impl CodeVersionManager {
138138
pub async fn get_entrypoint_for_install_dir(path: &Path) -> Option<PathBuf> {
139139
use tokio::sync::mpsc;
140140

141+
// Check whether the user is supplying a path to the CLI directly (e.g. #164622)
142+
if let Ok(true) = path.metadata().map(|m| m.is_file()) {
143+
let result = std::process::Command::new(path)
144+
.args(["--version"])
145+
.output()
146+
.map(|o| o.status.success());
147+
148+
if let Ok(true) = result {
149+
return Some(path.to_owned());
150+
}
151+
}
152+
141153
let (tx, mut rx) = mpsc::channel(1);
142154

143155
// Look for all the possible paths in parallel
@@ -576,4 +588,37 @@ mod tests {
576588
.is_none()
577589
);
578590
}
591+
592+
#[tokio::test]
593+
async fn test_gets_entrypoint_as_binary() {
594+
let dir = tempfile::tempdir().expect("expected to make temp dir");
595+
596+
#[cfg(windows)]
597+
let binary_file_path = {
598+
let path = dir.path().join("code.cmd");
599+
File::create(&path).expect("expected to create file");
600+
path
601+
};
602+
603+
#[cfg(unix)]
604+
let binary_file_path = {
605+
use std::fs;
606+
use std::os::unix::fs::PermissionsExt;
607+
608+
let path = dir.path().join("code");
609+
{
610+
let mut f = File::create(&path).expect("expected to create file");
611+
f.write_all(b"#!/bin/sh")
612+
.expect("expected to write to file");
613+
}
614+
fs::set_permissions(&path, fs::Permissions::from_mode(0o777))
615+
.expect("expected to set permissions");
616+
path
617+
};
618+
619+
assert_eq!(
620+
CodeVersionManager::get_entrypoint_for_install_dir(&binary_file_path).await,
621+
Some(binary_file_path)
622+
);
623+
}
579624
}

0 commit comments

Comments
 (0)