Mathias Gottschlag 5 лет назад
Родитель
Сommit
7310428904
2 измененных файлов: 16 добавлений и 21 удалений
  1. 5
    21
      src/bin/server.rs
  2. 11
    0
      src/paths.rs

+ 5
- 21
src/bin/server.rs Просмотреть файл

@@ -9,35 +9,19 @@ use log::*;
9 9
 use tokio::net::{TcpListener, TcpStream};
10 10
 use tokio::stream::StreamExt;
11 11
 
12
-use twfss::Database;
13
-
14
-fn config_dir() -> String {
15
-    format!(
16
-        "{}/.config/twfss",
17
-        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
18
-    )
19
-}
20
-
21
-fn data_dir() -> String {
22
-    format!(
23
-        "{}/.local/share/twfss-server",
24
-        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
25
-    )
26
-}
27
-
28
-fn db_path() -> String {
29
-    format!("{}/server.db", data_dir())
30
-}
12
+use twfss::{paths, Database};
31 13
 
32 14
 #[tokio::main]
33 15
 async fn main() {
34 16
     env_logger::init();
35 17
 
36 18
     // Create the configuration directory if necessary.
37
-    create_dir_all(config_dir()).unwrap();
19
+    create_dir_all(paths::config_dir()).unwrap();
38 20
 
39 21
     // Read configuration.
40
-    let _db = Arc::new(Mutex::new(Database::create_or_open(&db_path()).unwrap()));
22
+    let _db = Arc::new(Mutex::new(
23
+        Database::create_or_open(&paths::server_db()).unwrap(),
24
+    ));
41 25
     // TODO
42 26
 
43 27
     // Start a thread that periodically checks whether the maximum database size

+ 11
- 0
src/paths.rs Просмотреть файл

@@ -12,10 +12,21 @@ pub fn client_data() -> String {
12 12
     )
13 13
 }
14 14
 
15
+pub fn server_data() -> String {
16
+    format!(
17
+        "{}/.local/share/twfss-server",
18
+        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
19
+    )
20
+}
21
+
15 22
 pub fn client_db() -> String {
16 23
     format!("{}/client.db", client_data())
17 24
 }
18 25
 
26
+pub fn server_db() -> String {
27
+    format!("{}/client.db", client_data())
28
+}
29
+
19 30
 pub fn client_socket() -> String {
20 31
     format!("{}/client.sock", client_data())
21 32
 }

Загрузка…
Отмена
Сохранить