Skip to content

Commit 8641799

Browse files
author
Roy Lin
committed
style(box): cargo fmt + fix clippy::single-match in restore readiness
The v2.1.0 snapshot-fork work landed on a feature branch; box ci.yml (fmt + clippy -D warnings) only runs on PRs to main, so these surfaced on PR #28: - cargo fmt across pool/prune/mod/ready - ready.rs probe_exec_ready_once: single-arm match -> if let (clippy::single-match) No functional change; release binaries unaffected.
1 parent bea0f9d commit 8641799

4 files changed

Lines changed: 36 additions & 17 deletions

File tree

src/cli/src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) mod network;
3434
mod pause;
3535
mod pool;
3636
mod port;
37+
mod prune;
3738
mod ps;
3839
mod pull;
3940
mod push;
@@ -45,7 +46,6 @@ mod run;
4546
mod save;
4647
mod seal;
4748
mod shell;
48-
mod prune;
4949
mod snapshot;
5050
mod start;
5151
mod stats;

src/cli/src/commands/prune.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,24 @@ mod tests {
6060

6161
#[test]
6262
fn test_is_prunable_box_only_inactive() {
63-
assert!(!is_prunable_box(&make_record("a", "running", "running", Some(1))));
64-
assert!(!is_prunable_box(&make_record("b", "paused", "paused", Some(1))));
65-
assert!(is_prunable_box(&make_record("c", "stopped", "stopped", None)));
63+
assert!(!is_prunable_box(&make_record(
64+
"a",
65+
"running",
66+
"running",
67+
Some(1)
68+
)));
69+
assert!(!is_prunable_box(&make_record(
70+
"b",
71+
"paused",
72+
"paused",
73+
Some(1)
74+
)));
75+
assert!(is_prunable_box(&make_record(
76+
"c", "stopped", "stopped", None
77+
)));
6678
assert!(is_prunable_box(&make_record("d", "dead", "dead", None)));
67-
assert!(is_prunable_box(&make_record("e", "created", "created", None)));
79+
assert!(is_prunable_box(&make_record(
80+
"e", "created", "created", None
81+
)));
6882
}
6983
}

src/runtime/src/pool/warm_pool.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,10 @@ impl WarmPool {
462462
return Ok(t.clone());
463463
}
464464

465-
let dir = a3s_box_core::dirs_home()
466-
.join("pool")
467-
.join(format!("tpl-{:016x}", crate::vm::fnv1a_hash(&box_config.image)));
465+
let dir = a3s_box_core::dirs_home().join("pool").join(format!(
466+
"tpl-{:016x}",
467+
crate::vm::fnv1a_hash(&box_config.image)
468+
));
468469
std::fs::create_dir_all(&dir).map_err(BoxError::IoError)?;
469470
let mem_file = dir.join("template.ram");
470471
let sock = dir.join("template.sock");
@@ -542,7 +543,10 @@ impl WarmPool {
542543
/// state save/restore, neither of which exist on Windows. `--snapshot-fork` is
543544
/// Linux/KVM-only, so this path is never reached there in practice.
544545
#[cfg(not(unix))]
545-
async fn trigger_snapshot(_sock: &std::path::Path, _state_file: &std::path::Path) -> Result<()> {
546+
async fn trigger_snapshot(
547+
_sock: &std::path::Path,
548+
_state_file: &std::path::Path,
549+
) -> Result<()> {
546550
Err(BoxError::PoolError(
547551
"snapshot-fork is only supported on Linux/KVM hosts".to_string(),
548552
))

src/runtime/src/vm/ready.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ impl VmManager {
2222
// (no cold boot), so a short grace catches an immediate restore failure while
2323
// saving ~200ms on the fork fast-path; a cold boot keeps the longer grace.
2424
#[cfg(unix)]
25-
let max_wait_ms: u64 = if super::is_restore_mode(&self.config) { 40 } else { 250 };
25+
let max_wait_ms: u64 = if super::is_restore_mode(&self.config) {
26+
40
27+
} else {
28+
250
29+
};
2630
#[cfg(not(unix))]
2731
let max_wait_ms: u64 = 250;
2832
const POLL_MS: u64 = 10;
@@ -142,13 +146,10 @@ impl VmManager {
142146
if let Ok(Ok(client)) =
143147
tokio::time::timeout(ATTEMPT_TIMEOUT, ExecClient::connect(exec_socket_path)).await
144148
{
145-
match tokio::time::timeout(ATTEMPT_TIMEOUT, client.heartbeat()).await {
146-
Ok(Ok(true)) => {
147-
tracing::debug!("restore: exec server heartbeat passed");
148-
self.exec_client = Some(client);
149-
return;
150-
}
151-
_ => {}
149+
if let Ok(Ok(true)) = tokio::time::timeout(ATTEMPT_TIMEOUT, client.heartbeat()).await {
150+
tracing::debug!("restore: exec server heartbeat passed");
151+
self.exec_client = Some(client);
152+
return;
152153
}
153154
}
154155
tracing::debug!(

0 commit comments

Comments
 (0)