PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.4 KiB

package Package
import (
"errors"
"fmt"
"os"
"PackageManager/Archive"
"PackageManager/Client/Database"
"PackageManager/Variables"
)
func CheckPackageDependancies(deps map[string]string) ([]int64, error) {
var (
name, version string
depIds []int64
id int64
e error
)
for name, version = range deps {
id, e = Database.IsPackageInstalled(name, version)
if e != nil {
return depIds, e
}
depIds = append(depIds, id)
}
return depIds, e
}
func InstallPackage(pkgs []string) error {
var (
manifest Manifest
depIds []int64
pkg string
mStr string
e error
)
for _, pkg = range pkgs {
_, e = os.Stat(pkg)
if os.IsNotExist(e) {
return errors.New(fmt.Sprintf("Invalid package %s", pkg))
}
}
for _, pkg = range pkgs {
fmt.Printf(
"Installing %s...\n",
pkg,
)
mStr, e = Archive.ExtractManifestFile(pkg)
if e != nil {
return e
}
manifest, e = ParseManifestFile(mStr)
if e != nil {
return e
}
if !Variables.IgnoreDepsCheck {
depIds, e = CheckPackageDependancies(manifest.Dependancies)
if e != nil {
// TODO: Search for package on error
return e
}
}
e = Archive.ExtractArchive(pkg, Variables.RootDir)
if e != nil {
return e
}
e = Database.InsertPackage(manifest.Name, manifest.Version, depIds)
if e != nil {
return e
}
fmt.Printf(
"%s successfully installed\n",
pkg,
)
}
return nil
}