mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-09 08:42:03 +08:00
fix: plugin in windows
This commit is contained in:
@@ -70,11 +70,7 @@ impl PluginDataStore {
|
|||||||
.await?;
|
.await?;
|
||||||
file.sync_all().await?;
|
file.sync_all().await?;
|
||||||
drop(file);
|
drop(file);
|
||||||
#[cfg(windows)]
|
replace_file(&temporary, &path).await?;
|
||||||
if path.exists() {
|
|
||||||
tokio::fs::remove_file(&path).await?;
|
|
||||||
}
|
|
||||||
tokio::fs::rename(&temporary, &path).await?;
|
|
||||||
set_file_permissions(&path)?;
|
set_file_permissions(&path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -106,6 +102,41 @@ impl PluginDataStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 原子替换目标文件。Windows 上 rename 不覆盖已存在文件,且目标可能被
|
||||||
|
/// 杀毒软件或索引器短暂锁定(拒绝访问/共享冲突),需删除后重试。
|
||||||
|
async fn replace_file(temporary: &Path, path: &Path) -> Result<()> {
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
const ACCESS_DENIED: i32 = 5;
|
||||||
|
const SHARING_VIOLATION: i32 = 32;
|
||||||
|
let mut attempts = 0;
|
||||||
|
loop {
|
||||||
|
if path.exists() {
|
||||||
|
let _ = tokio::fs::remove_file(path).await;
|
||||||
|
}
|
||||||
|
match tokio::fs::rename(temporary, path).await {
|
||||||
|
Ok(()) => return Ok(()),
|
||||||
|
Err(error)
|
||||||
|
if attempts < 10
|
||||||
|
&& matches!(
|
||||||
|
error.raw_os_error(),
|
||||||
|
Some(ACCESS_DENIED | SHARING_VIOLATION)
|
||||||
|
) =>
|
||||||
|
{
|
||||||
|
attempts += 1;
|
||||||
|
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||||
|
}
|
||||||
|
Err(error) => return Err(error.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
tokio::fs::rename(temporary, path).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn validate_component(value: &str, label: &str) -> Result<()> {
|
fn validate_component(value: &str, label: &str) -> Result<()> {
|
||||||
if value.is_empty()
|
if value.is_empty()
|
||||||
|| value.len() > 128
|
|| value.len() > 128
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ impl PluginDefinitionLoader {
|
|||||||
) -> Result<PluginModuleDefinition> {
|
) -> Result<PluginModuleDefinition> {
|
||||||
let entry_url = file_url(entry)?;
|
let entry_url = file_url(entry)?;
|
||||||
let mut command = tokio::process::Command::new(executable);
|
let mut command = tokio::process::Command::new(executable);
|
||||||
|
super::detach_console(&mut command);
|
||||||
command
|
command
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ fn extract_runtime_archive(archive: &Path, output: &Path, executable_name: &str)
|
|||||||
|
|
||||||
async fn validate_runtime(executable: &Path, cancellation: &CancellationToken) -> Result<()> {
|
async fn validate_runtime(executable: &Path, cancellation: &CancellationToken) -> Result<()> {
|
||||||
let mut command = tokio::process::Command::new(executable);
|
let mut command = tokio::process::Command::new(executable);
|
||||||
|
super::detach_console(&mut command);
|
||||||
command
|
command
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
|
|||||||
@@ -21,3 +21,12 @@ pub use descriptor::{
|
|||||||
pub use registry::{ImportResponse, OAuthBeginResponse, OAuthPollResponse, PluginRegistry};
|
pub use registry::{ImportResponse, OAuthBeginResponse, OAuthPollResponse, PluginRegistry};
|
||||||
pub use runtime::{PluginRuntime, PluginRuntimePhase, PluginRuntimeState, PluginRuntimeStatus};
|
pub use runtime::{PluginRuntime, PluginRuntimePhase, PluginRuntimeState, PluginRuntimeStatus};
|
||||||
pub(crate) use wire::llm_request as plugin_llm_request;
|
pub(crate) use wire::llm_request as plugin_llm_request;
|
||||||
|
|
||||||
|
/// Windows 下阻止 Deno 子进程弹出控制台窗口(CREATE_NO_WINDOW)。
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn detach_console(command: &mut tokio::process::Command) {
|
||||||
|
command.creation_flags(0x0800_0000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn detach_console(_command: &mut tokio::process::Command) {}
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ impl PluginWorker {
|
|||||||
async fn spawn(&self) -> Result<WorkerProcess> {
|
async fn spawn(&self) -> Result<WorkerProcess> {
|
||||||
let entry_url = file_url(&self.inner.entry)?;
|
let entry_url = file_url(&self.inner.entry)?;
|
||||||
let mut command = tokio::process::Command::new(&self.inner.executable);
|
let mut command = tokio::process::Command::new(&self.inner.executable);
|
||||||
|
super::detach_console(&mut command);
|
||||||
command
|
command
|
||||||
.arg("run")
|
.arg("run")
|
||||||
.arg("--quiet")
|
.arg("--quiet")
|
||||||
|
|||||||
Reference in New Issue
Block a user