|
@@ -6,6 +6,7 @@ import (
|
|
|
"bytes"
|
|
|
"crypto/sha256"
|
|
|
"encoding/hex"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"net/http"
|
|
@@ -82,14 +83,14 @@ func (i *Item) downloadLatest(overwrite bool, updateOnly bool) (string, error) {
|
|
|
i.hub.logger.Tracef("collection, recurse")
|
|
|
|
|
|
if _, err := sub.downloadLatest(overwrite, updateOnly); err != nil {
|
|
|
- return "", fmt.Errorf("while downloading %s: %w", sub.Name, err)
|
|
|
+ return "", err
|
|
|
}
|
|
|
}
|
|
|
|
|
|
downloaded := sub.State.Downloaded
|
|
|
|
|
|
if _, err := sub.download(overwrite); err != nil {
|
|
|
- return "", fmt.Errorf("while downloading %s: %w", sub.Name, err)
|
|
|
+ return "", err
|
|
|
}
|
|
|
|
|
|
// We need to enable an item when it has been added to a collection since latest release of the collection.
|
|
@@ -108,7 +109,7 @@ func (i *Item) downloadLatest(overwrite bool, updateOnly bool) (string, error) {
|
|
|
|
|
|
ret, err := i.download(overwrite)
|
|
|
if err != nil {
|
|
|
- return "", fmt.Errorf("failed to download item: %w", err)
|
|
|
+ return "", err
|
|
|
}
|
|
|
|
|
|
return ret, nil
|
|
@@ -116,6 +117,10 @@ func (i *Item) downloadLatest(overwrite bool, updateOnly bool) (string, error) {
|
|
|
|
|
|
// FetchLatest downloads the latest item from the hub, verifies the hash and returns the content and the used url.
|
|
|
func (i *Item) FetchLatest() ([]byte, string, error) {
|
|
|
+ if i.latestHash() == "" {
|
|
|
+ return nil, "", errors.New("latest hash missing from index")
|
|
|
+ }
|
|
|
+
|
|
|
url, err := i.hub.remote.urlTo(i.RemotePath)
|
|
|
if err != nil {
|
|
|
return nil, "", fmt.Errorf("failed to build request: %w", err)
|
|
@@ -146,7 +151,7 @@ func (i *Item) FetchLatest() ([]byte, string, error) {
|
|
|
i.hub.logger.Errorf("Downloaded version doesn't match index, please 'hub update'")
|
|
|
i.hub.logger.Debugf("got %s, expected %s", meow, i.Versions[i.Version].Digest)
|
|
|
|
|
|
- return nil, "", fmt.Errorf("invalid download hash for %s", i.Name)
|
|
|
+ return nil, "", fmt.Errorf("invalid download hash")
|
|
|
}
|
|
|
|
|
|
return body, url, nil
|
|
@@ -180,7 +185,12 @@ func (i *Item) download(overwrite bool) (string, error) {
|
|
|
|
|
|
body, url, err := i.FetchLatest()
|
|
|
if err != nil {
|
|
|
- return "", fmt.Errorf("while downloading %s: %w", url, err)
|
|
|
+ what := i.Name
|
|
|
+ if url != "" {
|
|
|
+ what += " from " + url
|
|
|
+ }
|
|
|
+
|
|
|
+ return "", fmt.Errorf("while downloading %s: %w", what, err)
|
|
|
}
|
|
|
|
|
|
// all good, install
|