Skip to content

Commit 05e1f9c

Browse files
authored
chore: drop fd-lock, narrow icp tokio features, and move update_check into dist (#708)
* chore: remove unused fd-lock dependency The `fd-lock` crate had zero source references anywhere in the workspace; drop it from `crates/icp` and the workspace dependency table. * refactor: move update_check out of operations into dist CLI self-update checking is not a library operation. Fold `operations/update_check.rs` into `dist.rs`, which already owns the `dist_supports_update_check`/`dist_check_for_updates` helpers it calls, and update the single call site in `main.rs`. * chore: narrow crates/icp tokio features from "full" `crates/icp` only needs sync, macros, rt, time, io-util, io-std, process and signal. The workspace `tokio` entry still supplies macros and rt-multi-thread, the latter required by the `tokio::task::block_in_place` call in `canister/sync/plugin.rs`. Dropping "full" stops pulling in net and fs, which nothing in the crate uses. * no-mistakes(document): document narrowed tokio feature rationale in icp manifest
1 parent f966961 commit 05e1f9c

7 files changed

Lines changed: 55 additions & 72 deletions

File tree

‎Cargo.lock‎

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ dunce = "1.0.5"
4444
ed25519-consensus = "2.1.0"
4545
crypto-bigint = { version = "0.5.5", features = ["zeroize"] }
4646
elliptic-curve = { version = "0.13.8", features = ["sec1", "std", "pkcs8"] }
47-
fd-lock = "4.0.4"
4847
flate2 = { version = "1.1.8", default-features = false, features = ["zlib-rs"] }
4948
futures = "0.3.31"
5049
glob = "0.3.2"

‎crates/icp-cli/src/dist.rs‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::sync::LazyLock;
2+
use std::time::{Duration, SystemTime};
23

34
use axoupdater::AxoUpdater;
5+
use icp::settings::UpdateCheck;
46
use reqwest::Client;
57
use tracing::debug;
68

@@ -175,3 +177,50 @@ fn newer_than_current(version_str: &str) -> bool {
175177
};
176178
latest > current
177179
}
180+
181+
const ONE_DAY: Duration = Duration::from_secs(24 * 60 * 60);
182+
183+
/// Check for CLI updates, returning the latest version string if one is available.
184+
pub(crate) async fn update_check(ctx: &icp::context::Context) -> Option<String> {
185+
let update_check_setting = match ctx.dirs.settings() {
186+
Ok(dirs) => {
187+
dirs.with_read(async |dirs| icp::settings::Settings::load_from(dirs).ok())
188+
.await
189+
.ok()
190+
.flatten()
191+
.unwrap_or_default()
192+
.update_check
193+
}
194+
Err(_) => UpdateCheck::Releases,
195+
};
196+
197+
let enabled =
198+
!matches!(update_check_setting, UpdateCheck::Disabled) && dist_supports_update_check();
199+
if !enabled {
200+
return None;
201+
}
202+
let beta = matches!(update_check_setting, UpdateCheck::Betas);
203+
let nag_path = ctx.dirs.cli_update_nag_timestamp();
204+
205+
// Throttle to at most once per day
206+
if let Ok(contents) = icp::fs::read_to_string(&nag_path)
207+
&& let Ok(ts) = contents.trim().parse::<u64>()
208+
{
209+
let then = SystemTime::UNIX_EPOCH + Duration::from_secs(ts);
210+
if then.elapsed().unwrap_or(Duration::ZERO) < ONE_DAY {
211+
debug!("Skipping CLI update check (last check < 24h ago)");
212+
return None;
213+
}
214+
}
215+
216+
// update the timestamp regardless of result
217+
let now = SystemTime::now()
218+
.duration_since(SystemTime::UNIX_EPOCH)
219+
.expect("since epoch")
220+
.as_secs();
221+
let _ = icp::fs::create_dir_all(nag_path.parent().unwrap());
222+
let _ = icp::fs::write(&nag_path, format!("{now}\n").as_bytes());
223+
224+
let client = reqwest::Client::new();
225+
dist_check_for_updates(&client, beta).await
226+
}

‎crates/icp-cli/src/main.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use tracing::{Instrument, debug, info, subscriber::set_global_default, trace_spa
88
use tracing_subscriber::{Registry, layer::SubscriberExt};
99

1010
use crate::{
11-
dist::dist_update_suggestion,
11+
dist::{dist_update_suggestion, update_check},
1212
logging::{UserLayer, debug_layer},
13-
operations::update_check::update_check,
1413
version::{git_sha, icp_cli_version_str},
1514
};
1615

‎crates/icp-cli/src/operations/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ pub(crate) mod sync;
1414
pub(crate) mod token;
1515

1616
pub(crate) mod misc;
17-
pub(crate) mod update_check;
1817
pub(crate) mod wasm;

‎crates/icp-cli/src/operations/update_check.rs‎

Lines changed: 0 additions & 53 deletions
This file was deleted.

‎crates/icp/Cargo.toml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ directories = { workspace = true }
2121
dunce = { workspace = true }
2222
ed25519-consensus = { workspace = true }
2323
elliptic-curve = { workspace = true }
24-
fd-lock = { workspace = true }
2524
flate2 = { workspace = true }
2625
futures = { workspace = true }
2726
glob = { workspace = true }
@@ -68,7 +67,11 @@ sysinfo = { workspace = true }
6867
tar = { workspace = true }
6968
time = { workspace = true }
7069
tiny-bip39 = { workspace = true }
71-
tokio = { workspace = true, features = ["full"] }
70+
# `io-std` is listed for `tokio::io::stdout`/`stderr`; feature unification with other
71+
# crates supplies it anyway, so dropping it would not fail the build. `rt-multi-thread`
72+
# is needed by `block_in_place` in `canister::sync::plugin` and arrives via the
73+
# workspace `tokio` entry.
74+
tokio = { workspace = true, features = ["sync", "macros", "rt", "time", "io-util", "io-std", "process", "signal"] }
7275
tracing = { workspace = true }
7376
url = { workspace = true }
7477
uuid = { workspace = true }

0 commit comments

Comments
 (0)