дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-19 16:15:42 +02:00
Порівняти коміти
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
4304d10021 | ||
|
|
4b7870ba2a |
No files matched your search
@@ -325,6 +325,20 @@ pub fn migrate(data: &Path, local: &Path) {
|
||||
if cfg!(target_os = "windows") && data != local {
|
||||
migrate_entries(data, local);
|
||||
}
|
||||
if cfg!(target_os = "windows") {
|
||||
relative_tool_shims(&local.join("tools"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrappers written before they named their tool relative to themselves hold its absolute
|
||||
/// path, which cmd.exe can't find through a non-ASCII user directory (#3338).
|
||||
fn relative_tool_shims(tools: &Path) {
|
||||
let Ok(entries) = fs::read_dir(tools) else { return };
|
||||
for dir in entries.flatten().map(|e| e.path()).filter(|p| p.is_dir()) {
|
||||
if let Err(error) = relocate_shims(&dir, &dir) {
|
||||
tracing::warn!(%error, ?dir, "cannot make the tool's wrappers relative");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn migrate_entries(data: &Path, local: &Path) {
|
||||
@@ -651,6 +665,22 @@ mod tests {
|
||||
fs::set_permissions(&dir, fs::Permissions::from_mode(0o755)).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installed_tool_wrappers_become_relative() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let tools = tmp.path().join("tools");
|
||||
let tool = tools.join("taplo");
|
||||
fs::create_dir_all(tool.join("bin")).unwrap();
|
||||
let shim = tool.join("bin/taplo.cmd");
|
||||
fs::write(&shim, format!("@echo off\r\n\"{}\\taplo.exe\" %*\r\n", tool.display())).unwrap();
|
||||
// A wrapper the user re-saved in another encoding is left alone.
|
||||
fs::create_dir_all(tools.join("other/bin")).unwrap();
|
||||
fs::write(tools.join("other/bin/x.cmd"), b"@echo off\r\n\"C:\\\xd5\xc5\" %*\r\n").unwrap();
|
||||
relative_tool_shims(&tools);
|
||||
assert_eq!(fs::read_to_string(&shim).unwrap(), "@echo off\r\n\"%~dp0..\\taplo.exe\" %*\r\n");
|
||||
relative_tool_shims(&tmp.path().join("missing"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wrappers_accept_mixed_separators_without_rewriting_neighbor_paths() {
|
||||
let text = "@echo off\r\n\"C:\\old\\tools/demo\\payload.exe\" \"C:\\old\\tools/demo-other\\x\" %*\r\n";
|
||||
|
||||
@@ -331,8 +331,8 @@ pub fn env_wrapper(bin_dir: &Path, command: &str, target: &Path, env: &[(&str, &
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let link = bin_dir.join(format!("{command}.cmd"));
|
||||
let vars: String = env.iter().map(|(k, v)| format!("set \"{k}={}\"\r\n", v.display())).collect();
|
||||
fs::write(&link, format!("@echo off\r\nsetlocal\r\n{vars}\"{}\" %*\r\n", target.display()))?;
|
||||
let vars: String = env.iter().map(|(k, v)| format!("set \"{k}={}\"\r\n", cmd_path(bin_dir, v))).collect();
|
||||
fs::write(&link, format!("@echo off\r\nsetlocal\r\n{vars}\"{}\" %*\r\n", cmd_path(bin_dir, target)))?;
|
||||
Ok(link)
|
||||
}
|
||||
}
|
||||
@@ -357,11 +357,25 @@ pub fn link_executable(bin_dir: &Path, command: &str, target: &Path) -> IdeResul
|
||||
{
|
||||
let link = bin_dir.join(format!("{command}.cmd"));
|
||||
let runner = if target.extension().is_some_and(|e| e == "js") { "node " } else { "" };
|
||||
fs::write(&link, format!("@echo off\r\n{runner}\"{}\" %*\r\n", target.display()))?;
|
||||
fs::write(&link, format!("@echo off\r\n{runner}\"{}\" %*\r\n", cmd_path(bin_dir, target)))?;
|
||||
Ok(link)
|
||||
}
|
||||
}
|
||||
|
||||
/// `path` as a `.cmd` shim in `bin_dir` names it: relative to the shim (`%~dp0..\…`) when it
|
||||
/// is in the tool's own directory. cmd.exe reads a batch file in the console's code page, so
|
||||
/// an absolute path through a non-ASCII user directory, written as UTF-8, isn't found (#3338).
|
||||
#[cfg_attr(unix, allow(dead_code))]
|
||||
fn cmd_path(bin_dir: &Path, path: &Path) -> String {
|
||||
match bin_dir.parent().and_then(|tool| path.strip_prefix(tool).ok()) {
|
||||
Some(rest) => {
|
||||
let rest: Vec<_> = rest.components().map(|c| c.as_os_str().to_string_lossy()).collect();
|
||||
format!("%~dp0..\\{}", rest.join("\\"))
|
||||
}
|
||||
None => path.display().to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -743,6 +757,17 @@ mod tests {
|
||||
assert!(found.ends_with("server/com.microsoft.java.debug.plugin-0.53.2.jar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_shims_name_the_tool_relative_to_themselves() {
|
||||
let tool = Path::new("/Users/张三/AppData/Local/ai.l0ng.openidea/tools/taplo");
|
||||
let bin = tool.join("bin");
|
||||
assert_eq!(cmd_path(&bin, &tool.join("taplo.exe")), "%~dp0..\\taplo.exe");
|
||||
assert_eq!(cmd_path(&bin, &tool.join("gems/bin/solargraph")), "%~dp0..\\gems\\bin\\solargraph");
|
||||
// Outside the tool's directory (a system SDK) stays absolute.
|
||||
let sdk = Path::new("/usr/local/share/dotnet");
|
||||
assert_eq!(cmd_path(&bin, sdk), sdk.display().to_string());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn wrapper_runs_target() {
|
||||
|
||||
Reference in new issue
Заблокувати користувача