mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
add detection for integrated cli, verify
This commit is contained in:
32
cli/src/util/is_integrated.rs
Normal file
32
cli/src/util/is_integrated.rs
Normal 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())
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user