浏览代码

Fix client socket path.

父节点
当前提交
28759d35ca
共有 4 个文件被更改,包括 27 次插入9 次删除
  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 查看文件

7
 use serde::{Deserialize, Serialize};
7
 use serde::{Deserialize, Serialize};
8
 use structopt::StructOpt;
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
 #[derive(StructOpt, Serialize, Deserialize)]
12
 #[derive(StructOpt, Serialize, Deserialize)]
18
 #[structopt(about = "CLI for the two-way file system sync client")]
13
 #[structopt(about = "CLI for the two-way file system sync client")]
68
 
63
 
69
 impl SyncClient {
64
 impl SyncClient {
70
     fn connect() -> Result<SyncClient, Error> {
65
     fn connect() -> Result<SyncClient, Error> {
71
-        let stream = UnixStream::connect(socket_path()).unwrap();
66
+        let stream = UnixStream::connect(paths::client_socket()).unwrap();
72
         Ok(SyncClient { stream })
67
         Ok(SyncClient { stream })
73
     }
68
     }
74
 
69
 

+ 3
- 2
src/bin/client.rs 查看文件

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

+ 1
- 0
src/lib.rs 查看文件

9
 mod file_system_watcher;
9
 mod file_system_watcher;
10
 mod file_tree;
10
 mod file_tree;
11
 pub mod network;
11
 pub mod network;
12
+pub mod paths;
12
 pub mod protocol;
13
 pub mod protocol;
13
 
14
 
14
 pub use client_side_sync::ClientSideSync;
15
 pub use client_side_sync::ClientSideSync;

+ 21
- 0
src/paths.rs 查看文件

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
+}

正在加载...
取消
保存