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 { | ||||
|         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.
 | ||||
|             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}"); | ||||
|             } | ||||
|         } | ||||
| @ -244,17 +244,17 @@ fn set_logging() { | ||||
|         .init(); | ||||
| } | ||||
| 
 | ||||
| fn download_and_replace_binary() -> Result<()> { | ||||
|     use reqwest::blocking::get; | ||||
| async fn download_and_replace_binary() -> Result<()> { | ||||
|     use reqwest::get; | ||||
|     use std::os::unix::fs::PermissionsExt; | ||||
|     const TMP_DAEMON: &str = "/usr/local/bin/detee/new-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() { | ||||
|         return Err(anyhow!("Failed to download file: {}", response.status())); | ||||
|     } | ||||
|     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 old_hash = crate::global::compute_sha256(BINARY)?; | ||||
|     log::debug!("Old binary hash: {old_hash}. New binary hash: {new_hash}"); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user