summaryrefslogtreecommitdiff
path: root/src/pkgtoolkit/git_source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkgtoolkit/git_source.rs')
-rw-r--r--src/pkgtoolkit/git_source.rs47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/pkgtoolkit/git_source.rs b/src/pkgtoolkit/git_source.rs
index 2f33c14..0bedf0a 100644
--- a/src/pkgtoolkit/git_source.rs
+++ b/src/pkgtoolkit/git_source.rs
@@ -1,8 +1,8 @@
+use crate::cfg::config::Config;
+use crate::pkgtoolkit::types::Package;
+use git2::Repository;
use std::fs;
use std::path::Path;
-use git2::Repository;
-use crate::pkgtoolkit::types::Package;
-use crate::cfg::config::Config;
use toml;
pub struct GitSource;
@@ -15,8 +15,13 @@ impl GitSource {
}
/// Get source code for a package from its git repository
- pub fn get_package_source(package: &Package, config: &Config) -> Result<String, Box<dyn std::error::Error>> {
- let git_repo = package.git_repo.as_ref()
+ pub fn get_package_source(
+ package: &Package,
+ config: &Config,
+ ) -> Result<String, Box<dyn std::error::Error>> {
+ let git_repo = package
+ .git_repo
+ .as_ref()
.ok_or("Package does not have a git repository specified")?;
let source_dir = Path::new(&config.paths.cache_dir)
@@ -31,53 +36,57 @@ impl GitSource {
let source_path = source_dir.to_string_lossy().to_string();
println!("Source code downloaded to: {}", source_path);
-
+
Ok(source_path)
}
/// Get source code for a package by name, first checking INSTALL file, then falling back to index
- pub fn get_source_by_name(pkg_name: &str, config: &Config) -> Result<String, Box<dyn std::error::Error>> {
- // First try to get git_repo from INSTALL file in cache
+ pub fn get_source_by_name(
+ pkg_name: &str,
+ config: &Config,
+ ) -> Result<String, Box<dyn std::error::Error>> {
let install_path = Path::new(&config.paths.cache_dir).join(format!("{}/INSTALL", pkg_name));
-
+
if install_path.exists() {
let install_content = fs::read_to_string(&install_path)?;
let install_data: crate::pkgtoolkit::types::Install = toml::from_str(&install_content)
.map_err(|e| format!("Failed to parse INSTALL file: {}", e))?;
-
+
// Check if InstallMeta has git_repo
if let Some(git_repo) = install_data.install.git_repo {
println!("Found git repository in INSTALL file: {}", git_repo);
-
+
let source_dir = Path::new(&config.paths.cache_dir)
.join("sources")
.join(&install_data.package.name)
.join(&install_data.package.version);
fs::create_dir_all(&source_dir)?;
-
+
println!("Cloning {} from {}", install_data.package.name, git_repo);
Self::clone_repo(&git_repo, &source_dir)?;
-
+
let source_path = source_dir.to_string_lossy().to_string();
println!("Source code downloaded to: {}", source_path);
-
+
return Ok(source_path);
}
}
-
+
// Fall back to index if INSTALL file doesn't exist or doesn't have git_repo
let index_path = Path::new(&config.paths.cache_dir).join("INDEX.toml");
-
+
if !index_path.exists() {
return Err("Index file not found. Please run 'mesk update' first.".into());
}
let index_content = fs::read_to_string(&index_path)?;
- let index: crate::pkgtoolkit::types::Index = toml::from_str(&index_content)
- .map_err(|e| format!("Failed to parse index: {}", e))?;
+ let index: crate::pkgtoolkit::types::Index =
+ toml::from_str(&index_content).map_err(|e| format!("Failed to parse index: {}", e))?;
- let package = index.packages.iter()
+ let package = index
+ .packages
+ .iter()
.find(|pkg| pkg.name == pkg_name)
.ok_or(format!("Package '{}' not found in index", pkg_name))?;