diff --git a/main.go b/main.go index 10a6570..9efa20e 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( /* A simple-to-use package manager */ /* ---------------------------------- */ -var bpmVer = "0.4" +var bpmVer = "0.4.1" var subcommand = "help" var subcommandArgs []string @@ -99,7 +99,7 @@ func resolveCommand() { var info *utils.PackageInfo info = utils.GetPackageInfo(pkg, rootDir, false) if info == nil { - log.Fatalf("Package (%s) is not installed\n", pkg) + log.Fatalf("Error: package (%s) is not installed\n", pkg) } fmt.Println("----------------") fmt.Println(utils.CreateReadableInfo(true, true, true, info, rootDir)) @@ -110,7 +110,7 @@ func resolveCommand() { case list: packages, err := utils.GetInstalledPackages(rootDir) if err != nil { - log.Fatalf("Could not get installed packages\nError: %s", err.Error()) + log.Fatalf("Error: could not get installed packages: %s", err.Error()) return } if pkgListNumbers { @@ -139,8 +139,7 @@ func resolveCommand() { case search: searchTerms := subcommandArgs if len(searchTerms) == 0 { - fmt.Println("No search terms given") - os.Exit(0) + log.Fatalf("Error: no search terms given") } for _, term := range searchTerms { @@ -157,18 +156,17 @@ func resolveCommand() { } results := append(nameResults, descResults...) if len(results) == 0 { - log.Fatalf("No results for term (%s) were found\n", term) + log.Fatalf("Error: no results for term (%s) were found\n", term) } fmt.Printf("Results for term (%s)\n", term) for i, result := range results { fmt.Println("----------------") - fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.Version) + fmt.Printf("%d) %s: %s (%s)\n", i+1, result.Name, result.Description, result.GetFullVersion()) } } case install: if os.Getuid() != 0 { - fmt.Println("This subcommand needs to be run with superuser permissions") - os.Exit(0) + log.Fatalf("Error: this subcommand needs to be run with superuser permissions") } pkgs := subcommandArgs if len(pkgs) == 0 { @@ -189,9 +187,9 @@ func resolveCommand() { if stat, err := os.Stat(pkg); err == nil && !stat.IsDir() { pkgInfo, err := utils.ReadPackage(pkg) if err != nil { - log.Fatalf("Could not read package. Error: %s\n", err) + log.Fatalf("Error: could not read package: %s\n", err) } - if !reinstall && utils.IsPackageInstalled(pkgInfo.Name, rootDir) && utils.GetPackageInfo(pkgInfo.Name, rootDir, true).Version == pkgInfo.Version { + if !reinstall && utils.IsPackageInstalled(pkgInfo.Name, rootDir) && utils.GetPackageInfo(pkgInfo.Name, rootDir, true).GetFullVersion() == pkgInfo.GetFullVersion() { continue } pkgsToInstall.Set(pkgInfo.Name, &struct { @@ -203,9 +201,9 @@ func resolveCommand() { } else { entry, _, err := utils.GetRepositoryEntry(pkg) if err != nil { - log.Fatalf("Could not find package (%s) in any repository\n", pkg) + log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) } - if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir, true).Version == entry.Info.Version { + if !reinstall && utils.IsPackageInstalled(entry.Info.Name, rootDir) && utils.GetPackageInfo(entry.Info.Name, rootDir, true).GetFullVersion() == entry.Info.GetFullVersion() { continue } pkgsToInstall.Set(entry.Info.Name, &struct { @@ -226,7 +224,7 @@ func resolveCommand() { }]() for _, pkg := range clone.Keys() { value, _ := clone.Get(pkg) - resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, !reinstall, rootDir) + resolved, unresolved := value.pkgInfo.ResolveAll(&[]string{}, &[]string{}, value.pkgInfo.Type == "source", !noOptional, !reinstall, rootDir) unresolvedDepends = append(unresolvedDepends, unresolved...) for _, depend := range resolved { if _, ok := pkgsToInstall.Get(depend); !ok && depend != value.pkgInfo.Name { @@ -235,7 +233,7 @@ func resolveCommand() { } entry, _, err := utils.GetRepositoryEntry(depend) if err != nil { - log.Fatalf("Could not find package (%s) in any repository\n", pkg) + log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) } pkgsToInstall.Set(depend, &struct { bpmFile string @@ -251,7 +249,7 @@ func resolveCommand() { // Show summary if len(unresolvedDepends) != 0 { if !force { - log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolvedDepends, ", ")) + log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolvedDepends, ", ")) } else { log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolvedDepends, ", ")) } @@ -265,14 +263,21 @@ func resolveCommand() { value, _ := pkgsToInstall.Get(pkg) pkgInfo := value.pkgInfo installedInfo := utils.GetPackageInfo(pkgInfo.Name, rootDir, false) + sourceInfo := "" + if pkgInfo.Type == "source" { + if rootDir != "/" && !force { + log.Fatalf("Error: cannot compile and install source packages to a different root directory") + } + sourceInfo = "(From Source)" + } if installedInfo == nil { - fmt.Printf("%s: %s (Install)\n", pkgInfo.Name, pkgInfo.Version) - } else if strings.Compare(pkgInfo.Version, installedInfo.Version) < 0 { - fmt.Printf("%s: %s -> %s (Downgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version) - } else if strings.Compare(pkgInfo.Version, installedInfo.Version) > 0 { - fmt.Printf("%s: %s -> %s (Upgrade)\n", pkgInfo.Name, installedInfo.Version, pkgInfo.Version) + fmt.Printf("%s: %s (Install) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo) + } else if strings.Compare(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion()) < 0 { + fmt.Printf("%s: %s -> %s (Downgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo) + } else if strings.Compare(pkgInfo.GetFullVersion(), installedInfo.GetFullVersion()) > 0 { + fmt.Printf("%s: %s -> %s (Upgrade) %s\n", pkgInfo.Name, installedInfo.GetFullVersion(), pkgInfo.GetFullVersion(), sourceInfo) } else { - fmt.Printf("%s: %s (Reinstall)\n", pkgInfo.Name, pkgInfo.Version) + fmt.Printf("%s: %s (Reinstall) %s\n", pkgInfo.Name, pkgInfo.GetFullVersion(), sourceInfo) } } if rootDir != "/" { @@ -280,7 +285,12 @@ func resolveCommand() { } if !yesAll { reader := bufio.NewReader(os.Stdin) - fmt.Printf("Do you wish to install these %d packages? [y\\N] ", pkgsToInstall.Len()) + if pkgsToInstall.Len() == 1 { + fmt.Printf("Do you wish to install this package? [y\\N] ") + } else { + fmt.Printf("Do you wish to install these %d packages? [y\\N] ", pkgsToInstall.Len()) + } + text, _ := reader.ReadString('\n') if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" { fmt.Println("Cancelling...") @@ -297,12 +307,13 @@ func resolveCommand() { } entry, repo, err := utils.GetRepositoryEntry(pkg) if err != nil { - log.Fatalf("Could not find package (%s) in any repository\n", pkg) + log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) } fetchedPackage, err := repo.FetchPackage(entry.Info.Name) if err != nil { - log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err) + log.Fatalf("Error: could not fetch package (%s): %s\n", pkg, err) } + fmt.Printf("Package (%s) was successfully fetched!\n", value.pkgInfo.Name) value.bpmFile = fetchedPackage pkgsToInstall.Set(pkg, value) } @@ -322,13 +333,13 @@ func resolveCommand() { if pkgInfo.Type == "source" && keepTempDir { fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name) } - log.Fatalf("Could not install package (%s). Error: %s\n", pkg, err) + log.Fatalf("Error: could not install package (%s): %s\n", pkg, err) } - fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name) + fmt.Printf("Package (%s) was successfully installed\n", pkgInfo.Name) if value.isDependency { err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir) if err != nil { - log.Fatalf("Could not set installation reason for package\nError: %s\n", err) + log.Fatalf("Error: could not set installation reason for package: %s\n", err) } } if pkgInfo.Type == "source" && keepTempDir { @@ -337,8 +348,7 @@ func resolveCommand() { } case update: if os.Getuid() != 0 { - fmt.Println("This subcommand needs to be run with superuser permissions") - os.Exit(0) + log.Fatalf("Error: this subcommand needs to be run with superuser permissions") } // Sync repositories @@ -347,7 +357,7 @@ func resolveCommand() { fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name) err := repo.SyncLocalDatabase() if err != nil { - log.Fatal(err) + log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err) } } fmt.Println("All package databases synced successfully!") @@ -358,7 +368,7 @@ func resolveCommand() { // Get installed packages and check for updates pkgs, err := utils.GetInstalledPackages(rootDir) if err != nil { - log.Fatalf("Could not get installed packages! Error: %s\n", err) + log.Fatalf("Error: could not get installed packages: %s\n", err) } toUpdate := orderedmap.NewOrderedMap[string, *struct { isDependency bool @@ -371,9 +381,9 @@ func resolveCommand() { } installedInfo := utils.GetPackageInfo(pkg, rootDir, true) if installedInfo == nil { - log.Fatalf(pkg) + log.Fatalf("Error: could not get package info for (%s)\n", pkg) } - if strings.Compare(entry.Info.Version, installedInfo.Version) > 0 { + if strings.Compare(entry.Info.GetFullVersion(), installedInfo.GetFullVersion()) > 0 { toUpdate.Set(entry.Info.Name, &struct { isDependency bool entry *utils.RepositoryEntry @@ -395,13 +405,13 @@ func resolveCommand() { clone := toUpdate.Copy() for _, key := range clone.Keys() { pkg, _ := clone.Get(key) - r, u := pkg.entry.Info.ResolveAll(&[]string{}, &[]string{}, false, !noOptional, true, rootDir) + r, u := pkg.entry.Info.ResolveAll(&[]string{}, &[]string{}, pkg.entry.Info.Type == "source", !noOptional, true, rootDir) unresolved = append(unresolved, u...) for _, depend := range r { if _, ok := toUpdate.Get(depend); !ok { entry, _, err := utils.GetRepositoryEntry(depend) if err != nil { - log.Fatalf("Could not find package (%s) in any repository\n", depend) + log.Fatalf("Error: could not find package (%s) in any repository\n", depend) } toUpdate.Set(depend, &struct { isDependency bool @@ -413,23 +423,27 @@ func resolveCommand() { if len(unresolved) != 0 { if !force { - log.Fatalf("The following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", ")) + log.Fatalf("Error: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", ")) } else { - log.Println("Warning: The following dependencies could not be found in any repositories: " + strings.Join(unresolved, ", ")) + log.Printf("Warning: the following dependencies could not be found in any repositories: %s\n", strings.Join(unresolved, ", ")) } } for _, key := range toUpdate.Keys() { value, _ := toUpdate.Get(key) installedInfo := utils.GetPackageInfo(value.entry.Info.Name, rootDir, true) + sourceInfo := "" + if value.entry.Info.Type == "source" { + sourceInfo = "(From Source)" + } if installedInfo == nil { - fmt.Printf("%s: %s (Install)\n", value.entry.Info.Name, value.entry.Info.Version) + fmt.Printf("%s: %s (Install) %s\n", value.entry.Info.Name, value.entry.Info.GetFullVersion(), sourceInfo) continue } - if strings.Compare(value.entry.Info.Version, installedInfo.Version) > 0 { - fmt.Printf("%s: %s -> %s (Upgrade)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version) + if strings.Compare(value.entry.Info.GetFullVersion(), installedInfo.GetFullVersion()) > 0 { + fmt.Printf("%s: %s -> %s (Upgrade) %s\n", value.entry.Info.Name, installedInfo.GetFullVersion(), value.entry.Info.GetFullVersion(), sourceInfo) } else if reinstall { - fmt.Printf("%s: %s -> %s (Reinstall)\n", value.entry.Info.Name, installedInfo.Version, value.entry.Info.Version) + fmt.Printf("%s: %s -> %s (Reinstall) %s\n", value.entry.Info.Name, installedInfo.GetFullVersion(), value.entry.Info.GetFullVersion(), sourceInfo) } } @@ -440,7 +454,7 @@ func resolveCommand() { text, _ := reader.ReadString('\n') if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" { fmt.Println("Cancelling update...") - os.Exit(0) + os.Exit(1) } } @@ -451,16 +465,17 @@ func resolveCommand() { }]() fmt.Println("Fetching packages from available repositories...") for _, pkg := range toUpdate.Keys() { - isDependency, _ := toUpdate.Get(pkg) + value, _ := toUpdate.Get(pkg) entry, repo, err := utils.GetRepositoryEntry(pkg) if err != nil { - log.Fatalf("Could not find package (%s) in any repository\n", pkg) + log.Fatalf("Error: could not find package (%s) in any repository\n", pkg) } fetchedPackage, err := repo.FetchPackage(entry.Info.Name) if err != nil { - log.Fatalf("Could not fetch package (%s). Error: %s\n", pkg, err) + log.Fatalf("Error: could not fetch package (%s): %s\n", pkg, err) } - pkgsToInstall.Set(fetchedPackage, isDependency) + fmt.Printf("Package (%s) was successfully fetched!\n", value.entry.Info.Name) + pkgsToInstall.Set(fetchedPackage, value) } // Install fetched packages @@ -478,13 +493,13 @@ func resolveCommand() { if pkgInfo.Type == "source" && keepTempDir { fmt.Println("BPM temp directory was created at /var/tmp/bpm_source-" + pkgInfo.Name) } - log.Fatalf("Could not install package (%s). Error: %s\n", pkg, err) + log.Fatalf("Error: could not install package (%s): %s\n", pkg, err) } fmt.Printf("Package (%s) was successfully installed!\n", pkgInfo.Name) if value.isDependency { err := utils.SetInstallationReason(pkgInfo.Name, utils.Dependency, rootDir) if err != nil { - log.Fatalf("Could not set installation reason for package\nError: %s\n", err) + log.Fatalf("Error: could not set installation reason for package: %s\n", err) } } if pkgInfo.Type == "source" && keepTempDir { @@ -493,8 +508,7 @@ func resolveCommand() { } case sync: if os.Getuid() != 0 { - fmt.Println("This subcommand needs to be run with superuser permissions") - os.Exit(0) + log.Fatalf("Error: this subcommand needs to be run with superuser permissions") } if !yesAll { fmt.Printf("Are you sure you wish to sync all databases? [y\\N] ") @@ -502,21 +516,20 @@ func resolveCommand() { text, _ := reader.ReadString('\n') if strings.TrimSpace(strings.ToLower(text)) != "y" && strings.TrimSpace(strings.ToLower(text)) != "yes" { fmt.Println("Cancelling sync...") - os.Exit(0) + os.Exit(1) } } for _, repo := range utils.BPMConfig.Repositories { fmt.Printf("Fetching package database for repository (%s)...\n", repo.Name) err := repo.SyncLocalDatabase() if err != nil { - log.Fatal(err) + log.Fatalf("Error: could not sync local database for repository (%s): %s\n", repo.Name, err) } } fmt.Println("All package databases synced successfully!") case remove: if os.Getuid() != 0 { - fmt.Println("This subcommand needs to be run with superuser permissions") - os.Exit(0) + log.Fatalf("Error: this subcommand needs to be run with superuser permissions") } packages := subcommandArgs if len(packages) == 0 { @@ -546,7 +559,7 @@ func resolveCommand() { err := utils.RemovePackage(pkg, verbose, rootDir) if err != nil { - log.Fatalf("Could not remove package\nError: %s\n", err) + log.Fatalf("Error: could not remove package: %s\n", err) } fmt.Printf("Package (%s) was successfully removed!\n", pkgInfo.Name) } @@ -559,23 +572,23 @@ func resolveCommand() { for _, file := range files { absFile, err := filepath.Abs(file) if err != nil { - log.Fatalf("Could not get absolute path of %s", file) + log.Fatalf("Error: could not get absolute path of file (%s)\n", file) } stat, err := os.Stat(absFile) if os.IsNotExist(err) { - log.Fatalf(absFile + " does not exist!") + log.Fatalf("Error: file (%s) does not exist!\n", absFile) } pkgs, err := utils.GetInstalledPackages(rootDir) if err != nil { - log.Fatalf("Could not get installed packages. Error %s", err.Error()) + log.Fatalf("Error: could not get installed packages: %s\n", err.Error()) } if !strings.HasPrefix(absFile, rootDir) { - log.Fatalf("Could not get relative path of %s to root path", absFile) + log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile) } absFile, err = filepath.Rel(rootDir, absFile) if err != nil { - log.Fatalf("Could not get relative path of %s to root path", absFile) + log.Fatalf("Error: could not get path of file (%s) relative to root path", absFile) } absFile = strings.TrimPrefix(absFile, "/") if stat.IsDir() { diff --git a/utils/package_utils.go b/utils/package_utils.go index d0c34cb..9c4fb69 100644 --- a/utils/package_utils.go +++ b/utils/package_utils.go @@ -23,6 +23,7 @@ type PackageInfo struct { Name string `yaml:"name,omitempty"` Description string `yaml:"description,omitempty"` Version string `yaml:"version,omitempty"` + Revision int `yaml:"revision,omitempty"` Url string `yaml:"url,omitempty"` License string `yaml:"license,omitempty"` Arch string `yaml:"architecture,omitempty"` @@ -35,6 +36,10 @@ type PackageInfo struct { Provides []string `yaml:"provides,omitempty"` } +func (pkgInfo *PackageInfo) GetFullVersion() string { + return pkgInfo.Version + "-" + strconv.Itoa(pkgInfo.Revision) +} + type InstallationReason string const ( @@ -132,7 +137,7 @@ func ReadPackage(filename string) (*PackageInfo, error) { if err != nil { return nil, err } - pkgInfo, err := ReadPackageInfo(string(bs), false) + pkgInfo, err := ReadPackageInfo(string(bs)) if err != nil { return nil, err } @@ -306,11 +311,12 @@ func ExecutePackageScripts(filename, rootDir string, operation Operation, postOp return nil } -func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) { +func ReadPackageInfo(contents string) (*PackageInfo, error) { pkgInfo := PackageInfo{ Name: "", Description: "", Version: "", + Revision: 1, Url: "", License: "", Arch: "", @@ -326,18 +332,18 @@ func ReadPackageInfo(contents string, defaultValues bool) (*PackageInfo, error) if err != nil { return nil, err } - if !defaultValues { - if pkgInfo.Name == "" { - return nil, errors.New("this package contains no name") - } else if pkgInfo.Description == "" { - return nil, errors.New("this package contains no description") - } else if pkgInfo.Version == "" { - return nil, errors.New("this package contains no version") - } else if pkgInfo.Arch == "" { - return nil, errors.New("this package contains no architecture") - } else if pkgInfo.Type == "" { - return nil, errors.New("this package contains no type") - } + if pkgInfo.Name == "" { + return nil, errors.New("this package contains no name") + } else if pkgInfo.Description == "" { + return nil, errors.New("this package contains no description") + } else if pkgInfo.Version == "" { + return nil, errors.New("this package contains no version") + } else if pkgInfo.Revision <= 0 { + return nil, errors.New("this package contains a revision number less or equal to 0") + } else if pkgInfo.Arch == "" { + return nil, errors.New("this package contains no architecture") + } else if pkgInfo.Type == "" { + return nil, errors.New("this package contains no type") } for i := 0; i < len(pkgInfo.Keep); i++ { pkgInfo.Keep[i] = strings.TrimPrefix(pkgInfo.Keep[i], "/") @@ -363,7 +369,7 @@ func CreateReadableInfo(showArchitecture, showType, showPackageRelations bool, p } ret = append(ret, "Name: "+pkgInfo.Name) ret = append(ret, "Description: "+pkgInfo.Description) - ret = append(ret, "Version: "+pkgInfo.Version) + ret = append(ret, "Version: "+pkgInfo.GetFullVersion()) ret = append(ret, "URL: "+pkgInfo.Url) ret = append(ret, "License: "+pkgInfo.License) if showArchitecture { @@ -504,7 +510,7 @@ func extractPackage(pkgInfo *PackageInfo, verbose bool, filename, rootDir string return err, nil } default: - return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename), nil + return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename), nil } } } @@ -638,7 +644,7 @@ func compilePackage(pkgInfo *PackageInfo, filename, rootDir string, verbose, bin fmt.Println("Skipping hard link (Bundling hard links in source packages is not supported)") } default: - return errors.New("ExtractTarGz: unknown type: " + strconv.Itoa(int(header.Typeflag)) + " in " + extractFilename), nil + return errors.New("unknown type (" + strconv.Itoa(int(header.Typeflag)) + ") in " + extractFilename), nil } } if header.Name == "source.sh" { @@ -776,6 +782,7 @@ fi cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version)) + cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.Revision)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch)) depends := make([]string, len(pkgInfo.Depends)) @@ -928,7 +935,7 @@ fi } } sed := fmt.Sprintf("s/output/files/") - fileName := compiledInfo.Name + "-" + compiledInfo.Version + "-" + compiledInfo.Arch + ".bpm" + fileName := compiledInfo.Name + "-" + compiledInfo.GetFullVersion() + "-" + compiledInfo.Arch + ".bpm" cmd := exec.Command("/usr/bin/fakeroot", "-i fakeroot_file", "tar", "-czvpf", fileName, "pkg.info", "output/", "--transform", sed) if !BPMConfig.SilentCompilation { cmd.Stdin = os.Stdin @@ -987,7 +994,7 @@ func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc, return errors.New("cannot install a package with a different architecture") } if unresolved := pkgInfo.CheckDependencies(pkgInfo.Type == "source", true, rootDir); len(unresolved) != 0 { - return errors.New("Could not resolve all dependencies. Missing " + strings.Join(unresolved, ", ")) + return errors.New("the following dependencies are not installed: " + strings.Join(unresolved, ", ")) } } if pkgInfo.Type == "binary" { @@ -1006,7 +1013,7 @@ func InstallPackage(filename, rootDir string, verbose, force, binaryPkgFromSrc, } files = i } else { - return errors.New("Unknown package type: " + pkgInfo.Type) + return errors.New("unknown package type: " + pkgInfo.Type) } slices.Sort(files) slices.Reverse(files) @@ -1273,7 +1280,9 @@ func (pkgInfo *PackageInfo) ResolveAll(resolved, unresolved *[]string, checkMake entry.Info.ResolveAll(resolved, unresolved, checkMake, checkOptional, ignoreInstalled, rootDir) } } - *resolved = append(*resolved, pkgInfo.Name) + if !slices.Contains(*resolved, pkgInfo.Name) { + *resolved = append(*resolved, pkgInfo.Name) + } *unresolved = stringSliceRemove(*unresolved, pkgInfo.Name) return *resolved, *unresolved } @@ -1363,7 +1372,7 @@ func GetPackageInfo(pkg, rootDir string, defaultValues bool) *PackageInfo { if err != nil { return nil } - info, err := ReadPackageInfo(string(bs), defaultValues) + info, err := ReadPackageInfo(string(bs)) if err != nil { return nil } @@ -1463,6 +1472,7 @@ func RemovePackage(pkg string, verbose bool, rootDir string) error { cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_NAME=%s", pkgInfo.Name)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_DESC=%s", pkgInfo.Description)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_VERSION=%s", pkgInfo.Version)) + cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_REVISION=%d", pkgInfo.Revision)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_URL=%s", pkgInfo.Url)) cmd.Env = append(cmd.Env, fmt.Sprintf("BPM_PKG_ARCH=%s", pkgInfo.Arch)) depends := make([]string, len(pkgInfo.Depends)) diff --git a/utils/repo_utils.go b/utils/repo_utils.go index 68ce00e..80fd42b 100644 --- a/utils/repo_utils.go +++ b/utils/repo_utils.go @@ -46,6 +46,7 @@ func (repo *Repository) ReadLocalDatabase() error { Name: "", Description: "", Version: "", + Revision: 1, Url: "", License: "", Arch: "", @@ -137,7 +138,7 @@ func GetRepositoryEntry(str string) (*RepositoryEntry, *Repository, error) { func (repo *Repository) FetchPackage(pkg string) (string, error) { if !repo.ContainsPackage(pkg) { - return "", errors.New("Could not fetch package '" + pkg + "'") + return "", errors.New("could not fetch package '" + pkg + "'") } entry := repo.Entries[pkg] URL, err := url.JoinPath(repo.Source, entry.Download)