fix #1083 : do not update/overwrite 'not installed' collections sub-items on 'cscli XX upgrade' (#1089)
* fix #1083 : do not update/overwrite 'not installed' collections sub-items on 'cscli XX upgrade'
This commit is contained in:
parent
c7fb6a1428
commit
e5204bc1b1
|
@ -149,7 +149,7 @@ func InstallItem(name string, obtype string, force bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item, err := cwhub.DownloadLatest(csConfig.Hub, item, force)
|
item, err := cwhub.DownloadLatest(csConfig.Hub, item, force, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error while downloading %s : %v", item.Name, err)
|
log.Fatalf("error while downloading %s : %v", item.Name, err)
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ func UpgradeConfig(itemType string, name string, force bool) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v, err = cwhub.DownloadLatest(csConfig.Hub, v, force)
|
v, err = cwhub.DownloadLatest(csConfig.Hub, v, force, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%s : download failed : %v", v.Name, err)
|
log.Fatalf("%s : download failed : %v", v.Name, err)
|
||||||
}
|
}
|
||||||
|
@ -515,7 +515,7 @@ func silenceInstallItem(name string, obtype string) (string, error) {
|
||||||
if downloadOnly && it.Downloaded && it.UpToDate {
|
if downloadOnly && it.Downloaded && it.UpToDate {
|
||||||
return fmt.Sprintf("%s is already downloaded and up-to-date", it.Name), nil
|
return fmt.Sprintf("%s is already downloaded and up-to-date", it.Name), nil
|
||||||
}
|
}
|
||||||
it, err := cwhub.DownloadLatest(csConfig.Hub, it, forceAction)
|
it, err := cwhub.DownloadLatest(csConfig.Hub, it, forceAction, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error while downloading %s : %v", it.Name, err)
|
return "", fmt.Errorf("error while downloading %s : %v", it.Name, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ func test_prepenv() *csconfig.Config {
|
||||||
func testInstallItem(cfg *csconfig.Hub, t *testing.T, item Item) {
|
func testInstallItem(cfg *csconfig.Hub, t *testing.T, item Item) {
|
||||||
|
|
||||||
//Install the parser
|
//Install the parser
|
||||||
item, err := DownloadLatest(cfg, item, false)
|
item, err := DownloadLatest(cfg, item, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error while downloading %s : %v", item.Name, err)
|
t.Fatalf("error while downloading %s : %v", item.Name, err)
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ func testUpdateItem(cfg *csconfig.Hub, t *testing.T, item Item) {
|
||||||
t.Fatalf("update: %s should NOT be up-to-date", item.Name)
|
t.Fatalf("update: %s should NOT be up-to-date", item.Name)
|
||||||
}
|
}
|
||||||
//Update it + check status
|
//Update it + check status
|
||||||
item, err := DownloadLatest(cfg, item, true)
|
item, err := DownloadLatest(cfg, item, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to update %s : %s", item.Name, err)
|
t.Fatalf("failed to update %s : %s", item.Name, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func DownloadHubIdx(hub *csconfig.Hub) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//DownloadLatest will download the latest version of Item to the tdir directory
|
//DownloadLatest will download the latest version of Item to the tdir directory
|
||||||
func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool) (Item, error) {
|
func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool, updateOnly bool) (Item, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
log.Debugf("Downloading %s %s", target.Type, target.Name)
|
log.Debugf("Downloading %s %s", target.Type, target.Name)
|
||||||
|
@ -86,11 +86,15 @@ func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool) (Item, error
|
||||||
ptrtype := ItemTypes[idx]
|
ptrtype := ItemTypes[idx]
|
||||||
for _, p := range ptr {
|
for _, p := range ptr {
|
||||||
if val, ok := hubIdx[ptrtype][p]; ok {
|
if val, ok := hubIdx[ptrtype][p]; ok {
|
||||||
log.Debugf("Download %s sub-item : %s %s", target.Name, ptrtype, p)
|
if !val.Installed && updateOnly {
|
||||||
|
log.Debugf("skipping upgrade of %s : not installed", target.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Debugf("Download %s sub-item : %s %s (%t -> %t)", target.Name, ptrtype, p, target.Installed, updateOnly)
|
||||||
//recurse as it's a collection
|
//recurse as it's a collection
|
||||||
if ptrtype == COLLECTIONS {
|
if ptrtype == COLLECTIONS {
|
||||||
log.Tracef("collection, recurse")
|
log.Tracef("collection, recurse")
|
||||||
hubIdx[ptrtype][p], err = DownloadLatest(hub, val, overwrite)
|
hubIdx[ptrtype][p], err = DownloadLatest(hub, val, overwrite, updateOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return target, errors.Wrap(err, fmt.Sprintf("while downloading %s", val.Name))
|
return target, errors.Wrap(err, fmt.Sprintf("while downloading %s", val.Name))
|
||||||
}
|
}
|
||||||
|
@ -118,6 +122,10 @@ func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool) (Item, error
|
||||||
return target, fmt.Errorf("failed to download item : %s", err)
|
return target, fmt.Errorf("failed to download item : %s", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if !target.Installed && updateOnly {
|
||||||
|
log.Debugf("skipping upgrade of %s : not installed", target.Name)
|
||||||
|
return target, nil
|
||||||
|
}
|
||||||
return DownloadItem(hub, target, overwrite)
|
return DownloadItem(hub, target, overwrite)
|
||||||
}
|
}
|
||||||
return target, nil
|
return target, nil
|
||||||
|
|
Loading…
Reference in a new issue