-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.go
36 lines (31 loc) · 909 Bytes
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package packages
import (
"github.com/MarconiProtocol/cli/core/configs"
"sync"
)
type PackageManager struct {
}
var instance *PackageManager
var once sync.Once
func Instance() *PackageManager {
once.Do(func() {
instance = &PackageManager{}
})
return instance
}
/*
Downloads or updates the packages as defined in config
*/
func (pm *PackageManager) UpdatePackages(baseDir string, packagesConfig *configs.PackagesConfig) {
autoUpdateEnabled := packagesConfig.AutoUpdateEnabled
for _, config := range packagesConfig.Packages {
// Check if the package's version file exist as a proxy for whether the package itself exists
packageExists := doesPackageVersionFileExist(baseDir, config)
// If the package does not exist, just download
if !packageExists {
downloadPackage(baseDir, config)
} else {
updatePackage(baseDir, config, autoUpdateEnabled)
}
}
}