Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1diff --git a/src/main.rs b/src/main.rs
2index 357a33b..7073497 100644
3--- a/src/main.rs
4+++ b/src/main.rs
5@@ -1,4 +1,4 @@
6-use std::env;
7+use std::path::PathBuf;
8
9 mod devices;
10
11@@ -8,12 +8,23 @@ fn main() -> Result<(), std::io::Error> {
12 configs: vec![]
13 };
14
15- let mut config_path = env::current_exe()?;
16- config_path.pop();
17- config_path.push("uni-sync.json");
18+ let mut config_path = PathBuf::from("/etc/uni-sync/uni-sync.json");
19
20 if !config_path.exists() {
21- std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap())?;
22+ match std::fs::create_dir_all(config_path.parent().unwrap()) {
23+ Ok(result) => result,
24+ Err(_) => {
25+ println!("Please run uni-sync with elevated permissions.");
26+ std::process::exit(0);
27+ }
28+ };
29+ match std::fs::write(&config_path, serde_json::to_string_pretty(&configs).unwrap()) {
30+ Ok(result) => result,
31+ Err(_) => {
32+ println!("Please run uni-sync with elevated permissions.");
33+ std::process::exit(0);
34+ }
35+ };
36 }
37
38 let config_content = std::fs::read_to_string(&config_path).unwrap();