add detection for integrated cli, verify

This commit is contained in:
Connor Peet
2022-09-26 07:22:58 +02:00
parent 07453efc00
commit 889fbd2f1b
10 changed files with 52 additions and 157 deletions

View File

@@ -0,0 +1,32 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use std::{env, io};
use crate::constants::VSCODE_CLI_QUALITY;
pub fn is_integrated_cli() -> io::Result<bool> {
let exe = env::current_exe()?;
let parent = match exe.parent().and_then(|p| p.parent()) {
Some(p) => p,
None => return Ok(false),
};
let expected_file = if cfg!(windows) {
match VSCODE_CLI_QUALITY {
Some("insider") => "Code - Insiders.exe",
Some("exploration") => "Code - Exploration.exe",
_ => "Code.exe",
}
} else {
match VSCODE_CLI_QUALITY {
Some("insider") => "code-insiders",
Some("exploration") => "code-exploration",
_ => "code",
}
};
Ok(parent.join(expected_file).exists())
}

View File

@@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use crate::util::errors;
use std::path::Path;
use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt};
@@ -49,30 +49,3 @@ pub fn find_running_process(name: &Path) -> Option<u32> {
}
None
}
#[cfg(not(target_family = "unix"))]
pub async fn set_executable_permission<P: AsRef<std::path::Path>>(
_file: P,
) -> Result<(), errors::WrappedError> {
Ok(())
}
#[cfg(target_family = "unix")]
pub async fn set_executable_permission<P: AsRef<std::path::Path>>(
file: P,
) -> Result<(), errors::WrappedError> {
use std::os::unix::prelude::PermissionsExt;
let mut permissions = tokio::fs::metadata(&file)
.await
.map_err(|e| errors::wrap(e, "failed to read executable file metadata"))?
.permissions();
permissions.set_mode(0o750);
tokio::fs::set_permissions(&file, permissions)
.await
.map_err(|e| errors::wrap(e, "failed to set executable permissions"))?;
Ok(())
}