Skip to content

Commit 52b7063

Browse files
committed
clippy fixes
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 13a5d2c commit 52b7063

8 files changed

Lines changed: 50 additions & 60 deletions

File tree

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Debug for Bind {
150150
Bind::Unix(path, permissions) => f
151151
.debug_tuple("Unix")
152152
.field(path)
153-
.field(&format!("0{:0}", permissions))
153+
.field(&format!("0{permissions:0}"))
154154
.finish(),
155155
}
156156
}

src/connection.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl ActiveConnections {
5757
pub fn remove(&self, user: &UserId) {
5858
if let Entry::Occupied(e) = self.0.entry(user.clone()) {
5959
if e.get().receiver_count() == 1 {
60-
log::debug!("Removing {} from active connections", user);
60+
log::debug!("Removing {user} from active connections");
6161
METRICS.remove_user();
6262
e.remove();
6363
}
@@ -96,8 +96,8 @@ pub async fn handle_user_socket(
9696
{
9797
Ok(Ok(user_id)) => user_id,
9898
Ok(Err(e)) => {
99-
log::warn!("{}", e);
100-
ws.send(Message::text(format!("err: {}", e))).await.ok();
99+
log::warn!("{e:#}");
100+
ws.send(Message::text(format!("err: {e:#}"))).await.ok();
101101
return;
102102
}
103103
Err(_) => {
@@ -108,7 +108,7 @@ pub async fn handle_user_socket(
108108
}
109109
};
110110

111-
log::info!("new websocket authenticated as {}", user_id);
111+
log::info!("new websocket authenticated as {user_id}");
112112
ws.send(Message::text("authenticated")).await.ok();
113113

114114
let mut rx = match app.connections.add(user_id.clone()) {
@@ -149,7 +149,7 @@ pub async fn handle_user_socket(
149149
match msg {
150150
Ok(Ok(msg)) => {
151151
if let Some(msg) = send_queue.push(msg, now) {
152-
log::debug!(target: "notify_push::send", "Sending {} to {}", msg, user_id);
152+
log::debug!(target: "notify_push::send", "Sending {msg} to {user_id}");
153153
METRICS.add_message(msg.message_type());
154154
last_send = now;
155155
user_ws_tx.send(msg.into_message(&opts)).await.ok();
@@ -165,18 +165,18 @@ pub async fn handle_user_socket(
165165
for msg in send_queue.drain(now, METRICS.active_connection_count() + 50000, opts.max_debounce_time) {
166166
last_send = now;
167167
METRICS.add_message(msg.message_type());
168-
log::debug!(target: "notify_push::send", "Sending debounced {} to {}", msg, user_id);
168+
log::debug!(target: "notify_push::send", "Sending debounced {msg} to {user_id}");
169169
user_ws_tx.feed(msg.into_message(&opts)).await.ok();
170170
}
171171

172172
if now.duration_since(last_send) > PING_INTERVAL {
173173
let data = rng.gen::<NonZeroUsize>().into();
174174
let last_ping = expect_pong.swap(data, Ordering::SeqCst);
175175
if last_ping > 0 {
176-
log::info!("{} didn't reply to ping, closing", user_id);
176+
log::info!("{user_id} didn't reply to ping, closing");
177177
break;
178178
}
179-
log::debug!(target: "notify_push::send", "Sending ping to {}", user_id);
179+
log::debug!(target: "notify_push::send", "Sending ping to {user_id}");
180180
last_send = now;
181181
user_ws_tx
182182
.feed(Message::ping(data.to_le_bytes()))
@@ -223,9 +223,9 @@ pub async fn handle_user_socket(
223223
match formatted.as_str() {
224224
"WebSocket protocol error: Connection reset without closing handshake"
225225
| "IO error: Connection reset by peer (os error 104)" => {
226-
log::debug!("websocket error: {}", e)
226+
log::debug!("websocket error: {e:#}")
227227
}
228-
_ => log::warn!("websocket error: {}", e),
228+
_ => log::warn!("websocket error: {e:#}"),
229229
};
230230
break;
231231
}
@@ -269,10 +269,7 @@ async fn socket_auth(
269269
app.pre_auth.retain(|_, (time, _)| *time > cutoff);
270270

271271
if let Some((_, (_, user))) = app.pre_auth.remove(password) {
272-
log::debug!(
273-
"Authenticated socket for {} using pre authenticated token",
274-
user
275-
);
272+
log::debug!("Authenticated socket for {user} using pre authenticated token");
276273
return Ok(user);
277274
}
278275

src/lib.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl App {
162162
.send_to_user(&user, PushMessage::File(file_id.into()));
163163
}
164164
}
165-
Err(e) => log::error!("{:#}", e),
165+
Err(e) => log::error!("{e:#}"),
166166
}
167167
}
168168
Event::GroupUpdate(GroupUpdate { user, .. }) => {
@@ -196,8 +196,8 @@ impl App {
196196
}
197197
Event::Config(event::Config::LogSpec(spec)) => {
198198
match self.log_handle.lock().await.parse_and_push_temp_spec(&spec) {
199-
Ok(()) => log::info!("Set log level to {}", spec),
200-
Err(e) => log::error!("Failed to set log level: {:?}", e),
199+
Ok(()) => log::info!("Set log level to {spec}"),
200+
Err(e) => log::error!("Failed to set log level: {e:#}"),
201201
}
202202
}
203203
Event::Config(event::Config::LogRestore) => {
@@ -213,15 +213,15 @@ impl App {
213213
)
214214
.await
215215
{
216-
log::warn!("Failed to set metrics: {}", e);
216+
log::warn!("Failed to set metrics: {e:#}");
217217
}
218218
}
219-
Err(e) => log::warn!("Failed to set metrics: {}", e),
219+
Err(e) => log::warn!("Failed to set metrics: {e:#}"),
220220
},
221221
Event::Signal(event::Signal::Reset) => {
222222
log::info!("Stopping all open connections");
223223
if let Err(e) = self.reset_tx.send(()) {
224-
log::warn!("Failed to send reset command to all connections: {}", e);
224+
log::warn!("Failed to send reset command to all connections: {e:#}");
225225
}
226226
}
227227
}
@@ -270,7 +270,7 @@ pub fn serve(
270270
.and(app.clone())
271271
.map(|app: Arc<App>| {
272272
let cookie = app.test_cookie.load(Ordering::SeqCst);
273-
log::debug!("current test cookie is {}", cookie);
273+
log::debug!("current test cookie is {cookie}");
274274
cookie.to_string()
275275
});
276276

@@ -279,12 +279,12 @@ pub fn serve(
279279
.and_then(|app: Arc<App>| async move {
280280
let response = match app.nc_client.get_test_cookie().await {
281281
Ok(cookie) => {
282-
log::debug!("got remote test cookie {}", cookie);
282+
log::debug!("got remote test cookie {cookie}");
283283
cookie.to_string()
284284
}
285285
Err(e) => {
286-
log::warn!("Error while trying to get cookie from Nextcloud {:#}", e);
287-
format!("{:#}", e)
286+
log::warn!("Error while trying to get cookie from Nextcloud {e:#}");
287+
format!("{e:#}")
288288
}
289289
};
290290

@@ -300,16 +300,11 @@ pub fn serve(
300300
.await
301301
.map(|access| {
302302
let count = access.count();
303-
log::debug!("storage mapping count for {} = {}", storage_id, count);
303+
log::debug!("storage mapping count for {storage_id} = {count}");
304304
count
305305
})
306-
.map_err(|err| {
307-
log::error!(
308-
"error while getting mapping count for {}: {:#}",
309-
storage_id,
310-
err
311-
);
312-
err
306+
.inspect_err(|err| {
307+
log::error!("error while getting mapping count for {storage_id}: {err:#}");
313308
})
314309
.unwrap_or(0);
315310
Result::<_, Infallible>::Ok(access.to_string())
@@ -324,7 +319,7 @@ pub fn serve(
324319
.await
325320
.map(|remote| remote.to_string())
326321
.unwrap_or_else(|e| e.to_string());
327-
log::debug!("got remote {} when trying to set remote {}", result, remote);
322+
log::debug!("got remote {result} when trying to set remote {remote}");
328323
Result::<_, Infallible>::Ok(result)
329324
});
330325

@@ -341,7 +336,7 @@ pub fn serve(
341336
"set"
342337
}
343338
Err(e) => {
344-
log::warn!("Failed to get redis connection for version set: {:#}", e);
339+
log::warn!("Failed to get redis connection for version set: {e:#}");
345340
"error"
346341
}
347342
})
@@ -412,7 +407,7 @@ pub async fn listen_loop(app: Arc<App>, cancel: oneshot::Receiver<()>) {
412407
let loop_ = async move {
413408
loop {
414409
if let Err(e) = listen(app.clone()).await {
415-
log::error!("Failed to setup redis subscription: {:#}", e);
410+
log::error!("Failed to setup redis subscription: {e:#}");
416411
}
417412
log::warn!("Redis server disconnected, reconnecting in 1s");
418413
sleep(Duration::from_secs(1)).await;
@@ -438,12 +433,11 @@ pub async fn listen(app: Arc<App>) -> Result<()> {
438433
Ok(event) => {
439434
log::debug!(
440435
target: "notify_push::receive",
441-
"Received {}",
442-
event
436+
"Received {event}"
443437
);
444438
tokio::spawn(handle(event));
445439
}
446-
Err(e) => log::warn!("{:#}", e),
440+
Err(e) => log::warn!("{e:#}"),
447441
}
448442
}
449443
Ok(())

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> Result<()> {
3232
let config = Config::from_opt(opt)?;
3333

3434
if dump_config {
35-
println!("{:#?}", config);
35+
println!("{config:#?}");
3636
return Ok(());
3737
}
3838

@@ -64,7 +64,7 @@ async fn run(config: Config, log_handle: LoggerHandle) -> Result<()> {
6464
let (metrics_cancel, metrics_cancel_handle) = oneshot::channel();
6565
let (listen_cancel, listen_cancel_handle) = oneshot::channel();
6666

67-
log::trace!("Running with config: {:?}", config);
67+
log::trace!("Running with config: {config:?}");
6868

6969
if config.allow_self_signed {
7070
log::info!("Running with certificate validation disabled");
@@ -81,10 +81,10 @@ async fn run(config: Config, log_handle: LoggerHandle) -> Result<()> {
8181
let max_connection_time = config.max_connection_time;
8282
let app = Arc::new(App::new(config, log_handle).await?);
8383
if let Err(e) = app.self_test().await {
84-
log::error!("Self test failed: {:#}", e);
84+
log::error!("Self test failed: {e:#}");
8585
}
8686

87-
log::trace!("Listening on {}", bind);
87+
log::trace!("Listening on {bind}");
8888
let server = spawn(serve(
8989
app.clone(),
9090
bind,
@@ -95,7 +95,7 @@ async fn run(config: Config, log_handle: LoggerHandle) -> Result<()> {
9595
)?);
9696

9797
if let Some(metrics_bind) = metrics_bind {
98-
log::trace!("Metrics listening {}", metrics_bind);
98+
log::trace!("Metrics listening {metrics_bind}");
9999
spawn(serve_metrics(
100100
metrics_bind,
101101
metrics_cancel_handle,

src/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl PushMessage {
8989
ty
9090
} else {
9191
let mut str = ty;
92-
write!(&mut str, " {}", body).ok();
92+
write!(&mut str, " {body}").ok();
9393
str
9494
}
9595
}),

src/nc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Client {
3232
password: &str,
3333
forwarded_for: Vec<IpAddr>,
3434
) -> Result<UserId, AuthenticationError> {
35-
log::debug!("Verifying credentials for {}", username);
35+
log::debug!("Verifying credentials for {username}");
3636
let response = self.auth_request(username, password, forwarded_for).await?;
3737

3838
match response.status() {
@@ -65,7 +65,7 @@ impl Client {
6565
if !joined.is_empty() {
6666
write!(&mut joined, ", ").ok();
6767
}
68-
write!(&mut joined, "{}", ip).ok();
68+
write!(&mut joined, "{ip}").ok();
6969
joined
7070
},
7171
),

src/storage_mapping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl StorageMapping {
105105
&self,
106106
storage: u32,
107107
) -> Result<Vec<UserStorageAccess>, DatabaseError> {
108-
debug!("querying storage mapping for {}", storage);
108+
debug!("querying storage mapping for {storage}");
109109
let users = query_as::<Any, UserStorageAccess>(&format!(
110110
"\
111111
SELECT user_id, path \
@@ -120,7 +120,7 @@ impl StorageMapping {
120120
.map_err(DatabaseError::Query)?;
121121
METRICS.add_mapping_query();
122122

123-
debug!("got storage mappings for {}: {:?}", storage, users);
123+
debug!("got storage mappings for {storage}: {users:?}");
124124

125125
Ok(users)
126126
}

test_client/src/main.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() -> Result<()> {
2626
let (nc_url, username, password) = match (args.next(), args.next(), args.next()) {
2727
(Some(host), Some(username), Some(password)) => (host, username, password),
2828
_ => {
29-
eprintln!("usage {} <nextcloud url> <username> <password>", bin);
29+
eprintln!("usage {bin} <nextcloud url> <username> <password>");
3030
return Ok(());
3131
}
3232
};
@@ -36,7 +36,7 @@ fn main() -> Result<()> {
3636
} else {
3737
get_endpoint(&nc_url, &username, &password)?
3838
};
39-
info!("Found push server at {}", ws_url);
39+
info!("Found push server at {ws_url}");
4040

4141
let ws_url = Url::parse(&ws_url)
4242
.into_diagnostic()
@@ -61,30 +61,30 @@ fn main() -> Result<()> {
6161
loop {
6262
if let Message::Text(text) = socket.read().into_diagnostic()? {
6363
if let Some(err) = text.strip_prefix("err: ") {
64-
warn!("Received error: {}", err);
64+
warn!("Received error: {err}");
6565
return Ok(());
6666
} else if text.starts_with("notify_file") {
67-
info!("Received file update notification {}", text);
67+
info!("Received file update notification {text}");
6868
} else if text == "notify_activity" {
6969
info!("Received activity notification");
7070
} else if text == "notify_notification" {
7171
info!("Received notification notification");
7272
} else if text == "authenticated" {
7373
info!("Authenticated");
7474
} else {
75-
info!("Received: {}", text);
75+
info!("Received: {text}");
7676
}
7777
}
7878
}
7979
}
8080

8181
fn get_endpoint(nc_url: &str, user: &str, password: &str) -> Result<String> {
82-
let raw = ureq::get(&format!("{}/ocs/v2.php/cloud/capabilities", nc_url))
82+
let raw = ureq::get(&format!("{nc_url}/ocs/v2.php/cloud/capabilities"))
8383
.set(
8484
"Authorization",
8585
&format!(
8686
"Basic {}",
87-
base64::engine::general_purpose::STANDARD.encode(format!("{}:{}", user, password))
87+
base64::engine::general_purpose::STANDARD.encode(format!("{user}:{password}"))
8888
),
8989
)
9090
.set("Accept", "application/json")
@@ -93,10 +93,10 @@ fn get_endpoint(nc_url: &str, user: &str, password: &str) -> Result<String> {
9393
.into_diagnostic()?
9494
.into_string()
9595
.into_diagnostic()?;
96-
trace!("Capabilities response: {}", raw);
96+
trace!("Capabilities response: {raw}");
9797
let json: Value = serde_json::from_str(&raw)
9898
.into_diagnostic()
99-
.wrap_err_with(|| format!("Failed to decode json capabilities response: {}", raw))?;
99+
.wrap_err_with(|| format!("Failed to decode json capabilities response: {raw}"))?;
100100
if let Some(capabilities) = json["ocs"]["data"]["capabilities"].as_object() {
101101
debug!(
102102
"Supported capabilities: {:?}",
@@ -116,8 +116,7 @@ fn get_endpoint(nc_url: &str, user: &str, password: &str) -> Result<String> {
116116
}
117117
} else {
118118
Err(Report::msg(format!(
119-
"invalid capabilities response: {}",
120-
json
119+
"invalid capabilities response: {json}"
121120
)))
122121
}
123122
}

0 commit comments

Comments
 (0)