fix cfg
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -90,7 +90,10 @@ fn run_setup() -> Result<()> {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.to_path_buf();
|
.to_path_buf();
|
||||||
let cfg_file = config::config_file();
|
let cfg_file = config::config_file();
|
||||||
let site_config = log_dir.join("public").join("config.json");
|
let site_config = dirs::config_dir()
|
||||||
|
.expect("Cannot find config directory")
|
||||||
|
.join("ai.syui.log")
|
||||||
|
.join("config.json");
|
||||||
let aigpt_bin = std::env::current_exe().unwrap_or_else(|_| "aigpt".into());
|
let aigpt_bin = std::env::current_exe().unwrap_or_else(|_| "aigpt".into());
|
||||||
|
|
||||||
// 1. ~/ai/
|
// 1. ~/ai/
|
||||||
@@ -114,22 +117,14 @@ fn run_setup() -> Result<()> {
|
|||||||
|
|
||||||
// 3. config symlink
|
// 3. config symlink
|
||||||
std::fs::create_dir_all(&cfg_dir)?;
|
std::fs::create_dir_all(&cfg_dir)?;
|
||||||
if !cfg_file.exists() {
|
if cfg_file.is_symlink() || cfg_file.exists() {
|
||||||
|
std::fs::remove_file(&cfg_file)?;
|
||||||
|
}
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
std::os::unix::fs::symlink(&site_config, &cfg_file)?;
|
std::os::unix::fs::symlink(&site_config, &cfg_file)?;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
std::os::windows::fs::symlink_file(&site_config, &cfg_file)?;
|
std::os::windows::fs::symlink_file(&site_config, &cfg_file)?;
|
||||||
println!("ok {} -> {}", cfg_file.display(), site_config.display());
|
println!("ok {} -> {}", cfg_file.display(), site_config.display());
|
||||||
} else if cfg_file.is_symlink() {
|
|
||||||
let target = std::fs::read_link(&cfg_file)?;
|
|
||||||
if target == site_config {
|
|
||||||
println!("skip {} (linked)", cfg_file.display());
|
|
||||||
} else {
|
|
||||||
println!("skip {} (symlink -> {})", cfg_file.display(), target.display());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("skip {} (exists)", cfg_file.display());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. init data dirs
|
// 4. init data dirs
|
||||||
config::init();
|
config::init();
|
||||||
|
|||||||
Reference in New Issue
Block a user