updated spm package

This commit is contained in:
partisan 2025-02-04 17:11:27 +01:00
parent 3f67a0a6de
commit 7373e47c1d
11 changed files with 594 additions and 475 deletions

View file

@ -10,98 +10,6 @@ import (
"time"
)
// func DownloadPackage(pkg Package, destDir string, version, release, pkgType string) error {
// client := &http.Client{}
// var resp *http.Response
// var err error
// for i := 0; i < 3; i++ { // Retry up to 3 times
// fmt.Printf("[INFO] Attempting to download package from URL: %s (Attempt %d)\n", pkg.DownloadURL, i+1)
// resp, err = client.Get(pkg.DownloadURL)
// if err == nil && resp.StatusCode == http.StatusOK {
// break
// }
// if err != nil {
// fmt.Printf("[ERROR] Attempt %d failed: %v\n", i+1, err)
// }
// if resp != nil && resp.StatusCode != http.StatusOK {
// fmt.Printf("[ERROR] Server returned status: %d\n", resp.StatusCode)
// }
// if i < 2 {
// time.Sleep(2 * time.Second) // Delay between retries
// }
// }
// if err != nil {
// return fmt.Errorf("[ERROR] Failed to download %s after 3 retries: %w", pkg.Name, err)
// }
// defer resp.Body.Close()
// // Check content type
// contentType := resp.Header.Get("Content-Type")
// if contentType != "application/gzip" && contentType != "application/x-tar" {
// return fmt.Errorf("[ERROR] Invalid content type: %s. Expected a .tar.gz file.", contentType)
// }
// // Generate the filename using the desired format
// filename := fmt.Sprintf("%s@%s@%s@%s@%s@%s.tar.gz",
// pkg.Name, // Name of the package
// pkg.Arch, // Architecture (e.g., amd64)
// pkg.OS, // Operating System (e.g., windows, linux)
// pkgType, // Type of the package (e.g., nightly, stable)
// release, // Release (e.g., nightly, stable)
// version, // Version of the package
// )
// // Construct the full file path
// filePath := filepath.Join(destDir, filename)
// fmt.Printf("[INFO] Saving package to: %s\n", filePath)
// // Create the destination directory if it doesn't exist
// err = os.MkdirAll(destDir, 0755)
// if err != nil {
// return fmt.Errorf("[ERROR] Failed to create destination directory %s: %w", destDir, err)
// }
// // Create the file to save the download
// out, err := os.Create(filePath)
// if err != nil {
// return fmt.Errorf("[ERROR] Failed to create file %s: %w", filePath, err)
// }
// defer out.Close()
// // Track download progress
// totalSize := resp.ContentLength
// var downloaded int64
// buf := make([]byte, 1024)
// for {
// n, err := resp.Body.Read(buf)
// if n > 0 {
// downloaded += int64(n)
// percentage := int(float64(downloaded) / float64(totalSize) * 100)
// UpdateProgress(percentage, fmt.Sprintf("Downloading %s", pkg.Name))
// if _, err := out.Write(buf[:n]); err != nil {
// return fmt.Errorf("[ERROR] Failed to write to file %s: %w", filePath, err)
// }
// }
// if err == io.EOF {
// break
// }
// if err != nil {
// return fmt.Errorf("[ERROR] Error reading response body: %w", err)
// }
// }
// UpdateProgress(100, fmt.Sprintf("%s downloaded", pkg.Name))
// fmt.Printf("[INFO] Package %s downloaded successfully to: %s\n", pkg.Name, filePath)
// // Validate that the file is a valid gzip or tar file
// if _, err := os.Stat(filePath); err != nil {
// return fmt.Errorf("[ERROR] Downloaded file does not exist: %w", err)
// }
// return nil
// }
// DownloadPackageFromAppIndex selects and downloads the correct package from the APPINDEX.
func DownloadPackageFromAppIndex(appIndexPath string, packageName string, release string, pkgType string, destDir string) error {
// Parse the APPINDEX
@ -129,7 +37,7 @@ func DownloadPackageFromAppIndex(appIndexPath string, packageName string, releas
}
// Check if the package is already installed and up-to-date
installDir, err := GetDefaultInstallDir()
installDir, err := GetInstallDir()
if err != nil {
return fmt.Errorf("failed to get install directory: %w", err)
}