Initialize the CometBFT binary
()
| 9 | |
| 10 | /// Initialize the CometBFT binary |
| 11 | pub fn init_comet_binary() -> Result<PathBuf> { |
| 12 | let file_name = if cfg!(windows) { |
| 13 | "cometbft.exe" |
| 14 | } else { |
| 15 | "cometbft" |
| 16 | }; |
| 17 | let binary_path = env::temp_dir().join(file_name); |
| 18 | |
| 19 | // Skip if already exists |
| 20 | if binary_path.exists() { |
| 21 | return Ok(binary_path); |
| 22 | } |
| 23 | |
| 24 | // Write the binary |
| 25 | fs::write(&binary_path, COMET_BIN).with_context(|| { |
| 26 | format!( |
| 27 | "failed to write CometBFT binary to {}", |
| 28 | binary_path.display() |
| 29 | ) |
| 30 | })?; |
| 31 | |
| 32 | // Make executable on Unix |
| 33 | #[cfg(unix)] |
| 34 | { |
| 35 | use std::os::unix::fs::PermissionsExt; |
| 36 | let mut perms = fs::metadata(&binary_path)?.permissions(); |
| 37 | perms.set_mode(0o755); |
| 38 | fs::set_permissions(&binary_path, perms)?; |
| 39 | } |
| 40 | |
| 41 | Ok(binary_path) |
| 42 | } |
no test coverage detected