mirror of
https://github.com/jackwener/wx-cli.git
synced 2026-10-08 23:35:45 +00:00
fix: Windows init and daemon startup (issue #5)
Three related bugs caused "wx init" and daemon startup to fail on Windows: 1. init.rs: create ~/.wx-cli/ before writing all_keys.json (was created only before config.json, so first write failed with ENOENT) 2. transport.rs (Windows): daemon.log was always empty because stderr was never redirected, and log file open silently fell back to null when parent dir didn't exist. Now mirror the Unix version: create parent dir, try_clone to redirect both stdout and stderr. 3. server.rs (Windows): interprocess GenericNamespaced auto-prepends \\.\pipe\ on Windows. Passing the full path caused a double-prefixed pipe name that clients (using raw \\.\pipe\wx-cli-daemon) could never connect to, leading to the 15s startup timeout.
This commit is contained in:
+6
-5
@@ -43,6 +43,12 @@ pub fn cmd_init(force: bool) -> Result<()> {
|
||||
println!("扫描加密密钥(需要 root 权限)...");
|
||||
let entries = scanner::scan_keys(&db_dir)?;
|
||||
|
||||
// 确保父目录存在(如 ~/.wx-cli/),必须在任何写入之前
|
||||
if let Some(parent) = config_path.parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.with_context(|| format!("创建目录失败: {}", parent.display()))?;
|
||||
}
|
||||
|
||||
// Step 3: 保存 all_keys.json
|
||||
let keys_file_path = config_path.parent()
|
||||
.unwrap_or(std::path::Path::new("."))
|
||||
@@ -75,11 +81,6 @@ pub fn cmd_init(force: bool) -> Result<()> {
|
||||
cfg.entry("keys_file".into()).or_insert_with(|| json!("all_keys.json"));
|
||||
cfg.entry("decrypted_dir".into()).or_insert_with(|| json!("decrypted"));
|
||||
|
||||
// 确保父目录存在(如 ~/.wx-cli/)
|
||||
if let Some(parent) = config_path.parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.with_context(|| format!("创建目录失败: {}", parent.display()))?;
|
||||
}
|
||||
std::fs::write(&config_path, serde_json::to_string_pretty(&cfg)?)
|
||||
.context("写入 config.json 失败")?;
|
||||
println!("配置已保存: {}", config_path.display());
|
||||
|
||||
Reference in New Issue
Block a user