Skip to content
This repository was archived by the owner on Dec 15, 2025. It is now read-only.

Commit 4b33604

Browse files
committed
fix formatting
1 parent b07c40e commit 4b33604

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/app/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Client {
149149

150150
// Make a JSON-RPC request to the log method
151151
let response = self.jsonrpc_request("log", Some(params)).await?;
152-
152+
153153
// Write the log data to the output
154154
if let Some(logs) = response.as_array() {
155155
for log in logs {
@@ -161,7 +161,7 @@ impl Client {
161161
} else if let Some(log_str) = response.as_str() {
162162
out.write_all(log_str.as_bytes()).await?;
163163
}
164-
164+
165165
Ok(())
166166
}
167167

src/app/server.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ pub struct Status {
8787
pub struct Api {
8888
zinit: ZInit,
8989
socket: PathBuf,
90-
config_dir: PathBuf, // Configuration directory path
90+
config_dir: PathBuf, // Configuration directory path
9191
}
9292

9393
impl Api {
9494
pub fn new<P: AsRef<Path>>(zinit: ZInit, socket: P, _http_port: Option<u16>) -> Api {
9595
// _http_port parameter kept for backward compatibility but not used
9696
// Default to /etc/zinit if not specified
9797
let config_dir = PathBuf::from("/etc/zinit");
98-
98+
9999
Api {
100100
zinit,
101101
socket: socket.as_ref().to_path_buf(),
@@ -156,26 +156,29 @@ impl Api {
156156
} else {
157157
None
158158
};
159-
159+
160160
let snapshot = if let Some(params) = &request.params {
161-
params.get("snapshot").and_then(|v| v.as_bool()).unwrap_or(false)
161+
params
162+
.get("snapshot")
163+
.and_then(|v| v.as_bool())
164+
.unwrap_or(false)
162165
} else {
163166
false
164167
};
165-
168+
166169
let mut logs = zinit.logs(!snapshot).await;
167170
let mut log_data = Vec::new();
168-
171+
169172
// A simplified implementation that collects logs with tokio::time::timeout
170173
use tokio::time::{timeout, Duration};
171-
174+
172175
// For snapshot, wait only a short time; for continuous logs, wait longer
173176
let wait_duration = if snapshot {
174177
Duration::from_millis(500)
175178
} else {
176179
Duration::from_secs(5)
177180
};
178-
181+
179182
loop {
180183
match timeout(wait_duration, logs.recv()).await {
181184
Ok(Some(line)) => {
@@ -187,20 +190,20 @@ impl Api {
187190
} else {
188191
log_data.push(line.to_string());
189192
}
190-
193+
191194
if snapshot && !log_data.is_empty() {
192195
break; // For snapshot mode, get only the first logs
193196
}
194-
},
197+
}
195198
Ok(None) => break, // Stream ended
196199
Err(_) => break, // Timeout
197200
}
198201
}
199-
202+
200203
// Convert to a JSON value - handle potential error explicitly
201204
match serde_json::to_value(log_data) {
202205
Ok(value) => Ok(value),
203-
Err(e) => Err(anyhow::anyhow!("Failed to serialize logs: {}", e))
206+
Err(e) => Err(anyhow::anyhow!("Failed to serialize logs: {}", e)),
204207
}
205208
}
206209

@@ -472,8 +475,7 @@ impl Api {
472475
result: None,
473476
error: Some(JsonRpcError {
474477
code: INVALID_REQUEST,
475-
message: "Invalid JSON-RPC version, expected 2.0"
476-
.to_string(),
478+
message: "Invalid JSON-RPC version, expected 2.0".to_string(),
477479
data: None,
478480
}),
479481
}
@@ -553,8 +555,7 @@ impl Api {
553555
result: None,
554556
error: Some(JsonRpcError {
555557
code: INVALID_REQUEST,
556-
message: "Invalid JSON-RPC version, expected 2.0"
557-
.to_string(),
558+
message: "Invalid JSON-RPC version, expected 2.0".to_string(),
558559
data: None,
559560
}),
560561
}
@@ -639,7 +640,7 @@ impl Api {
639640
// when Zinit is started with the -c flag (default /etc/zinit)
640641
let (name, service) = config::load(format!("{}.yaml", name.as_ref()))
641642
.context("failed to load service config")?;
642-
643+
643644
zinit.monitor(name, service).await?;
644645
Ok(Value::Null)
645646
}

0 commit comments

Comments
 (0)