-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
36 lines (30 loc) · 962 Bytes
/
build.rs
File metadata and controls
36 lines (30 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use eyre::Result;
use std::path::PathBuf;
fn main() -> Result<()> {
#[cfg(feature = "config")]
{
let home = std::env!("HOME");
let config_dir = ".config/sui";
let res = {
let mut path = PathBuf::new();
path.push(home);
path.push(config_dir);
path.exists()
};
if !res {
let user_relative_path = ".config/sui/config.toml";
let mut config_path = PathBuf::new();
config_path.push(home);
config_path.push(user_relative_path);
let os_conf = config_path.clone().into_os_string();
save_config(&os_conf, "\n")?;
}
}
Ok(())
}
fn save_config(config_path: &std::ffi::OsStr, config_content: &str) -> Result<()> {
let parent = std::path::Path::new(&config_path).parent().unwrap();
std::fs::create_dir_all(parent)?;
std::fs::write(config_path, config_content)?;
Ok(())
}