|
|
@@ -2,9 +2,12 @@ use std::ffi::{OsStr, OsString};
|
|
2
|
2
|
use std::fs::{self, create_dir_all, remove_file};
|
|
3
|
3
|
use std::sync::Arc;
|
|
4
|
4
|
|
|
|
5
|
+use env_logger::Env;
|
|
5
|
6
|
use fslock::LockFile;
|
|
|
7
|
+use log::{error, info};
|
|
6
|
8
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
|
7
|
9
|
use tokio::net::{UnixListener, UnixStream};
|
|
|
10
|
+use tokio::signal;
|
|
8
|
11
|
use tokio::stream::StreamExt;
|
|
9
|
12
|
use tokio::sync::{mpsc, Mutex};
|
|
10
|
13
|
|
|
|
@@ -51,6 +54,8 @@ impl SynchronizedDirectory {
|
|
51
|
54
|
|
|
52
|
55
|
#[tokio::main]
|
|
53
|
56
|
async fn main() {
|
|
|
57
|
+ env_logger::from_env(Env::default().default_filter_or("info")).init();
|
|
|
58
|
+
|
|
54
|
59
|
// Create the data directories if necessary.
|
|
55
|
60
|
create_dir_all(paths::config_dir()).unwrap();
|
|
56
|
61
|
create_dir_all(paths::client_data()).unwrap();
|
|
|
@@ -59,7 +64,7 @@ async fn main() {
|
|
59
|
64
|
fs::write(&paths::client_lock(), b"").ok();
|
|
60
|
65
|
let mut lock = LockFile::open(&paths::client_lock()).expect("cannot open lockfile");
|
|
61
|
66
|
if !lock.try_lock().expect("error while locking the lock file") {
|
|
62
|
|
- eprintln!("Client already running, exiting...");
|
|
|
67
|
+ error!("Client already running, exiting...");
|
|
63
|
68
|
return;
|
|
64
|
69
|
}
|
|
65
|
70
|
|
|
|
@@ -90,7 +95,7 @@ async fn main() {
|
|
90
|
95
|
tokio::select! {
|
|
91
|
96
|
result = &mut ctrl_c => {
|
|
92
|
97
|
result.expect("could not listen for Ctrl+C");
|
|
93
|
|
- println!("Ctrl+C pressed, terminating...");
|
|
|
98
|
+ info!("Ctrl+C pressed, terminating...");
|
|
94
|
99
|
// Ctrl+C was pressed, so we terminate the program.
|
|
95
|
100
|
break;
|
|
96
|
101
|
}
|
|
|
@@ -111,18 +116,18 @@ async fn main() {
|
|
111
|
116
|
};
|
|
112
|
117
|
}
|
|
113
|
118
|
Some(Err(err)) => {
|
|
114
|
|
- eprintln!("Error while listening on the local unix socket: {:?}", err);
|
|
|
119
|
+ error!("Error while listening on the local unix socket: {:?}", err);
|
|
115
|
120
|
break;
|
|
116
|
121
|
}
|
|
117
|
122
|
None => {
|
|
118
|
|
- eprintln!("listening for CLI connections failed");
|
|
|
123
|
+ error!("listening for CLI connections failed");
|
|
119
|
124
|
break;
|
|
120
|
125
|
}
|
|
121
|
126
|
}
|
|
122
|
127
|
}
|
|
123
|
128
|
error = errors.next() => {
|
|
124
|
129
|
let error = error.unwrap();
|
|
125
|
|
- eprintln!("error: {:?}", error.error);
|
|
|
130
|
+ error!("Synchronization error: {:?}", error.error);
|
|
126
|
131
|
for directory in directories.iter_mut() {
|
|
127
|
132
|
if directory.path == error.directory {
|
|
128
|
133
|
// In theory, there could be a race condition here where we pause a
|
|
|
@@ -204,4 +209,3 @@ async fn handle_cli_client(
|
|
204
|
209
|
|
|
205
|
210
|
Ok(())
|
|
206
|
211
|
}
|
|
207
|
|
-
|