clean up
This commit is contained in:
parent
66f4191c5f
commit
44d20eb983
10 changed files with 319 additions and 72 deletions
38
auto.go
38
auto.go
|
@ -2,7 +2,6 @@ package spm
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
|
@ -10,22 +9,19 @@ import (
|
|||
// but not yet moved to the final install location, cuz Windows has this stupid file locking mechanism
|
||||
var pendingUpdates []AppIndexEntry
|
||||
|
||||
// AutoDownloadUpdates downloads the APPINDEX file, parses it, compares against
|
||||
// DownloadUpdates downloads the APPINDEX file, parses it, compares against
|
||||
// currently installed packages, and if it finds a newer version, downloads
|
||||
// and decompresses it into a temporary folder. The result is stored in pendingUpdates, so it can be used by AutoInstallUpdates().
|
||||
func AutoDownloadUpdates() error {
|
||||
// and decompresses it into a temporary folder. The result is stored in pendingUpdates, so it can be used by InstallUpdates().
|
||||
func DownloadUpdates() error {
|
||||
// 1) Download the APPINDEX file to a temporary location
|
||||
appIndexPath := filepath.Join(os.TempDir(), "APPINDEX")
|
||||
fmt.Println("[INFO] Starting APPINDEX download to:", appIndexPath)
|
||||
err := DownloadAppIndex(appIndexPath)
|
||||
err := UpdateIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("[ERROR] Failed to download APPINDEX: %w", err)
|
||||
}
|
||||
fmt.Println("[INFO] APPINDEX downloaded successfully")
|
||||
|
||||
// 2) Parse the APPINDEX file
|
||||
fmt.Println("[INFO] Parsing APPINDEX file:", appIndexPath)
|
||||
entries, err := ParseAppIndex(appIndexPath)
|
||||
entries, err := GetIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("[ERROR] Failed to parse APPINDEX: %w", err)
|
||||
}
|
||||
|
@ -84,7 +80,7 @@ func AutoDownloadUpdates() error {
|
|||
downloadDir := GetTempDir()
|
||||
fmt.Printf("[INFO] Downloading package '%s' to temporary folder: %s\n", matchingEntry.Name, downloadDir)
|
||||
|
||||
err = DownloadPackageFromAppIndex(appIndexPath, matchingEntry.Name, matchingEntry.Release, matchingEntry.Type, downloadDir)
|
||||
err = DownloadPackageFromAppIndex(matchingEntry.Name, matchingEntry.Release, matchingEntry.Type, downloadDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[ERROR] Failed to download package '%s': %w", matchingEntry.Name, err)
|
||||
}
|
||||
|
@ -99,7 +95,7 @@ func AutoDownloadUpdates() error {
|
|||
}
|
||||
fmt.Printf("[INFO] Package '%s' decompressed successfully to: %s\n", matchingEntry.Name, tempDir)
|
||||
|
||||
// 7) Store in pendingUpdates so that AutoInstallUpdates can finish the job
|
||||
// 7) Store in pendingUpdates so that InstallUpdates can finish the job
|
||||
fmt.Printf("[INFO] Adding '%s' to pending updates\n", matchingEntry.Name)
|
||||
pendingUpdates = append(pendingUpdates, AppIndexEntry{
|
||||
Name: matchingEntry.Name,
|
||||
|
@ -111,13 +107,13 @@ func AutoDownloadUpdates() error {
|
|||
})
|
||||
}
|
||||
|
||||
fmt.Println("[INFO] AutoDownloadUpdates completed successfully")
|
||||
fmt.Println("[INFO] DownloadUpdates completed successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
// AutoInstallUpdates installs any packages that were downloaded and decompressed by AutoDownloadUpdates.
|
||||
// InstallUpdates installs any packages that were downloaded and decompressed by DownloadUpdates.
|
||||
// It moves files from their temp directories to the final location and updates installed.ini.
|
||||
func AutoInstallUpdates() error {
|
||||
func InstallUpdates() error {
|
||||
installDir, err := GetInstallDir()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -146,7 +142,7 @@ func AutoInstallUpdates() error {
|
|||
}
|
||||
|
||||
// 5) Finalize
|
||||
err = FinalizeInstall(entry.Name, entry.Release, entry.Version, entry.Arch, entry.OS)
|
||||
err = finalizeInstall(entry.Name, entry.Release, entry.Version, entry.Arch, entry.OS)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to finalize install for %s: %w", entry.Name, err)
|
||||
}
|
||||
|
@ -156,18 +152,15 @@ func AutoInstallUpdates() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func AutoDownloadSpecified(specs []AppIndexEntry) error {
|
||||
func DownloadSpecified(specs []AppIndexEntry) error {
|
||||
// 1) Download the APPINDEX file to a temporary location
|
||||
appIndexPath := filepath.Join(os.TempDir(), "APPINDEX")
|
||||
fmt.Println("[INFO] Starting APPINDEX download to:", appIndexPath)
|
||||
if err := DownloadAppIndex(appIndexPath); err != nil {
|
||||
if err := UpdateIndex(); err != nil {
|
||||
return fmt.Errorf("[ERROR] Failed to download APPINDEX: %w", err)
|
||||
}
|
||||
fmt.Println("[INFO] APPINDEX downloaded successfully")
|
||||
|
||||
// 2) Parse the APPINDEX file
|
||||
fmt.Println("[INFO] Parsing APPINDEX file:", appIndexPath)
|
||||
entries, err := ParseAppIndex(appIndexPath)
|
||||
entries, err := GetIndex()
|
||||
if err != nil {
|
||||
return fmt.Errorf("[ERROR] Failed to parse APPINDEX: %w", err)
|
||||
}
|
||||
|
@ -225,7 +218,6 @@ func AutoDownloadSpecified(specs []AppIndexEntry) error {
|
|||
downloadDir := GetTempDir()
|
||||
fmt.Printf("[INFO] Downloading package '%s' to temporary folder: %s\n", matchingEntry.Name, downloadDir)
|
||||
if err := DownloadPackageFromAppIndex(
|
||||
appIndexPath,
|
||||
matchingEntry.Name,
|
||||
matchingEntry.Release,
|
||||
matchingEntry.Type,
|
||||
|
@ -251,7 +243,7 @@ func AutoDownloadSpecified(specs []AppIndexEntry) error {
|
|||
}
|
||||
fmt.Printf("[INFO] Package '%s' decompressed successfully to: %s\n", matchingEntry.Name, tempDir)
|
||||
|
||||
// 7) Store in pendingUpdates for AutoInstallUpdates
|
||||
// 7) Store in pendingUpdates for InstallUpdates
|
||||
fmt.Printf("[INFO] Adding '%s' to pending updates\n", matchingEntry.Name)
|
||||
pendingUpdates = append(pendingUpdates, *matchingEntry)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue