Fix: block call on async method
fix update method to use async reqwest for download new binary
This commit is contained in:
parent
974906804e
commit
e4f2cf2be3
10
src/main.rs
10
src/main.rs
@ -188,7 +188,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
loop {
|
loop {
|
||||||
if std::env::var("DAEMON_AUTO_UPGRADE") != Ok("OFF".to_string()) {
|
if std::env::var("DAEMON_AUTO_UPGRADE") != Ok("OFF".to_string()) {
|
||||||
// This upgrade procedure will get replaced in prod. We need this for the testnet.
|
// This upgrade procedure will get replaced in prod. We need this for the testnet.
|
||||||
if let Err(e) = download_and_replace_binary() {
|
if let Err(e) = download_and_replace_binary().await {
|
||||||
log::error!("Failed to upgrade detee-sgx-daemon to newer version: {e}");
|
log::error!("Failed to upgrade detee-sgx-daemon to newer version: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,17 +244,17 @@ fn set_logging() {
|
|||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_and_replace_binary() -> Result<()> {
|
async fn download_and_replace_binary() -> Result<()> {
|
||||||
use reqwest::blocking::get;
|
use reqwest::get;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
const TMP_DAEMON: &str = "/usr/local/bin/detee/new-daemon";
|
const TMP_DAEMON: &str = "/usr/local/bin/detee/new-daemon";
|
||||||
const BINARY: &str = "/usr/local/bin/detee-sgx-daemon";
|
const BINARY: &str = "/usr/local/bin/detee-sgx-daemon";
|
||||||
let response = get("https://registry.detee.ltd/sgx/daemon/detee-sgx-daemon")?;
|
let response = get("https://registry.detee.ltd/sgx/daemon/detee-sgx-daemon").await?;
|
||||||
if !response.status().is_success() {
|
if !response.status().is_success() {
|
||||||
return Err(anyhow!("Failed to download file: {}", response.status()));
|
return Err(anyhow!("Failed to download file: {}", response.status()));
|
||||||
}
|
}
|
||||||
let mut tmp_file = File::create(Path::new(&TMP_DAEMON))?;
|
let mut tmp_file = File::create(Path::new(&TMP_DAEMON))?;
|
||||||
std::io::copy(&mut response.bytes()?.as_ref(), &mut tmp_file)?;
|
std::io::copy(&mut response.bytes().await?.as_ref(), &mut tmp_file)?;
|
||||||
let new_hash = crate::global::compute_sha256(TMP_DAEMON)?;
|
let new_hash = crate::global::compute_sha256(TMP_DAEMON)?;
|
||||||
let old_hash = crate::global::compute_sha256(BINARY)?;
|
let old_hash = crate::global::compute_sha256(BINARY)?;
|
||||||
log::debug!("Old binary hash: {old_hash}. New binary hash: {new_hash}");
|
log::debug!("Old binary hash: {old_hash}. New binary hash: {new_hash}");
|
||||||
|
Loading…
Reference in New Issue
Block a user