formatting
This commit is contained in:
@@ -56,7 +56,10 @@ impl RegistryClient {
|
||||
|
||||
let http_client = reqwest::Client::builder()
|
||||
.timeout(timeout)
|
||||
.user_agent(format!("attune-registry-client/{}", env!("CARGO_PKG_VERSION")))
|
||||
.user_agent(format!(
|
||||
"attune-registry-client/{}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
))
|
||||
.build()
|
||||
.map_err(|e| Error::Internal(format!("Failed to create HTTP client: {}", e)))?;
|
||||
|
||||
@@ -69,7 +72,9 @@ impl RegistryClient {
|
||||
|
||||
/// Get all enabled registries sorted by priority (lower number = higher priority)
|
||||
pub fn get_registries(&self) -> Vec<RegistryIndexConfig> {
|
||||
let mut registries: Vec<_> = self.config.indices
|
||||
let mut registries: Vec<_> = self
|
||||
.config
|
||||
.indices
|
||||
.iter()
|
||||
.filter(|r| r.enabled)
|
||||
.cloned()
|
||||
@@ -156,7 +161,8 @@ impl RegistryClient {
|
||||
|
||||
/// Fetch index from file:// URL
|
||||
async fn fetch_index_from_file(&self, url: &str) -> Result<PackIndex> {
|
||||
let path = url.strip_prefix("file://")
|
||||
let path = url
|
||||
.strip_prefix("file://")
|
||||
.ok_or_else(|| Error::Configuration(format!("Invalid file URL: {}", url)))?;
|
||||
|
||||
let path = PathBuf::from(path);
|
||||
@@ -209,11 +215,7 @@ impl RegistryClient {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
"Failed to fetch registry {}: {}",
|
||||
registry.url,
|
||||
e
|
||||
);
|
||||
tracing::warn!("Failed to fetch registry {}: {}", registry.url, e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -236,7 +238,10 @@ impl RegistryClient {
|
||||
let matches = pack.pack_ref.to_lowercase().contains(&keyword_lower)
|
||||
|| pack.label.to_lowercase().contains(&keyword_lower)
|
||||
|| pack.description.to_lowercase().contains(&keyword_lower)
|
||||
|| pack.keywords.iter().any(|k| k.to_lowercase().contains(&keyword_lower));
|
||||
|| pack
|
||||
.keywords
|
||||
.iter()
|
||||
.any(|k| k.to_lowercase().contains(&keyword_lower));
|
||||
|
||||
if matches {
|
||||
results.push((pack, registry.url.clone()));
|
||||
@@ -244,11 +249,7 @@ impl RegistryClient {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
"Failed to fetch registry {}: {}",
|
||||
registry.url,
|
||||
e
|
||||
);
|
||||
tracing::warn!("Failed to fetch registry {}: {}", registry.url, e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +265,9 @@ impl RegistryClient {
|
||||
registry_name: &str,
|
||||
) -> Result<Option<PackIndexEntry>> {
|
||||
// Find registry by name
|
||||
let registry = self.config.indices
|
||||
let registry = self
|
||||
.config
|
||||
.indices
|
||||
.iter()
|
||||
.find(|r| r.name.as_deref() == Some(registry_name))
|
||||
.ok_or_else(|| Error::not_found("registry", "name", registry_name))?;
|
||||
|
||||
@@ -23,15 +23,9 @@ pub type ProgressCallback = Arc<dyn Fn(ProgressEvent) + Send + Sync>;
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ProgressEvent {
|
||||
/// Started a new step
|
||||
StepStarted {
|
||||
step: String,
|
||||
message: String,
|
||||
},
|
||||
StepStarted { step: String, message: String },
|
||||
/// Step completed
|
||||
StepCompleted {
|
||||
step: String,
|
||||
message: String,
|
||||
},
|
||||
StepCompleted { step: String, message: String },
|
||||
/// Download progress
|
||||
Downloading {
|
||||
url: String,
|
||||
@@ -39,21 +33,13 @@ pub enum ProgressEvent {
|
||||
total_bytes: Option<u64>,
|
||||
},
|
||||
/// Extraction progress
|
||||
Extracting {
|
||||
file: String,
|
||||
},
|
||||
Extracting { file: String },
|
||||
/// Verification progress
|
||||
Verifying {
|
||||
message: String,
|
||||
},
|
||||
Verifying { message: String },
|
||||
/// Warning message
|
||||
Warning {
|
||||
message: String,
|
||||
},
|
||||
Warning { message: String },
|
||||
/// Info message
|
||||
Info {
|
||||
message: String,
|
||||
},
|
||||
Info { message: String },
|
||||
}
|
||||
|
||||
/// Pack installer for handling various installation sources
|
||||
@@ -151,12 +137,15 @@ impl PackInstaller {
|
||||
/// Install a pack from the given source
|
||||
pub async fn install(&self, source: PackSource) -> Result<InstalledPack> {
|
||||
match source {
|
||||
PackSource::Git { url, git_ref } => self.install_from_git(&url, git_ref.as_deref()).await,
|
||||
PackSource::Git { url, git_ref } => {
|
||||
self.install_from_git(&url, git_ref.as_deref()).await
|
||||
}
|
||||
PackSource::Archive { url } => self.install_from_archive_url(&url, None).await,
|
||||
PackSource::LocalDirectory { path } => self.install_from_local_directory(&path).await,
|
||||
PackSource::LocalArchive { path } => self.install_from_local_archive(&path).await,
|
||||
PackSource::Registry { pack_ref, version } => {
|
||||
self.install_from_registry(&pack_ref, version.as_deref()).await
|
||||
self.install_from_registry(&pack_ref, version.as_deref())
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,7 +256,11 @@ impl PackInstaller {
|
||||
|
||||
// Verify source exists and is a directory
|
||||
if !source_path.exists() {
|
||||
return Err(Error::not_found("directory", "path", source_path.display().to_string()));
|
||||
return Err(Error::not_found(
|
||||
"directory",
|
||||
"path",
|
||||
source_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !source_path.is_dir() {
|
||||
@@ -301,7 +294,11 @@ impl PackInstaller {
|
||||
|
||||
// Verify file exists
|
||||
if !archive_path.exists() {
|
||||
return Err(Error::not_found("file", "path", archive_path.display().to_string()));
|
||||
return Err(Error::not_found(
|
||||
"file",
|
||||
"path",
|
||||
archive_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
if !archive_path.is_file() {
|
||||
@@ -369,9 +366,7 @@ impl PackInstaller {
|
||||
git_ref,
|
||||
checksum,
|
||||
} => {
|
||||
let mut installed = self
|
||||
.install_from_git(&url, git_ref.as_deref())
|
||||
.await?;
|
||||
let mut installed = self.install_from_git(&url, git_ref.as_deref()).await?;
|
||||
installed.checksum = Some(checksum);
|
||||
Ok(installed)
|
||||
}
|
||||
@@ -426,11 +421,7 @@ impl PackInstaller {
|
||||
}
|
||||
|
||||
// Determine filename from URL
|
||||
let filename = url
|
||||
.split('/')
|
||||
.last()
|
||||
.unwrap_or("archive.zip")
|
||||
.to_string();
|
||||
let filename = url.split('/').last().unwrap_or("archive.zip").to_string();
|
||||
|
||||
let archive_path = self.temp_dir.join(&filename);
|
||||
|
||||
@@ -483,7 +474,10 @@ impl PackInstaller {
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(Error::internal(format!("Failed to extract zip: {}", stderr)));
|
||||
return Err(Error::internal(format!(
|
||||
"Failed to extract zip: {}",
|
||||
stderr
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -502,22 +496,23 @@ impl PackInstaller {
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(Error::internal(format!("Failed to extract tar.gz: {}", stderr)));
|
||||
return Err(Error::internal(format!(
|
||||
"Failed to extract tar.gz: {}",
|
||||
stderr
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Verify archive checksum
|
||||
async fn verify_archive_checksum(
|
||||
&self,
|
||||
archive_path: &Path,
|
||||
checksum_str: &str,
|
||||
) -> Result<()> {
|
||||
async fn verify_archive_checksum(&self, archive_path: &Path, checksum_str: &str) -> Result<()> {
|
||||
let checksum = Checksum::parse(checksum_str)
|
||||
.map_err(|e| Error::validation(format!("Invalid checksum: {}", e)))?;
|
||||
|
||||
let computed = self.compute_checksum(archive_path, &checksum.algorithm).await?;
|
||||
let computed = self
|
||||
.compute_checksum(archive_path, &checksum.algorithm)
|
||||
.await?;
|
||||
|
||||
if computed != checksum.hash {
|
||||
return Err(Error::validation(format!(
|
||||
@@ -553,7 +548,10 @@ impl PackInstaller {
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(Error::internal(format!("Checksum computation failed: {}", stderr)));
|
||||
return Err(Error::internal(format!(
|
||||
"Checksum computation failed: {}",
|
||||
stderr
|
||||
)));
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
@@ -611,9 +609,9 @@ impl PackInstaller {
|
||||
use tokio::fs;
|
||||
|
||||
// Create destination directory if it doesn't exist
|
||||
fs::create_dir_all(dst)
|
||||
.await
|
||||
.map_err(|e| Error::internal(format!("Failed to create destination directory: {}", e)))?;
|
||||
fs::create_dir_all(dst).await.map_err(|e| {
|
||||
Error::internal(format!("Failed to create destination directory: {}", e))
|
||||
})?;
|
||||
|
||||
// Read source directory
|
||||
let mut entries = fs::read_dir(src)
|
||||
|
||||
@@ -145,7 +145,8 @@ impl PackStorage {
|
||||
})?;
|
||||
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|e| Error::io(format!("Failed to read directory entry: {}", e)))?;
|
||||
let entry =
|
||||
entry.map_err(|e| Error::io(format!("Failed to read directory entry: {}", e)))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
@@ -209,13 +210,21 @@ pub fn calculate_directory_checksum<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||
|
||||
// Hash file contents
|
||||
let mut file = fs::File::open(&file_path).map_err(|e| {
|
||||
Error::io(format!("Failed to open file {}: {}", file_path.display(), e))
|
||||
Error::io(format!(
|
||||
"Failed to open file {}: {}",
|
||||
file_path.display(),
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
let mut buffer = [0u8; 8192];
|
||||
loop {
|
||||
let n = file.read(&mut buffer).map_err(|e| {
|
||||
Error::io(format!("Failed to read file {}: {}", file_path.display(), e))
|
||||
Error::io(format!(
|
||||
"Failed to read file {}: {}",
|
||||
file_path.display(),
|
||||
e
|
||||
))
|
||||
})?;
|
||||
if n == 0 {
|
||||
break;
|
||||
@@ -255,15 +264,14 @@ pub fn calculate_file_checksum<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||
}
|
||||
|
||||
let mut hasher = Sha256::new();
|
||||
let mut file = fs::File::open(path).map_err(|e| {
|
||||
Error::io(format!("Failed to open file {}: {}", path.display(), e))
|
||||
})?;
|
||||
let mut file = fs::File::open(path)
|
||||
.map_err(|e| Error::io(format!("Failed to open file {}: {}", path.display(), e)))?;
|
||||
|
||||
let mut buffer = [0u8; 8192];
|
||||
loop {
|
||||
let n = file.read(&mut buffer).map_err(|e| {
|
||||
Error::io(format!("Failed to read file {}: {}", path.display(), e))
|
||||
})?;
|
||||
let n = file
|
||||
.read(&mut buffer)
|
||||
.map_err(|e| Error::io(format!("Failed to read file {}: {}", path.display(), e)))?;
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
@@ -291,7 +299,8 @@ fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
|
||||
e
|
||||
))
|
||||
})? {
|
||||
let entry = entry.map_err(|e| Error::io(format!("Failed to read directory entry: {}", e)))?;
|
||||
let entry =
|
||||
entry.map_err(|e| Error::io(format!("Failed to read directory entry: {}", e)))?;
|
||||
let path = entry.path();
|
||||
let file_name = entry.file_name();
|
||||
let dest_path = dst.join(&file_name);
|
||||
|
||||
Reference in New Issue
Block a user