mirror of
https://github.com/zed-industries/zed.git
synced 2026-05-31 19:05:00 +07:00
xtask: Fix setup-webrtc config overwrite refusal and Windows path format (#57058)
Some checks are pending
Congratsbot / check-author (push) Waiting to run
Congratsbot / congrats (push) Blocked by required conditions
deploy_nightly_docs / deploy_docs (push) Has been skipped
run_tests / orchestrate (push) Waiting to run
run_tests / check_style (push) Waiting to run
run_tests / clippy_windows (push) Blocked by required conditions
run_tests / clippy_linux (push) Blocked by required conditions
run_tests / clippy_mac (push) Blocked by required conditions
run_tests / clippy_mac_x86_64 (push) Blocked by required conditions
run_tests / run_tests_windows (push) Blocked by required conditions
run_tests / run_tests_linux (push) Blocked by required conditions
run_tests / run_tests_mac (push) Blocked by required conditions
run_tests / miri_scheduler (push) Blocked by required conditions
run_tests / doctests (push) Blocked by required conditions
run_tests / check_workspace_binaries (push) Blocked by required conditions
run_tests / build_visual_tests_binary (push) Blocked by required conditions
run_tests / check_wasm (push) Blocked by required conditions
run_tests / check_dependencies (push) Blocked by required conditions
run_tests / check_docs (push) Blocked by required conditions
run_tests / check_licenses (push) Blocked by required conditions
run_tests / check_scripts (push) Blocked by required conditions
run_tests / check_postgres_and_protobuf_migrations (push) Blocked by required conditions
run_tests / extension_tests (push) Blocked by required conditions
run_tests / tests_pass (push) Blocked by required conditions
Some checks are pending
Congratsbot / check-author (push) Waiting to run
Congratsbot / congrats (push) Blocked by required conditions
deploy_nightly_docs / deploy_docs (push) Has been skipped
run_tests / orchestrate (push) Waiting to run
run_tests / check_style (push) Waiting to run
run_tests / clippy_windows (push) Blocked by required conditions
run_tests / clippy_linux (push) Blocked by required conditions
run_tests / clippy_mac (push) Blocked by required conditions
run_tests / clippy_mac_x86_64 (push) Blocked by required conditions
run_tests / run_tests_windows (push) Blocked by required conditions
run_tests / run_tests_linux (push) Blocked by required conditions
run_tests / run_tests_mac (push) Blocked by required conditions
run_tests / miri_scheduler (push) Blocked by required conditions
run_tests / doctests (push) Blocked by required conditions
run_tests / check_workspace_binaries (push) Blocked by required conditions
run_tests / build_visual_tests_binary (push) Blocked by required conditions
run_tests / check_wasm (push) Blocked by required conditions
run_tests / check_dependencies (push) Blocked by required conditions
run_tests / check_docs (push) Blocked by required conditions
run_tests / check_licenses (push) Blocked by required conditions
run_tests / check_scripts (push) Blocked by required conditions
run_tests / check_postgres_and_protobuf_migrations (push) Blocked by required conditions
run_tests / extension_tests (push) Blocked by required conditions
run_tests / tests_pass (push) Blocked by required conditions
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] No unsafe blocks - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes #57057 Release Notes: - N/A --------- Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
This commit is contained in:
parent
2a00db06ce
commit
9abb73ee32
1 changed files with 34 additions and 18 deletions
|
|
@ -219,31 +219,47 @@ fn update_cargo_config(webrtc_path: &Path) -> Result<()> {
|
|||
.or_else(|| std::env::var_os("USERPROFILE"))
|
||||
.context("could not determine home directory")?;
|
||||
let config_path = PathBuf::from(home).join(".cargo").join("config.toml");
|
||||
if config_path.exists() {
|
||||
bail!(
|
||||
"{} already exists; refusing to modify it. \
|
||||
Add `[env]\\n{ENV_VAR} = \"{}\"` yourself, \
|
||||
or re-run with --no-cargo-config.",
|
||||
config_path.display(),
|
||||
webrtc_path.display(),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(parent) = config_path.parent() {
|
||||
fs::create_dir_all(parent).with_context(|| format!("creating {}", parent.display()))?;
|
||||
}
|
||||
|
||||
let mut doc = DocumentMut::new();
|
||||
let mut env_table = Table::new();
|
||||
env_table.set_implicit(false);
|
||||
let path_str = webrtc_path
|
||||
.to_str()
|
||||
.context("webrtc path is not valid UTF-8")?;
|
||||
env_table.insert(ENV_VAR, value(path_str));
|
||||
doc.insert("env", Item::Table(env_table));
|
||||
let existing_content = if config_path.exists() {
|
||||
fs::read_to_string(&config_path)
|
||||
.with_context(|| format!("reading {}", config_path.display()))?
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let mut doc = existing_content
|
||||
.parse::<DocumentMut>()
|
||||
.with_context(|| format!("parsing existing {}", config_path.display()))?;
|
||||
|
||||
let env_table = doc
|
||||
.entry("env")
|
||||
.or_insert(Item::Table(Table::new()))
|
||||
.as_table_mut()
|
||||
.context("`env` entry is not a table")?;
|
||||
|
||||
let cleaned_path = clean_webrtc_path(webrtc_path)?;
|
||||
env_table.insert(ENV_VAR, value(cleaned_path.clone()));
|
||||
|
||||
fs::write(&config_path, doc.to_string())
|
||||
.with_context(|| format!("writing {}", config_path.display()))?;
|
||||
eprintln!("Wrote {} with {ENV_VAR}={path_str}", config_path.display());
|
||||
|
||||
eprintln!(
|
||||
"Updated {} with {ENV_VAR}={cleaned_path}",
|
||||
config_path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clean_webrtc_path(path: &Path) -> Result<String> {
|
||||
let path_str = path.to_str().context("webrtc path is not valid UTF-8")?;
|
||||
let mut cleaned = path_str.to_string();
|
||||
if cleaned.starts_with(r"\\?\") {
|
||||
cleaned = cleaned[4..].to_string();
|
||||
}
|
||||
cleaned = cleaned.replace('\\', "/");
|
||||
Ok(cleaned)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue