Pārlūkot izejas kodu

Fix client socket path.

Mathias Gottschlag 5 gadus atpakaļ
vecāks
revīzija
28759d35ca
4 mainītis faili ar 27 papildinājumiem un 9 dzēšanām
  1. 2
    7
      src/bin/cli.rs
  2. 3
    2
      src/bin/client.rs
  3. 1
    0
      src/lib.rs
  4. 21
    0
      src/paths.rs

+ 2
- 7
src/bin/cli.rs Parādīt failu

@@ -7,12 +7,7 @@ use byteorder::{BigEndian, ReadBytesExt};
7 7
 use serde::{Deserialize, Serialize};
8 8
 use structopt::StructOpt;
9 9
 
10
-pub fn socket_path() -> String {
11
-    format!(
12
-        "{}/.twfss/sock",
13
-        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
14
-    )
15
-}
10
+use twfss::paths;
16 11
 
17 12
 #[derive(StructOpt, Serialize, Deserialize)]
18 13
 #[structopt(about = "CLI for the two-way file system sync client")]
@@ -68,7 +63,7 @@ struct SyncClient {
68 63
 
69 64
 impl SyncClient {
70 65
     fn connect() -> Result<SyncClient, Error> {
71
-        let stream = UnixStream::connect(socket_path()).unwrap();
66
+        let stream = UnixStream::connect(paths::client_socket()).unwrap();
72 67
         Ok(SyncClient { stream })
73 68
     }
74 69
 

+ 3
- 2
src/bin/client.rs Parādīt failu

@@ -8,7 +8,7 @@ use tokio::stream::StreamExt;
8 8
 use tokio::sync::{mpsc, Mutex};
9 9
 use tokio::signal;
10 10
 
11
-use twfss::{Database, FileTree, ClientSideSync, FileSystemWatcher, Error, SynchronizationError};
11
+use twfss::{Database, FileTree, ClientSideSync, FileSystemWatcher, Error, SynchronizationError, paths};
12 12
 
13 13
 mod cli;
14 14
 
@@ -75,7 +75,7 @@ async fn main() {
75 75
 
76 76
     // We create the socket before starting synchronization, so that the unwrap() below does not
77 77
     // cause corruption.
78
-    let mut listener = UnixListener::bind(cli::socket_path()).unwrap();
78
+    let mut listener = UnixListener::bind(paths::client_socket()).unwrap();
79 79
     let mut incoming = listener.incoming();
80 80
 
81 81
     // Initialize the existing synchronized directories.
@@ -92,6 +92,7 @@ async fn main() {
92 92
         tokio::select! {
93 93
             result = &mut ctrl_c => {
94 94
                 result.expect("could not listen for Ctrl+C");
95
+                println!("Ctrl+C pressed, terminating...");
95 96
                 // Ctrl+C was pressed, so we terminate the program.
96 97
                 break;
97 98
             }

+ 1
- 0
src/lib.rs Parādīt failu

@@ -9,6 +9,7 @@ mod database;
9 9
 mod file_system_watcher;
10 10
 mod file_tree;
11 11
 pub mod network;
12
+pub mod paths;
12 13
 pub mod protocol;
13 14
 
14 15
 pub use client_side_sync::ClientSideSync;

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

@@ -0,0 +1,21 @@
1
+pub fn config_dir() -> String {
2
+    format!(
3
+        "{}/.config/twfss",
4
+        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
5
+    )
6
+}
7
+
8
+pub fn client_data() -> String {
9
+    format!(
10
+        "{}/.local/share/twfss-client",
11
+        dirs::home_dir().unwrap().to_str().unwrap().to_owned()
12
+    )
13
+}
14
+
15
+pub fn client_db() -> String {
16
+    format!("{}/client.db", client_data())
17
+}
18
+
19
+pub fn client_socket() -> String {
20
+    format!("{}/client.sock", client_data())
21
+}

Notiek ielāde…
Atcelt
Saglabāt