|
1 | | -use std::path::PathBuf; |
| 1 | +use nanvix::registry::Registry; |
2 | 2 |
|
3 | | -/// Get the default cache directory for nanvix registry |
4 | | -pub fn get_cache_directory() -> PathBuf { |
5 | | - let home_dir = std::env::var("HOME").unwrap_or_else(|_| ".".to_string()); |
6 | | - std::path::Path::new(&home_dir) |
7 | | - .join(".cache") |
8 | | - .join("nanvix-registry") |
9 | | -} |
| 3 | +/// Default machine type for hyperlight-nanvix |
| 4 | +const DEFAULT_MACHINE: &str = "hyperlight"; |
10 | 5 |
|
11 | | -/// Get the binary cache directory |
12 | | -pub fn get_binary_cache_directory() -> PathBuf { |
13 | | - get_cache_directory().join("bin") |
14 | | -} |
| 6 | +/// Default deployment type for hyperlight-nanvix |
| 7 | +const DEFAULT_DEPLOYMENT: &str = "single-process"; |
15 | 8 |
|
16 | 9 | /// Check if a binary exists in the cache and return its path if found |
17 | 10 | pub async fn get_cached_binary_path(binary_name: &str) -> Option<String> { |
18 | | - let cache_path = get_binary_cache_directory().join(binary_name); |
19 | | - |
20 | | - if tokio::fs::metadata(&cache_path).await.is_ok() { |
21 | | - Some(cache_path.to_string_lossy().to_string()) |
22 | | - } else { |
23 | | - None |
24 | | - } |
| 11 | + let registry = Registry::new(None); |
| 12 | + registry |
| 13 | + .get_cached_binary(DEFAULT_MACHINE, DEFAULT_DEPLOYMENT, binary_name) |
| 14 | + .await |
| 15 | + .ok() |
25 | 16 | } |
26 | 17 |
|
27 | 18 | /// Check if a binary exists in the cache (synchronous version for setup command) |
28 | 19 | pub fn is_binary_cached(binary_name: &str) -> bool { |
29 | | - let cache_path = get_binary_cache_directory().join(binary_name); |
30 | | - cache_path.exists() |
| 20 | + // Use blocking runtime to check cache synchronously |
| 21 | + let registry = Registry::new(None); |
| 22 | + let rt = tokio::runtime::Builder::new_current_thread() |
| 23 | + .enable_all() |
| 24 | + .build() |
| 25 | + .ok(); |
| 26 | + |
| 27 | + if let Some(rt) = rt { |
| 28 | + rt.block_on(async { |
| 29 | + registry |
| 30 | + .get_cached_binary(DEFAULT_MACHINE, DEFAULT_DEPLOYMENT, binary_name) |
| 31 | + .await |
| 32 | + .is_ok() |
| 33 | + }) |
| 34 | + } else { |
| 35 | + false |
| 36 | + } |
31 | 37 | } |
0 commit comments