Pārlūkot izejas kodu

Move server path definitions.

Mathias Gottschlag 5 gadus atpakaļ
vecāks
revīzija
7310428904
2 mainītis faili ar 16 papildinājumiem un 21 dzēšanām
  1. 5
    21
      src/bin/server.rs
  2. 11
    0
      src/paths.rs

+ 5
- 21
src/bin/server.rs Parādīt failu

9
 use tokio::net::{TcpListener, TcpStream};
9
 use tokio::net::{TcpListener, TcpStream};
10
 use tokio::stream::StreamExt;
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
 #[tokio::main]
14
 #[tokio::main]
33
 async fn main() {
15
 async fn main() {
34
     env_logger::init();
16
     env_logger::init();
35
 
17
 
36
     // Create the configuration directory if necessary.
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
     // Read configuration.
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
     // TODO
25
     // TODO
42
 
26
 
43
     // Start a thread that periodically checks whether the maximum database size
27
     // Start a thread that periodically checks whether the maximum database size

+ 11
- 0
src/paths.rs Parādīt failu

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
 pub fn client_db() -> String {
22
 pub fn client_db() -> String {
16
     format!("{}/client.db", client_data())
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
 pub fn client_socket() -> String {
30
 pub fn client_socket() -> String {
20
     format!("{}/client.sock", client_data())
31
     format!("{}/client.sock", client_data())
21
 }
32
 }

Notiek ielāde…
Atcelt
Saglabāt