From 6160c054bc42499c27dbd7b810088fe6e8163799 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 06:33:38 +0000 Subject: [PATCH 01/16] build(deps): bump serde_json from 1.0.108 to 1.0.109 (#239) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84fe857a..057d760e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3102,9 +3102,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" dependencies = [ "itoa", "ryu", From 3afd6d51846b68de6efdeacf5815a0ae5fb86c00 Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:30:55 +0800 Subject: [PATCH 02/16] build(deps): bump axum from 0.6 to 0.7 --- Cargo.lock | 149 +++++++++++++++++++++++++++-------- crates/metrics/Cargo.toml | 3 +- crates/metrics/src/error.rs | 7 +- crates/metrics/src/server.rs | 12 ++- 4 files changed, 132 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84fe857a..2a584df9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,14 +350,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", - "headers", "http 0.2.11", "http-body 0.4.6", - "hyper", + "hyper 0.14.27", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d" +dependencies = [ + "async-trait", + "axum-core 0.4.2", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.1.0", + "hyper-util", "itoa", "matchit", "memchr", @@ -374,6 +402,7 @@ dependencies = [ "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -393,6 +422,27 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.69" @@ -740,12 +790,13 @@ name = "clipcat-metrics" version = "0.16.0" dependencies = [ "async-trait", - "axum", + "axum 0.7.3", "bytes", "lazy_static", "mime", "prometheus", "snafu 0.8.0", + "tokio", "tower", "tower-http", ] @@ -1751,6 +1802,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "h2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.0.0", + "indexmap 2.1.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.2.1" @@ -1781,30 +1851,6 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -[[package]] -name = "headers" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" -dependencies = [ - "base64", - "bytes", - "headers-core", - "http 0.2.11", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http 0.2.11", -] - [[package]] name = "heck" version = "0.4.1" @@ -1944,7 +1990,7 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", + "h2 0.3.22", "http 0.2.11", "http-body 0.4.6", "httparse", @@ -1958,18 +2004,55 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.0", + "http 1.0.0", + "http-body 1.0.0", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "tokio", +] + [[package]] name = "hyper-timeout" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.27", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.0.0", + "http-body 1.0.0", + "hyper 1.1.0", + "pin-project-lite", + "socket2 0.5.5", + "tokio", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.58" @@ -3692,14 +3775,14 @@ checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.6.20", "base64", "bytes", "flate2", - "h2", + "h2 0.3.22", "http 0.2.11", "http-body 0.4.6", - "hyper", + "hyper 0.14.27", "hyper-timeout", "percent-encoding", "pin-project", diff --git a/crates/metrics/Cargo.toml b/crates/metrics/Cargo.toml index 420f29a7..108134cb 100644 --- a/crates/metrics/Cargo.toml +++ b/crates/metrics/Cargo.toml @@ -13,8 +13,9 @@ keywords.workspace = true [dependencies] async-trait = "0.1" +tokio = { version = "1", features = ["net"] } -axum = { version = "0.6", features = ["headers"] } +axum = "0.7" tower = { version = "0.4", features = ["timeout"] } tower-http = { version = "0.5", features = ["trace"] } diff --git a/crates/metrics/src/error.rs b/crates/metrics/src/error.rs index 840d326c..5acb5afb 100644 --- a/crates/metrics/src/error.rs +++ b/crates/metrics/src/error.rs @@ -5,9 +5,12 @@ pub type Result = std::result::Result; #[derive(Debug, Snafu)] #[snafu(visibility(pub))] pub enum Error { - #[snafu(display("Could not setup metrics, error: {source}",))] + #[snafu(display("Could not setup metrics, error: {source}"))] SetupMetrics { source: prometheus::Error, backtrace: Backtrace }, - #[snafu(display("Error occurs while serving metrics server, error: {message}",))] + #[snafu(display("Error occurs while binding metrics server, error: {source}"))] + BindMetricsServer { source: std::io::Error }, + + #[snafu(display("Error occurs while serving metrics server, error: {message}"))] ServeMetricsServer { message: String }, } diff --git a/crates/metrics/src/server.rs b/crates/metrics/src/server.rs index fa766824..5e58eab6 100644 --- a/crates/metrics/src/server.rs +++ b/crates/metrics/src/server.rs @@ -11,8 +11,13 @@ use bytes::{BufMut, BytesMut}; use lazy_static::lazy_static; use mime::Mime; use prometheus::{Encoder, TextEncoder}; +use snafu::ResultExt; +use tokio::net::TcpListener; -use crate::{error::Error, traits}; +use crate::{ + error::{self, Error}, + traits, +}; lazy_static! { static ref OPENMETRICS_TEXT: Mime = @@ -64,8 +69,9 @@ where .layer(middleware_stack) .into_make_service_with_connect_info::(); - axum::Server::bind(&listen_address) - .serve(router) + let listener = + TcpListener::bind(&listen_address).await.context(error::BindMetricsServerSnafu)?; + axum::serve(listener, router) .with_graceful_shutdown(shutdown_signal) .await .map_err(|err| Error::ServeMetricsServer { message: err.to_string() }) From c66f3dee617bfc8b266502387b87d9353b20e383 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:37:17 +0000 Subject: [PATCH 03/16] build(deps): bump serde from 1.0.193 to 1.0.194 (#240) --- Cargo.lock | 64 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 057d760e..ee080939 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -300,7 +300,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -317,7 +317,7 @@ checksum = "531b97fb4cd3dfdce92c35dedbfdc1f0b9d8091c8ca943d6dae340ef5012d514" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -595,7 +595,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -1111,7 +1111,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -1133,7 +1133,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -1315,7 +1315,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -1620,7 +1620,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2681,7 +2681,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2775,7 +2775,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2790,9 +2790,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" dependencies = [ "unicode-ident", ] @@ -2839,7 +2839,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.41", + "syn 2.0.46", "tempfile", "which", ] @@ -2854,7 +2854,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -2892,9 +2892,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -3082,22 +3082,22 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.194" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3129,7 +3129,7 @@ checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3179,7 +3179,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3351,7 +3351,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3414,9 +3414,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" dependencies = [ "proc-macro2", "quote", @@ -3495,7 +3495,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3611,7 +3611,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3722,7 +3722,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -3795,7 +3795,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", ] [[package]] @@ -4065,7 +4065,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", "wasm-bindgen-shared", ] @@ -4087,7 +4087,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.41", + "syn 2.0.46", "wasm-bindgen-backend", "wasm-bindgen-shared", ] From 3657f3fa56368aa2eb1e4882ff7604a38a8c7e4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:37:45 +0000 Subject: [PATCH 04/16] build(deps): bump async-trait from 0.1.76 to 0.1.77 (#241) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee080939..e92419ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,9 +311,9 @@ checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" [[package]] name = "async-trait" -version = "0.1.76" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531b97fb4cd3dfdce92c35dedbfdc1f0b9d8091c8ca943d6dae340ef5012d514" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", From e9a2b6b97f1a522eb45dc4c6632a43a78d22d503 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 09:38:08 +0000 Subject: [PATCH 05/16] build(deps): bump serde_json from 1.0.109 to 1.0.110 (#242) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e92419ac..f15b0beb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3102,9 +3102,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.109" +version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +checksum = "6fbd975230bada99c8bb618e0c365c2eefa219158d5c6c29610fd09ff1833257" dependencies = [ "itoa", "ryu", From 6478e6866e6b93d67e761a4893363aff2895d128 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:30:13 +0000 Subject: [PATCH 06/16] build(deps): bump semver from 1.0.20 to 1.0.21 (#245) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afe773b3..3ed72427 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3159,9 +3159,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" From b767b3021fcb9252b3ac6187b6aa4c899f95f4fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:30:45 +0000 Subject: [PATCH 07/16] build(deps): bump clap_complete from 4.4.5 to 4.4.6 (#244) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ed72427..c335a6d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -629,9 +629,9 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.4.5" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a51919c5608a32e34ea1d6be321ad070065e17613e168c5b6977024290f2630b" +checksum = "97aeaa95557bd02f23fbb662f981670c3d20c5a26e69f7354b28f57092437fcd" dependencies = [ "clap 4.4.12", ] From c389253f35806ebd1350720584611411683a3fe5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 06:25:04 +0000 Subject: [PATCH 08/16] build(deps): bump serde_json from 1.0.110 to 1.0.111 (#246) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c335a6d5..35cb6cf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3185,9 +3185,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.110" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fbd975230bada99c8bb618e0c365c2eefa219158d5c6c29610fd09ff1833257" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", From 45210e759074115560ef87e7614020b23ac64e56 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 06:25:10 +0000 Subject: [PATCH 09/16] build(deps): bump clap from 4.4.12 to 4.4.13 (#247) --- Cargo.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 35cb6cf1..750b8d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -607,9 +607,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.12" +version = "4.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" +checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" dependencies = [ "clap_builder", "clap_derive", @@ -633,7 +633,7 @@ version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97aeaa95557bd02f23fbb662f981670c3d20c5a26e69f7354b28f57092437fcd" dependencies = [ - "clap 4.4.12", + "clap 4.4.13", ] [[package]] @@ -766,7 +766,7 @@ dependencies = [ name = "clipcat-menu" version = "0.16.0" dependencies = [ - "clap 4.4.12", + "clap 4.4.13", "clap_complete", "clipcat-base", "clipcat-cli", @@ -805,7 +805,7 @@ dependencies = [ name = "clipcat-notify" version = "0.16.0" dependencies = [ - "clap 4.4.12", + "clap 4.4.13", "clap_complete", "clipcat-base", "clipcat-server", @@ -873,7 +873,7 @@ name = "clipcatctl" version = "0.16.0" dependencies = [ "bytes", - "clap 4.4.12", + "clap 4.4.13", "clap_complete", "clipcat-base", "clipcat-cli", @@ -898,7 +898,7 @@ dependencies = [ name = "clipcatd" version = "0.16.0" dependencies = [ - "clap 4.4.12", + "clap 4.4.13", "clap_complete", "clipcat-base", "clipcat-cli", From 3436dd17ce9ee757620a7e9bdcc0b03f81d6fbd7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 7 Jan 2024 08:02:41 +0000 Subject: [PATCH 10/16] build(deps): bump serde from 1.0.194 to 1.0.195 (#248) --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 750b8d86..b2986a69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3165,18 +3165,18 @@ checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", From e5777811c857f31758cf5c2dc5f9a5146e72d083 Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Mon, 8 Jan 2024 22:52:39 +0800 Subject: [PATCH 11/16] refactor(clipcatd): split `config` into modules --- Cargo.lock | 32 +- clipcatd/Cargo.toml | 1 + clipcatd/src/config.rs | 495 -------------------- clipcatd/src/config/dbus.rs | 22 + clipcatd/src/config/desktop_notification.rs | 79 ++++ clipcatd/src/config/error.rs | 13 + clipcatd/src/config/grpc.rs | 67 +++ clipcatd/src/config/metrics.rs | 45 ++ clipcatd/src/config/mod.rs | 185 ++++++++ clipcatd/src/config/snippet.rs | 20 + clipcatd/src/config/watcher.rs | 96 ++++ 11 files changed, 559 insertions(+), 496 deletions(-) delete mode 100644 clipcatd/src/config.rs create mode 100644 clipcatd/src/config/dbus.rs create mode 100644 clipcatd/src/config/desktop_notification.rs create mode 100644 clipcatd/src/config/error.rs create mode 100644 clipcatd/src/config/grpc.rs create mode 100644 clipcatd/src/config/metrics.rs create mode 100644 clipcatd/src/config/mod.rs create mode 100644 clipcatd/src/config/snippet.rs create mode 100644 clipcatd/src/config/watcher.rs diff --git a/Cargo.lock b/Cargo.lock index b2986a69..cbb49160 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -909,6 +909,7 @@ dependencies = [ "libc", "linicon", "mime", + "resolve-path", "serde", "shadow-rs", "simdutf8", @@ -1276,7 +1277,16 @@ version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys 0.3.7", ] [[package]] @@ -1289,6 +1299,17 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -3081,6 +3102,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "resolve-path" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "321e5e41b3b192dab6f1e75b9deacb6688b4b8c5e68906a78e8f43e7c2887bb5" +dependencies = [ + "dirs", +] + [[package]] name = "rust-ini" version = "0.17.0" diff --git a/clipcatd/Cargo.toml b/clipcatd/Cargo.toml index 835ceaf4..c1cc1d96 100644 --- a/clipcatd/Cargo.toml +++ b/clipcatd/Cargo.toml @@ -29,6 +29,7 @@ exitcode = "1" libc = "0.2" linicon = "2" mime = "0.3" +resolve-path = "0.1" shadow-rs = "0.26" simdutf8 = "0.1" snafu = "0.8" diff --git a/clipcatd/src/config.rs b/clipcatd/src/config.rs deleted file mode 100644 index 066bd4c3..00000000 --- a/clipcatd/src/config.rs +++ /dev/null @@ -1,495 +0,0 @@ -use std::{ - collections::HashSet, - net::{IpAddr, SocketAddr}, - path::{Path, PathBuf}, - time::Duration, -}; - -use directories::BaseDirs; -use serde::{Deserialize, Serialize}; -use snafu::{ResultExt, Snafu}; - -const DEFAULT_ICON_NAME: &str = "accessories-clipboard"; - -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct Config { - pub daemonize: bool, - - #[serde(default = "Config::default_pid_file_path")] - pub pid_file: PathBuf, - - #[serde(default = "Config::default_max_history")] - pub max_history: usize, - - #[serde(default = "Config::default_synchronize_selection_with_clipboard")] - pub synchronize_selection_with_clipboard: bool, - - #[serde(default = "Config::default_history_file_path")] - pub history_file_path: PathBuf, - - #[serde(default)] - pub log: clipcat_cli::config::LogConfig, - - #[serde(default, alias = "monitor")] - pub watcher: WatcherConfig, - - #[serde(default)] - pub grpc: GrpcConfig, - - #[serde(default)] - pub dbus: DBusConfig, - - #[serde(default)] - pub metrics: MetricsConfig, - - #[serde(default)] - pub desktop_notification: DesktopNotificationConfig, - - #[serde(default)] - pub snippets: Vec, -} - -// SAFETY: user may use bool to enable/disable the functions -#[allow(clippy::struct_excessive_bools)] -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct WatcherConfig { - #[serde(default)] - pub enable_clipboard: bool, - - #[serde(default)] - pub enable_primary: bool, - - #[serde(default = "WatcherConfig::default_enable_secondary")] - pub enable_secondary: bool, - - #[serde(default = "WatcherConfig::default_sensitive_x11_atoms")] - pub sensitive_x11_atoms: HashSet, - - #[serde(default = "WatcherConfig::default_filter_text_min_length")] - pub filter_text_min_length: usize, - - #[serde(default = "WatcherConfig::default_filter_text_max_length")] - pub filter_text_max_length: usize, - - #[serde(default)] - pub denied_text_regex_patterns: HashSet, - - #[serde(default)] - pub capture_image: bool, - - #[serde(default = "WatcherConfig::default_filter_image_max_size")] - pub filter_image_max_size: usize, -} - -impl From for clipcat_server::ClipboardWatcherOptions { - fn from( - WatcherConfig { - enable_clipboard, - enable_primary, - enable_secondary, - capture_image, - filter_text_min_length, - filter_text_max_length, - denied_text_regex_patterns, - filter_image_max_size, - sensitive_x11_atoms, - }: WatcherConfig, - ) -> Self { - Self { - enable_clipboard, - enable_primary, - enable_secondary, - capture_image, - filter_text_min_length, - filter_text_max_length, - filter_image_max_size, - denied_text_regex_patterns, - sensitive_x11_atoms, - } - } -} - -impl WatcherConfig { - pub const fn default_filter_text_min_length() -> usize { 1 } - - pub const fn default_filter_text_max_length() -> usize { 20_000_000 } - - pub const fn default_filter_image_max_size() -> usize { - // 5 MiB - 5 * (1 << 20) - } - - pub const fn default_enable_secondary() -> bool { false } - - pub fn default_sensitive_x11_atoms() -> HashSet { - HashSet::from(["x-kde-passwordManagerHint".to_string()]) - } -} - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct GrpcConfig { - #[serde(default = "GrpcConfig::default_enable_http")] - pub enable_http: bool, - - #[serde(default = "GrpcConfig::default_enable_local_socket")] - pub enable_local_socket: bool, - - #[serde(default = "GrpcConfig::default_host")] - pub host: IpAddr, - - #[serde(default = "GrpcConfig::default_port")] - pub port: u16, - - #[serde(default = "clipcat_base::config::default_unix_domain_socket")] - pub local_socket: PathBuf, - - #[serde(default = "GrpcConfig::default_access_token")] - pub access_token: Option, - - #[serde(default = "GrpcConfig::default_access_token_file_path")] - pub access_token_file_path: Option, -} - -impl GrpcConfig { - #[inline] - pub const fn socket_address(&self) -> SocketAddr { SocketAddr::new(self.host, self.port) } - - #[inline] - pub const fn default_enable_http() -> bool { true } - - #[inline] - pub const fn default_enable_local_socket() -> bool { true } - - #[inline] - pub const fn default_host() -> IpAddr { clipcat_base::DEFAULT_GRPC_HOST } - - #[inline] - pub const fn default_port() -> u16 { clipcat_base::DEFAULT_GRPC_PORT } - - #[inline] - pub const fn default_access_token() -> Option { None } - - #[inline] - pub const fn default_access_token_file_path() -> Option { None } -} - -impl Default for GrpcConfig { - fn default() -> Self { - Self { - enable_http: Self::default_enable_http(), - enable_local_socket: Self::default_enable_local_socket(), - host: Self::default_host(), - port: Self::default_port(), - local_socket: clipcat_base::config::default_unix_domain_socket(), - access_token: Self::default_access_token(), - access_token_file_path: Self::default_access_token_file_path(), - } - } -} - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct DBusConfig { - #[serde(default = "DBusConfig::default_enable")] - pub enable: bool, - - pub identifier: Option, -} - -impl DBusConfig { - #[inline] - pub const fn default_enable() -> bool { true } -} - -impl Default for DBusConfig { - fn default() -> Self { Self { enable: Self::default_enable(), identifier: None } } -} - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct MetricsConfig { - #[serde(default = "MetricsConfig::default_enable")] - pub enable: bool, - - #[serde(default = "MetricsConfig::default_host")] - pub host: IpAddr, - - #[serde(default = "MetricsConfig::default_port")] - pub port: u16, -} - -impl MetricsConfig { - #[inline] - pub const fn socket_address(&self) -> SocketAddr { SocketAddr::new(self.host, self.port) } - - #[inline] - pub const fn default_enable() -> bool { true } - - #[inline] - pub const fn default_host() -> IpAddr { clipcat_base::DEFAULT_METRICS_HOST } - - #[inline] - pub const fn default_port() -> u16 { clipcat_base::DEFAULT_METRICS_PORT } -} - -impl Default for MetricsConfig { - fn default() -> Self { - Self { - enable: Self::default_enable(), - host: Self::default_host(), - port: Self::default_port(), - } - } -} - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub enum SnippetConfig { - Text { name: String, content: String }, - File { name: String, path: PathBuf }, - Directory { name: String, path: PathBuf }, -} - -impl Default for Config { - fn default() -> Self { - Self { - daemonize: true, - pid_file: Self::default_pid_file_path(), - max_history: Self::default_max_history(), - history_file_path: Self::default_history_file_path(), - synchronize_selection_with_clipboard: - Self::default_synchronize_selection_with_clipboard(), - log: clipcat_cli::config::LogConfig::default(), - watcher: WatcherConfig::default(), - grpc: GrpcConfig::default(), - desktop_notification: DesktopNotificationConfig::default(), - dbus: DBusConfig::default(), - metrics: MetricsConfig::default(), - snippets: Vec::new(), - } - } -} - -impl Default for WatcherConfig { - fn default() -> Self { - Self { - enable_clipboard: true, - enable_primary: true, - enable_secondary: Self::default_enable_secondary(), - capture_image: true, - filter_text_min_length: Self::default_filter_text_min_length(), - filter_text_max_length: Self::default_filter_text_max_length(), - denied_text_regex_patterns: HashSet::new(), - filter_image_max_size: Self::default_filter_image_max_size(), - sensitive_x11_atoms: Self::default_sensitive_x11_atoms(), - } - } -} - -impl Config { - #[inline] - pub fn default_path() -> PathBuf { - [ - clipcat_base::PROJECT_CONFIG_DIR.to_path_buf(), - PathBuf::from(clipcat_base::DAEMON_CONFIG_NAME), - ] - .into_iter() - .collect() - } - - #[inline] - pub fn default_history_file_path() -> PathBuf { - let base_dirs = BaseDirs::new().expect("`BaseDirs::new` always success"); - [ - PathBuf::from(base_dirs.cache_dir()), - PathBuf::from(clipcat_base::PROJECT_NAME), - PathBuf::from(clipcat_base::DAEMON_HISTORY_FILE_NAME), - ] - .into_iter() - .collect() - } - - #[inline] - pub const fn default_synchronize_selection_with_clipboard() -> bool { true } - - #[inline] - pub const fn default_max_history() -> usize { 50 } - - #[inline] - pub fn default_pid_file_path() -> PathBuf { - let base_dirs = BaseDirs::new().expect("`BaseDirs::new` always success"); - [ - base_dirs.runtime_dir().map_or_else(std::env::temp_dir, PathBuf::from), - PathBuf::from(format!("{}.pid", clipcat_base::DAEMON_PROGRAM_NAME)), - ] - .into_iter() - .collect() - } - - #[inline] - pub fn load>(path: P) -> Result { - let mut config: Self = { - let data = std::fs::read_to_string(&path) - .context(OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?; - - toml::from_str(&data) - .context(ParseConfigSnafu { filename: path.as_ref().to_path_buf() })? - }; - - if config.max_history == 0 { - config.max_history = Self::default_max_history(); - } - - Ok(config) - } -} - -#[derive(Clone, Debug, Deserialize, Serialize)] -pub struct DesktopNotificationConfig { - #[serde(default = "DesktopNotificationConfig::default_enable")] - pub enable: bool, - - #[serde(default = "DesktopNotificationConfig::default_icon")] - pub icon: String, - - #[serde(default = "DesktopNotificationConfig::default_timeout_ms")] - pub timeout_ms: u64, - - #[serde(default = "DesktopNotificationConfig::default_long_plaintext_length")] - pub long_plaintext_length: usize, -} - -impl DesktopNotificationConfig { - pub const fn default_enable() -> bool { true } - - pub fn default_icon() -> String { String::from("accessories-clipboard") } - - pub const fn default_timeout_ms() -> u64 { 2000 } - - pub const fn default_long_plaintext_length() -> usize { 2000 } - - pub fn search_icon(&self) -> PathBuf { - let icon_path = PathBuf::from(&self.icon); - if icon_path.exists() { - return icon_path; - }; - - let clipboard_icons = { - let iter = linicon::lookup_icon(self.icon.as_str()).use_fallback_themes(true); - if let Some(theme) = linicon::get_system_theme() { - iter.from_theme(theme) - } else { - iter - } - } - .collect::, _>>(); - - let mut clipboard_icons = match clipboard_icons { - Ok(icons) => icons, - Err(err) => { - tracing::warn!("Could not find icon, error: {err}"); - return PathBuf::from(DEFAULT_ICON_NAME); - } - }; - - // sort by size - clipboard_icons.sort_unstable_by_key(|icon| icon.max_size); - clipboard_icons.pop().map_or_else(|| PathBuf::from(DEFAULT_ICON_NAME), |icon| icon.path) - } -} - -impl Default for DesktopNotificationConfig { - fn default() -> Self { - Self { - enable: Self::default_enable(), - icon: Self::default_icon(), - timeout_ms: Self::default_timeout_ms(), - long_plaintext_length: Self::default_long_plaintext_length(), - } - } -} - -impl From for clipcat_server::config::DesktopNotificationConfig { - fn from(config: DesktopNotificationConfig) -> Self { - let icon = config.search_icon(); - let DesktopNotificationConfig { enable, timeout_ms, long_plaintext_length, .. } = config; - - Self { enable, icon, timeout: Duration::from_millis(timeout_ms), long_plaintext_length } - } -} - -impl From for clipcat_server::config::DBusConfig { - fn from(DBusConfig { enable, identifier }: DBusConfig) -> Self { Self { enable, identifier } } -} - -impl From for clipcat_server::config::MetricsConfig { - fn from(config: MetricsConfig) -> Self { - Self { enable: config.enable, listen_address: config.socket_address() } - } -} - -impl From for clipcat_server::config::SnippetConfig { - fn from(config: SnippetConfig) -> Self { - match config { - SnippetConfig::Text { name, content } => Self::Inline { name, content }, - SnippetConfig::File { name, path } => Self::File { name, path }, - SnippetConfig::Directory { name, path } => Self::Directory { name, path }, - } - } -} - -impl From for clipcat_server::Config { - fn from( - Config { - grpc, - max_history, - synchronize_selection_with_clipboard, - history_file_path, - watcher, - desktop_notification, - dbus, - metrics, - snippets, - .. - }: Config, - ) -> Self { - let grpc_listen_address = grpc.enable_http.then_some(grpc.socket_address()); - let grpc_local_socket = grpc.enable_local_socket.then_some(grpc.local_socket); - let grpc_access_token = if let Some(file_path) = grpc.access_token_file_path { - if let Ok(token) = std::fs::read_to_string(file_path) { - Some(token.trim_end().to_string()) - } else { - grpc.access_token - } - } else { - grpc.access_token - }; - let watcher = clipcat_server::ClipboardWatcherOptions::from(watcher); - let desktop_notification = - clipcat_server::config::DesktopNotificationConfig::from(desktop_notification); - let dbus = clipcat_server::config::DBusConfig::from(dbus); - let metrics = clipcat_server::config::MetricsConfig::from(metrics); - let snippets = - snippets.into_iter().map(clipcat_server::config::SnippetConfig::from).collect(); - - Self { - grpc_listen_address, - grpc_local_socket, - grpc_access_token, - max_history, - synchronize_selection_with_clipboard, - history_file_path, - watcher, - dbus, - desktop_notification, - metrics, - snippets, - } - } -} - -#[derive(Debug, Snafu)] -pub enum Error { - #[snafu(display("Could not open config from {}: {source}", filename.display()))] - OpenConfig { filename: PathBuf, source: std::io::Error }, - - #[snafu(display("Count not parse config from {}: {source}", filename.display()))] - ParseConfig { filename: PathBuf, source: toml::de::Error }, -} diff --git a/clipcatd/src/config/dbus.rs b/clipcatd/src/config/dbus.rs new file mode 100644 index 00000000..790c74bb --- /dev/null +++ b/clipcatd/src/config/dbus.rs @@ -0,0 +1,22 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct DBusConfig { + #[serde(default = "DBusConfig::default_enable")] + pub enable: bool, + + pub identifier: Option, +} + +impl DBusConfig { + #[inline] + pub const fn default_enable() -> bool { true } +} + +impl Default for DBusConfig { + fn default() -> Self { Self { enable: Self::default_enable(), identifier: None } } +} + +impl From for clipcat_server::config::DBusConfig { + fn from(DBusConfig { enable, identifier }: DBusConfig) -> Self { Self { enable, identifier } } +} diff --git a/clipcatd/src/config/desktop_notification.rs b/clipcatd/src/config/desktop_notification.rs new file mode 100644 index 00000000..72eec856 --- /dev/null +++ b/clipcatd/src/config/desktop_notification.rs @@ -0,0 +1,79 @@ +use std::{path::PathBuf, time::Duration}; + +use serde::{Deserialize, Serialize}; + +const DEFAULT_ICON_NAME: &str = "accessories-clipboard"; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct DesktopNotificationConfig { + #[serde(default = "DesktopNotificationConfig::default_enable")] + pub enable: bool, + + #[serde(default = "DesktopNotificationConfig::default_icon")] + pub icon: String, + + #[serde(default = "DesktopNotificationConfig::default_timeout_ms")] + pub timeout_ms: u64, + + #[serde(default = "DesktopNotificationConfig::default_long_plaintext_length")] + pub long_plaintext_length: usize, +} + +impl DesktopNotificationConfig { + pub const fn default_enable() -> bool { true } + + pub fn default_icon() -> String { String::from("accessories-clipboard") } + + pub const fn default_timeout_ms() -> u64 { 2000 } + + pub const fn default_long_plaintext_length() -> usize { 2000 } + + pub fn search_icon(&self) -> PathBuf { + let icon_path = PathBuf::from(&self.icon); + if icon_path.exists() { + return icon_path; + }; + + let clipboard_icons = { + let iter = linicon::lookup_icon(self.icon.as_str()).use_fallback_themes(true); + if let Some(theme) = linicon::get_system_theme() { + iter.from_theme(theme) + } else { + iter + } + } + .collect::, _>>(); + + let mut clipboard_icons = match clipboard_icons { + Ok(icons) => icons, + Err(err) => { + tracing::warn!("Could not find icon, error: {err}"); + return PathBuf::from(DEFAULT_ICON_NAME); + } + }; + + // sort by size + clipboard_icons.sort_unstable_by_key(|icon| icon.max_size); + clipboard_icons.pop().map_or_else(|| PathBuf::from(DEFAULT_ICON_NAME), |icon| icon.path) + } +} + +impl Default for DesktopNotificationConfig { + fn default() -> Self { + Self { + enable: Self::default_enable(), + icon: Self::default_icon(), + timeout_ms: Self::default_timeout_ms(), + long_plaintext_length: Self::default_long_plaintext_length(), + } + } +} + +impl From for clipcat_server::config::DesktopNotificationConfig { + fn from(config: DesktopNotificationConfig) -> Self { + let icon = config.search_icon(); + let DesktopNotificationConfig { enable, timeout_ms, long_plaintext_length, .. } = config; + + Self { enable, icon, timeout: Duration::from_millis(timeout_ms), long_plaintext_length } + } +} diff --git a/clipcatd/src/config/error.rs b/clipcatd/src/config/error.rs new file mode 100644 index 00000000..90b6de63 --- /dev/null +++ b/clipcatd/src/config/error.rs @@ -0,0 +1,13 @@ +use std::path::PathBuf; + +use snafu::Snafu; + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub))] +pub enum Error { + #[snafu(display("Could not open config from {}: {source}", filename.display()))] + OpenConfig { filename: PathBuf, source: std::io::Error }, + + #[snafu(display("Count not parse config from {}: {source}", filename.display()))] + ParseConfig { filename: PathBuf, source: toml::de::Error }, +} diff --git a/clipcatd/src/config/grpc.rs b/clipcatd/src/config/grpc.rs new file mode 100644 index 00000000..d754a418 --- /dev/null +++ b/clipcatd/src/config/grpc.rs @@ -0,0 +1,67 @@ +use std::{ + net::{IpAddr, SocketAddr}, + path::PathBuf, +}; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct GrpcConfig { + #[serde(default = "GrpcConfig::default_enable_http")] + pub enable_http: bool, + + #[serde(default = "GrpcConfig::default_enable_local_socket")] + pub enable_local_socket: bool, + + #[serde(default = "GrpcConfig::default_host")] + pub host: IpAddr, + + #[serde(default = "GrpcConfig::default_port")] + pub port: u16, + + #[serde(default = "clipcat_base::config::default_unix_domain_socket")] + pub local_socket: PathBuf, + + #[serde(default = "GrpcConfig::default_access_token")] + pub access_token: Option, + + #[serde(default = "GrpcConfig::default_access_token_file_path")] + pub access_token_file_path: Option, +} + +impl GrpcConfig { + #[inline] + pub const fn socket_address(&self) -> SocketAddr { SocketAddr::new(self.host, self.port) } + + #[inline] + pub const fn default_enable_http() -> bool { true } + + #[inline] + pub const fn default_enable_local_socket() -> bool { true } + + #[inline] + pub const fn default_host() -> IpAddr { clipcat_base::DEFAULT_GRPC_HOST } + + #[inline] + pub const fn default_port() -> u16 { clipcat_base::DEFAULT_GRPC_PORT } + + #[inline] + pub const fn default_access_token() -> Option { None } + + #[inline] + pub const fn default_access_token_file_path() -> Option { None } +} + +impl Default for GrpcConfig { + fn default() -> Self { + Self { + enable_http: Self::default_enable_http(), + enable_local_socket: Self::default_enable_local_socket(), + host: Self::default_host(), + port: Self::default_port(), + local_socket: clipcat_base::config::default_unix_domain_socket(), + access_token: Self::default_access_token(), + access_token_file_path: Self::default_access_token_file_path(), + } + } +} diff --git a/clipcatd/src/config/metrics.rs b/clipcatd/src/config/metrics.rs new file mode 100644 index 00000000..df9fbecd --- /dev/null +++ b/clipcatd/src/config/metrics.rs @@ -0,0 +1,45 @@ +use std::net::{IpAddr, SocketAddr}; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct MetricsConfig { + #[serde(default = "MetricsConfig::default_enable")] + pub enable: bool, + + #[serde(default = "MetricsConfig::default_host")] + pub host: IpAddr, + + #[serde(default = "MetricsConfig::default_port")] + pub port: u16, +} + +impl MetricsConfig { + #[inline] + pub const fn socket_address(&self) -> SocketAddr { SocketAddr::new(self.host, self.port) } + + #[inline] + pub const fn default_enable() -> bool { true } + + #[inline] + pub const fn default_host() -> IpAddr { clipcat_base::DEFAULT_METRICS_HOST } + + #[inline] + pub const fn default_port() -> u16 { clipcat_base::DEFAULT_METRICS_PORT } +} + +impl Default for MetricsConfig { + fn default() -> Self { + Self { + enable: Self::default_enable(), + host: Self::default_host(), + port: Self::default_port(), + } + } +} + +impl From for clipcat_server::config::MetricsConfig { + fn from(config: MetricsConfig) -> Self { + Self { enable: config.enable, listen_address: config.socket_address() } + } +} diff --git a/clipcatd/src/config/mod.rs b/clipcatd/src/config/mod.rs new file mode 100644 index 00000000..69c9d449 --- /dev/null +++ b/clipcatd/src/config/mod.rs @@ -0,0 +1,185 @@ +mod dbus; +mod desktop_notification; +mod error; +mod grpc; +mod metrics; +mod snippet; +mod watcher; + +use std::path::{Path, PathBuf}; + +use directories::BaseDirs; +use serde::{Deserialize, Serialize}; +use snafu::ResultExt; + +pub use self::error::Error; +use self::{ + dbus::DBusConfig, desktop_notification::DesktopNotificationConfig, grpc::GrpcConfig, + metrics::MetricsConfig, snippet::SnippetConfig, watcher::WatcherConfig, +}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Config { + pub daemonize: bool, + + #[serde(default = "Config::default_pid_file_path")] + pub pid_file: PathBuf, + + #[serde(default = "Config::default_max_history")] + pub max_history: usize, + + #[serde(default = "Config::default_synchronize_selection_with_clipboard")] + pub synchronize_selection_with_clipboard: bool, + + #[serde(default = "Config::default_history_file_path")] + pub history_file_path: PathBuf, + + #[serde(default)] + pub log: clipcat_cli::config::LogConfig, + + #[serde(default, alias = "monitor")] + pub watcher: WatcherConfig, + + #[serde(default)] + pub grpc: GrpcConfig, + + #[serde(default)] + pub dbus: DBusConfig, + + #[serde(default)] + pub metrics: MetricsConfig, + + #[serde(default)] + pub desktop_notification: DesktopNotificationConfig, + + #[serde(default)] + pub snippets: Vec, +} + +impl Default for Config { + fn default() -> Self { + Self { + daemonize: true, + pid_file: Self::default_pid_file_path(), + max_history: Self::default_max_history(), + history_file_path: Self::default_history_file_path(), + synchronize_selection_with_clipboard: + Self::default_synchronize_selection_with_clipboard(), + log: clipcat_cli::config::LogConfig::default(), + watcher: WatcherConfig::default(), + grpc: GrpcConfig::default(), + desktop_notification: DesktopNotificationConfig::default(), + dbus: DBusConfig::default(), + metrics: MetricsConfig::default(), + snippets: Vec::new(), + } + } +} + +impl Config { + #[inline] + pub fn default_path() -> PathBuf { + [ + clipcat_base::PROJECT_CONFIG_DIR.to_path_buf(), + PathBuf::from(clipcat_base::DAEMON_CONFIG_NAME), + ] + .into_iter() + .collect() + } + + #[inline] + pub fn default_history_file_path() -> PathBuf { + let base_dirs = BaseDirs::new().expect("`BaseDirs::new` always success"); + [ + PathBuf::from(base_dirs.cache_dir()), + PathBuf::from(clipcat_base::PROJECT_NAME), + PathBuf::from(clipcat_base::DAEMON_HISTORY_FILE_NAME), + ] + .into_iter() + .collect() + } + + #[inline] + pub const fn default_synchronize_selection_with_clipboard() -> bool { true } + + #[inline] + pub const fn default_max_history() -> usize { 50 } + + #[inline] + pub fn default_pid_file_path() -> PathBuf { + let base_dirs = BaseDirs::new().expect("`BaseDirs::new` always success"); + [ + base_dirs.runtime_dir().map_or_else(std::env::temp_dir, PathBuf::from), + PathBuf::from(format!("{}.pid", clipcat_base::DAEMON_PROGRAM_NAME)), + ] + .into_iter() + .collect() + } + + #[inline] + pub fn load>(path: P) -> Result { + let mut config: Self = { + let data = std::fs::read_to_string(&path) + .context(error::OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?; + + toml::from_str(&data) + .context(error::ParseConfigSnafu { filename: path.as_ref().to_path_buf() })? + }; + + if config.max_history == 0 { + config.max_history = Self::default_max_history(); + } + + Ok(config) + } +} + +impl From for clipcat_server::Config { + fn from( + Config { + grpc, + max_history, + synchronize_selection_with_clipboard, + history_file_path, + watcher, + desktop_notification, + dbus, + metrics, + snippets, + .. + }: Config, + ) -> Self { + let grpc_listen_address = grpc.enable_http.then_some(grpc.socket_address()); + let grpc_local_socket = grpc.enable_local_socket.then_some(grpc.local_socket); + let grpc_access_token = if let Some(file_path) = grpc.access_token_file_path { + if let Ok(token) = std::fs::read_to_string(file_path) { + Some(token.trim_end().to_string()) + } else { + grpc.access_token + } + } else { + grpc.access_token + }; + let watcher = clipcat_server::ClipboardWatcherOptions::from(watcher); + let desktop_notification = + clipcat_server::config::DesktopNotificationConfig::from(desktop_notification); + let dbus = clipcat_server::config::DBusConfig::from(dbus); + let metrics = clipcat_server::config::MetricsConfig::from(metrics); + let snippets = + snippets.into_iter().map(clipcat_server::config::SnippetConfig::from).collect(); + + Self { + grpc_listen_address, + grpc_local_socket, + grpc_access_token, + max_history, + synchronize_selection_with_clipboard, + history_file_path, + watcher, + dbus, + desktop_notification, + metrics, + snippets, + } + } +} diff --git a/clipcatd/src/config/snippet.rs b/clipcatd/src/config/snippet.rs new file mode 100644 index 00000000..13ad8232 --- /dev/null +++ b/clipcatd/src/config/snippet.rs @@ -0,0 +1,20 @@ +use std::path::PathBuf; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub enum SnippetConfig { + Text { name: String, content: String }, + File { name: String, path: PathBuf }, + Directory { name: String, path: PathBuf }, +} + +impl From for clipcat_server::config::SnippetConfig { + fn from(config: SnippetConfig) -> Self { + match config { + SnippetConfig::Text { name, content } => Self::Inline { name, content }, + SnippetConfig::File { name, path } => Self::File { name, path }, + SnippetConfig::Directory { name, path } => Self::Directory { name, path }, + } + } +} diff --git a/clipcatd/src/config/watcher.rs b/clipcatd/src/config/watcher.rs new file mode 100644 index 00000000..7276116a --- /dev/null +++ b/clipcatd/src/config/watcher.rs @@ -0,0 +1,96 @@ +use std::collections::HashSet; + +use serde::{Deserialize, Serialize}; + +// SAFETY: user may use bool to enable/disable the functions +#[allow(clippy::struct_excessive_bools)] +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +pub struct WatcherConfig { + #[serde(default)] + pub enable_clipboard: bool, + + #[serde(default)] + pub enable_primary: bool, + + #[serde(default = "WatcherConfig::default_enable_secondary")] + pub enable_secondary: bool, + + #[serde(default = "WatcherConfig::default_sensitive_x11_atoms")] + pub sensitive_x11_atoms: HashSet, + + #[serde(default = "WatcherConfig::default_filter_text_min_length")] + pub filter_text_min_length: usize, + + #[serde(default = "WatcherConfig::default_filter_text_max_length")] + pub filter_text_max_length: usize, + + #[serde(default)] + pub denied_text_regex_patterns: HashSet, + + #[serde(default)] + pub capture_image: bool, + + #[serde(default = "WatcherConfig::default_filter_image_max_size")] + pub filter_image_max_size: usize, +} + +impl Default for WatcherConfig { + fn default() -> Self { + Self { + enable_clipboard: true, + enable_primary: true, + enable_secondary: Self::default_enable_secondary(), + capture_image: true, + filter_text_min_length: Self::default_filter_text_min_length(), + filter_text_max_length: Self::default_filter_text_max_length(), + denied_text_regex_patterns: HashSet::new(), + filter_image_max_size: Self::default_filter_image_max_size(), + sensitive_x11_atoms: Self::default_sensitive_x11_atoms(), + } + } +} + +impl From for clipcat_server::ClipboardWatcherOptions { + fn from( + WatcherConfig { + enable_clipboard, + enable_primary, + enable_secondary, + capture_image, + filter_text_min_length, + filter_text_max_length, + denied_text_regex_patterns, + filter_image_max_size, + sensitive_x11_atoms, + }: WatcherConfig, + ) -> Self { + Self { + enable_clipboard, + enable_primary, + enable_secondary, + capture_image, + filter_text_min_length, + filter_text_max_length, + filter_image_max_size, + denied_text_regex_patterns, + sensitive_x11_atoms, + } + } +} + +impl WatcherConfig { + pub const fn default_filter_text_min_length() -> usize { 1 } + + pub const fn default_filter_text_max_length() -> usize { 20_000_000 } + + pub const fn default_filter_image_max_size() -> usize { + // 5 MiB + 5 * (1 << 20) + } + + pub const fn default_enable_secondary() -> bool { false } + + pub fn default_sensitive_x11_atoms() -> HashSet { + HashSet::from(["x-kde-passwordManagerHint".to_string()]) + } +} From 4d4861b6a9ae2a1b0103d5d3bd84dfdfeab4a2df Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:18:53 +0800 Subject: [PATCH 12/16] feat(clipcatd): resolve file paths while loading configuration --- clipcatd/src/config/error.rs | 7 ++++-- clipcatd/src/config/mod.rs | 43 +++++++++++++++++++++++++++++++--- clipcatd/src/config/snippet.rs | 14 +++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/clipcatd/src/config/error.rs b/clipcatd/src/config/error.rs index 90b6de63..4045e5ba 100644 --- a/clipcatd/src/config/error.rs +++ b/clipcatd/src/config/error.rs @@ -5,9 +5,12 @@ use snafu::Snafu; #[derive(Debug, Snafu)] #[snafu(visibility(pub))] pub enum Error { - #[snafu(display("Could not open config from {}: {source}", filename.display()))] + #[snafu(display("Could not open config from {}, error: {source}", filename.display()))] OpenConfig { filename: PathBuf, source: std::io::Error }, - #[snafu(display("Count not parse config from {}: {source}", filename.display()))] + #[snafu(display("Count not parse config from {}, error: {source}", filename.display()))] ParseConfig { filename: PathBuf, source: toml::de::Error }, + + #[snafu(display("Could not resolve file path {}, error: {source}", file_path.display()))] + ResolveFilePath { file_path: PathBuf, source: std::io::Error }, } diff --git a/clipcatd/src/config/mod.rs b/clipcatd/src/config/mod.rs index 69c9d449..9a54f6f8 100644 --- a/clipcatd/src/config/mod.rs +++ b/clipcatd/src/config/mod.rs @@ -9,6 +9,7 @@ mod watcher; use std::path::{Path, PathBuf}; use directories::BaseDirs; +use resolve_path::PathResolveExt; use serde::{Deserialize, Serialize}; use snafu::ResultExt; @@ -126,9 +127,35 @@ impl Config { .context(error::ParseConfigSnafu { filename: path.as_ref().to_path_buf() })? }; - if config.max_history == 0 { - config.max_history = Self::default_max_history(); - } + config.log.file_path = match config.log.file_path.map(|path| { + path.try_resolve() + .map(|path| path.to_path_buf()) + .with_context(|_| error::ResolveFilePathSnafu { file_path: path.clone() }) + }) { + Some(Ok(path)) => Some(path), + Some(Err(err)) => return Err(err), + None => None, + }; + + config.max_history = + if config.max_history == 0 { Self::default_max_history() } else { config.max_history }; + + config.snippets = config + .snippets + .into_iter() + .filter_map(|snippet| { + snippet.try_resolve_path().map_err(|err| tracing::warn!("{err}")).ok() + }) + .collect(); + + config.grpc.access_token_file_path = + match config.grpc.access_token_file_path.map(resolve_path) { + Some(Ok(path)) => Some(path), + Some(Err(err)) => return Err(err), + None => None, + }; + + config.history_file_path = resolve_path(&config.history_file_path)?; Ok(config) } @@ -183,3 +210,13 @@ impl From for clipcat_server::Config { } } } + +fn resolve_path

(path: P) -> Result +where + P: AsRef, +{ + path.as_ref() + .try_resolve() + .map(|path| path.to_path_buf()) + .with_context(|_| error::ResolveFilePathSnafu { file_path: path.as_ref().to_path_buf() }) +} diff --git a/clipcatd/src/config/snippet.rs b/clipcatd/src/config/snippet.rs index 13ad8232..e922599c 100644 --- a/clipcatd/src/config/snippet.rs +++ b/clipcatd/src/config/snippet.rs @@ -2,6 +2,8 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; +use crate::config::{resolve_path, Error}; + #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub enum SnippetConfig { Text { name: String, content: String }, @@ -9,6 +11,18 @@ pub enum SnippetConfig { Directory { name: String, path: PathBuf }, } +impl SnippetConfig { + pub fn try_resolve_path(self) -> Result { + match self { + Self::Text { name, content } => Ok(Self::Text { name, content }), + Self::File { name, path } => Ok(Self::File { name, path: resolve_path(path)? }), + Self::Directory { name, path } => { + Ok(Self::Directory { name, path: resolve_path(path)? }) + } + } + } +} + impl From for clipcat_server::config::SnippetConfig { fn from(config: SnippetConfig) -> Self { match config { From 9f6c1480cce9f06f276a31372440af1b67b1d109 Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:38:28 +0800 Subject: [PATCH 13/16] feat(clipcat-menu): resolve file paths while loading configuration --- clipcat-menu/Cargo.toml | 1 + clipcat-menu/src/config.rs | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/clipcat-menu/Cargo.toml b/clipcat-menu/Cargo.toml index 292368e8..2074430c 100644 --- a/clipcat-menu/Cargo.toml +++ b/clipcat-menu/Cargo.toml @@ -25,6 +25,7 @@ tokio = { version = "1", features = ["rt-multi-thread", "sync"] } clap = { version = "4", features = ["derive", "env"] } clap_complete = "4" http = "1" +resolve-path = "0.1" shadow-rs = "0.26" skim = "0.10" snafu = "0.8" diff --git a/clipcat-menu/src/config.rs b/clipcat-menu/src/config.rs index 05f71301..e38dc24e 100644 --- a/clipcat-menu/src/config.rs +++ b/clipcat-menu/src/config.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; +use resolve_path::PathResolveExt; use serde::{Deserialize, Serialize}; use snafu::{ResultExt, Snafu}; @@ -43,13 +44,31 @@ impl Config { #[inline] pub fn load>(path: P) -> Result { - let data = std::fs::read_to_string(&path) - .context(OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?; - - let mut config: Self = toml::from_str(&data) - .context(ParseConfigSnafu { filename: path.as_ref().to_path_buf() })?; + let mut config: Self = { + let path = + path.as_ref().try_resolve().map(|path| path.to_path_buf()).with_context(|_| { + ResolveFilePathSnafu { file_path: path.as_ref().to_path_buf() } + })?; + let data = std::fs::read_to_string(&path) + .context(OpenConfigSnafu { filename: path.clone() })?; + toml::from_str(&data).context(ParseConfigSnafu { filename: path })? + }; + + config.log.file_path = match config.log.file_path.map(|path| { + path.try_resolve() + .map(|path| path.to_path_buf()) + .with_context(|_| ResolveFilePathSnafu { file_path: path.clone() }) + }) { + Some(Ok(path)) => Some(path), + Some(Err(err)) => return Err(err), + None => None, + }; if let Some(ref file_path) = config.access_token_file_path { + let file_path = file_path + .try_resolve() + .with_context(|_| ResolveFilePathSnafu { file_path: file_path.clone() })?; + if let Ok(token) = std::fs::read_to_string(file_path) { config.access_token = Some(token.trim_end().to_string()); } @@ -162,9 +181,12 @@ const fn default_line_length() -> usize { 100 } #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("Could not open config from {}: {source}", filename.display()))] + #[snafu(display("Could not open config from {}, error: {source}", filename.display()))] OpenConfig { filename: PathBuf, source: std::io::Error }, - #[snafu(display("Count not parse config from {}: {source}", filename.display()))] + #[snafu(display("Count not parse config from {}, error: {source}", filename.display()))] ParseConfig { filename: PathBuf, source: toml::de::Error }, + + #[snafu(display("Could not resolve file path {}, error: {source}", file_path.display()))] + ResolveFilePath { file_path: PathBuf, source: std::io::Error }, } From d31551d40f3168979af973769dfe140e98484f8f Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:38:42 +0800 Subject: [PATCH 14/16] feat(clipcatctl): resolve file paths while loading configuration --- Cargo.lock | 225 ++++++++++++++++++++------------------- clipcatctl/Cargo.toml | 1 + clipcatctl/src/config.rs | 34 ++++-- 3 files changed, 142 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbb49160..66747113 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arboard" @@ -144,7 +144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" dependencies = [ "concurrent-queue", - "event-listener 4.0.0", + "event-listener 4.0.3", "event-listener-strategy", "futures-core", "pin-project-lite", @@ -160,7 +160,7 @@ dependencies = [ "async-task", "concurrent-queue", "fastrand 2.0.1", - "futures-lite 2.1.0", + "futures-lite 2.2.0", "slab", ] @@ -206,7 +206,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "futures-io", - "futures-lite 2.1.0", + "futures-lite 2.2.0", "parking", "polling 3.3.1", "rustix 0.38.28", @@ -230,7 +230,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" dependencies = [ - "event-listener 4.0.0", + "event-listener 4.0.3", "event-listener-strategy", "pin-project-lite", ] @@ -260,7 +260,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -300,14 +300,14 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] name = "async-task" -version = "4.5.0" +version = "4.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" +checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" [[package]] name = "async-trait" @@ -317,7 +317,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -356,7 +356,7 @@ dependencies = [ "futures-util", "http 0.2.11", "http-body 0.4.6", - "hyper 0.14.27", + "hyper 0.14.28", "itoa", "matchit", "memchr", @@ -460,9 +460,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" [[package]] name = "beef" @@ -523,7 +523,7 @@ dependencies = [ "async-task", "fastrand 2.0.1", "futures-io", - "futures-lite 2.1.0", + "futures-lite 2.2.0", "piper", "tracing", ] @@ -645,7 +645,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -774,6 +774,7 @@ dependencies = [ "clipcat-external-editor", "http 1.0.0", "http-serde", + "resolve-path", "serde", "shadow-rs", "skim", @@ -883,6 +884,7 @@ dependencies = [ "http 1.0.0", "http-serde", "mime", + "resolve-path", "serde", "shadow-rs", "simdutf8", @@ -1011,9 +1013,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -1029,11 +1031,10 @@ dependencies = [ [[package]] name = "crossbeam" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2801af0d36612ae591caa9568261fddce32ce6e08a7275ea334a06a4ad021a2c" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" dependencies = [ - "cfg-if", "crossbeam-channel", "crossbeam-deque", "crossbeam-epoch", @@ -1043,55 +1044,46 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c3242926edf34aec4ac3a77108ad4854bffaa2e4ddc1824124ce59231302d5" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.16" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2fe95351b870527a5d09bf563ed3c97c0cffb87cf1c78a591bf48bb218d9aa" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", - "memoffset 0.9.0", ] [[package]] name = "crossbeam-queue" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9bcf5bdbfdd6030fb4a1c497b5d5fc5921aa2f60d359a17e249c0e6df3de153" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.17" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crunchy" @@ -1163,7 +1155,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -1185,7 +1177,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -1200,9 +1192,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", "serde", @@ -1387,7 +1379,7 @@ checksum = "f95e2801cd355d4a1a3e3953ce6ee5ae9603a5c833455343a8bfe3f44d418246" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -1448,9 +1440,9 @@ dependencies = [ [[package]] name = "event-listener" -version = "4.0.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" dependencies = [ "concurrent-queue", "parking", @@ -1463,7 +1455,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ - "event-listener 4.0.0", + "event-listener 4.0.3", "pin-project-lite", ] @@ -1506,9 +1498,9 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fdeflate" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868" +checksum = "209098dd6dfc4445aa6111f0e98653ac323eaa4dfd212c9ca3931bf9955c31bd" dependencies = [ "simd-adler32", ] @@ -1673,9 +1665,9 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeee267a1883f7ebef3700f262d2d54de95dfaf38189015a74fdc4e0c7ad8143" +checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" dependencies = [ "fastrand 2.0.1", "futures-core", @@ -1692,7 +1684,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -2003,9 +1995,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -2018,7 +2010,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -2050,7 +2042,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper 0.14.27", + "hyper 0.14.28", "pin-project-lite", "tokio", "tokio-io-timeout", @@ -2076,16 +2068,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2276,9 +2268,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libgit2-sys" @@ -2321,9 +2313,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "5f526fdd09d99e19742883e43de41e1aa9e36db0c7ab7f935165d611c5cccc66" dependencies = [ "cc", "libc", @@ -2412,9 +2404,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memmap2" @@ -2662,9 +2654,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ "memchr", ] @@ -2703,12 +2695,12 @@ dependencies = [ [[package]] name = "os_pipe" -version = "1.1.4" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177" +checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2785,7 +2777,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -2813,9 +2805,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" [[package]] name = "png" @@ -2874,12 +2866,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -2894,9 +2886,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.74" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -2943,7 +2935,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.46", + "syn 2.0.48", "tempfile", "which", ] @@ -2958,7 +2950,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3210,7 +3202,7 @@ checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3226,9 +3218,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" dependencies = [ "itoa", "serde", @@ -3236,20 +3228,20 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] name = "serde_spanned" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -3292,7 +3284,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3464,7 +3456,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3527,9 +3519,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.46" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -3554,15 +3546,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall", "rustix 0.38.28", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -3593,22 +3585,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3724,7 +3716,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3812,7 +3804,7 @@ dependencies = [ "h2 0.3.22", "http 0.2.11", "http-body 0.4.6", - "hyper 0.14.27", + "hyper 0.14.28", "hyper-timeout", "percent-encoding", "pin-project", @@ -3835,7 +3827,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -3908,7 +3900,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", ] [[package]] @@ -4019,9 +4011,9 @@ dependencies = [ [[package]] name = "tzdb_data" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63691b1ba8e003011b427b0a2c369e2795d8f179b7ad6df3e3d7692338ff4b3" +checksum = "629555d2921f3f0dc0de98699415a8b2b61dfcd3a0b082a327f7ed748bbb2b76" dependencies = [ "tz-rs", ] @@ -4178,7 +4170,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -4200,7 +4192,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4348,7 +4340,7 @@ version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" dependencies = [ - "windows-core", + "windows-core 0.51.1", "windows-targets 0.48.5", ] @@ -4361,6 +4353,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -4495,9 +4496,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.28" +version = "0.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" dependencies = [ "memchr", ] diff --git a/clipcatctl/Cargo.toml b/clipcatctl/Cargo.toml index 5916ee14..0a51bbbe 100644 --- a/clipcatctl/Cargo.toml +++ b/clipcatctl/Cargo.toml @@ -28,6 +28,7 @@ clap_complete = "4" directories = "5" http = "1" mime = "0.3" +resolve-path = "0.1" shadow-rs = "0.26" simdutf8 = "0.1" snafu = "0.8" diff --git a/clipcatctl/src/config.rs b/clipcatctl/src/config.rs index 7119a137..b44cb436 100644 --- a/clipcatctl/src/config.rs +++ b/clipcatctl/src/config.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; +use resolve_path::PathResolveExt; use serde::{Deserialize, Serialize}; use snafu::{ResultExt, Snafu}; @@ -40,13 +41,31 @@ impl Config { #[inline] pub fn load>(path: P) -> Result { - let data = std::fs::read_to_string(&path) - .context(OpenConfigSnafu { filename: path.as_ref().to_path_buf() })?; + let mut config: Self = { + let path = + path.as_ref().try_resolve().map(|path| path.to_path_buf()).with_context(|_| { + ResolveFilePathSnafu { file_path: path.as_ref().to_path_buf() } + })?; + let data = std::fs::read_to_string(&path) + .context(OpenConfigSnafu { filename: path.clone() })?; + toml::from_str(&data).context(ParseConfigSnafu { filename: path })? + }; - let mut config: Self = toml::from_str(&data) - .context(ParseConfigSnafu { filename: path.as_ref().to_path_buf() })?; + config.log.file_path = match config.log.file_path.map(|path| { + path.try_resolve() + .map(|path| path.to_path_buf()) + .with_context(|_| ResolveFilePathSnafu { file_path: path.clone() }) + }) { + Some(Ok(path)) => Some(path), + Some(Err(err)) => return Err(err), + None => None, + }; if let Some(ref file_path) = config.access_token_file_path { + let file_path = file_path + .try_resolve() + .with_context(|_| ResolveFilePathSnafu { file_path: file_path.clone() })?; + if let Ok(token) = std::fs::read_to_string(file_path) { config.access_token = Some(token.trim_end().to_string()); } @@ -63,9 +82,12 @@ impl Config { #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("Could not open config from {}: {source}", filename.display()))] + #[snafu(display("Could not open config from {}, error: {source}", filename.display()))] OpenConfig { filename: PathBuf, source: std::io::Error }, - #[snafu(display("Count not parse config from {}: {source}", filename.display()))] + #[snafu(display("Count not parse config from {}, error: {source}", filename.display()))] ParseConfig { filename: PathBuf, source: toml::de::Error }, + + #[snafu(display("Could not resolve file path {}, error: {source}", file_path.display()))] + ResolveFilePath { file_path: PathBuf, source: std::io::Error }, } From 0c57ce282bd2fec905344d37a6bd541a32248a47 Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:43:49 +0800 Subject: [PATCH 15/16] build: bump version to `0.16.1` --- Cargo.lock | 26 +++++++++++++------------- Cargo.toml | 2 +- flake.nix | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 66747113..181a3c2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -676,7 +676,7 @@ dependencies = [ [[package]] name = "clipcat-base" -version = "0.16.0" +version = "0.16.1" dependencies = [ "bytes", "directories", @@ -696,7 +696,7 @@ dependencies = [ [[package]] name = "clipcat-cli" -version = "0.16.0" +version = "0.16.1" dependencies = [ "serde", "serde_with", @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "clipcat-client" -version = "0.16.0" +version = "0.16.1" dependencies = [ "async-trait", "clipcat-base", @@ -725,7 +725,7 @@ dependencies = [ [[package]] name = "clipcat-clipboard" -version = "0.16.0" +version = "0.16.1" dependencies = [ "arboard", "bytes", @@ -744,7 +744,7 @@ dependencies = [ [[package]] name = "clipcat-dbus-variant" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clipcat-base", "mime", @@ -755,7 +755,7 @@ dependencies = [ [[package]] name = "clipcat-external-editor" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clipcat-base", "snafu 0.8.0", @@ -764,7 +764,7 @@ dependencies = [ [[package]] name = "clipcat-menu" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clap 4.4.13", "clap_complete", @@ -788,7 +788,7 @@ dependencies = [ [[package]] name = "clipcat-metrics" -version = "0.16.0" +version = "0.16.1" dependencies = [ "async-trait", "axum 0.7.3", @@ -804,7 +804,7 @@ dependencies = [ [[package]] name = "clipcat-notify" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clap 4.4.13", "clap_complete", @@ -821,7 +821,7 @@ dependencies = [ [[package]] name = "clipcat-proto" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clipcat-base", "mime", @@ -835,7 +835,7 @@ dependencies = [ [[package]] name = "clipcat-server" -version = "0.16.0" +version = "0.16.1" dependencies = [ "async-trait", "bincode", @@ -871,7 +871,7 @@ dependencies = [ [[package]] name = "clipcatctl" -version = "0.16.0" +version = "0.16.1" dependencies = [ "bytes", "clap 4.4.13", @@ -898,7 +898,7 @@ dependencies = [ [[package]] name = "clipcatd" -version = "0.16.0" +version = "0.16.1" dependencies = [ "clap 4.4.13", "clap_complete", diff --git a/Cargo.toml b/Cargo.toml index 7e948521..46411d4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.16.0" +version = "0.16.1" authors = ["xrelkd <46590321+xrelkd@users.noreply.github.com>"] homepage = "https://github.com/xrelkd/clipcat" repository = "https://github.com/xrelkd/clipcat" diff --git a/flake.nix b/flake.nix index 94f7654e..f3159875 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ outputs = { self, nixpkgs, flake-utils, fenix, crane }: let name = "clipcat"; - version = "0.16.0"; + version = "0.16.1"; in (flake-utils.lib.eachDefaultSystem (system: From b60b68ef10a91b065a6c83f02f29e0fefacb027d Mon Sep 17 00:00:00 2001 From: xrelkd <46590321+xrelkd@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:45:02 +0800 Subject: [PATCH 16/16] docs(readme): update `README.md` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37b4b20f..32244ca9 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ cd ~/bin # download and extract clipcat to ~/bin/ # NOTE: replace the version with the version you want to install -export CLIPCAT_VERSION=v0.16.0 +export CLIPCAT_VERSION=v0.16.1 # NOTE: the architecture of your machine, # available value is `x86_64-unknown-linux-musl`