Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
handle unsupported schema correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Đặng Minh Dũng <dungdm93@live.com>
  • Loading branch information
dungdm93 committed Mar 18, 2024
1 parent bd22a93 commit ff303f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 2 additions & 10 deletions pkg/apk/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,14 @@ func (a *APK) InitKeyring(ctx context.Context, keyFiles, extraKeyFiles []string)
eg.Go(func() error {
log.Debugf("installing key %v", element)

var asURL *url.URL
var err error
if strings.HasPrefix(element, "https://") {
asURL, err = url.Parse(element)
} else {
// Attempt to parse non-https elements into URI's so they are translated into
// file:// URLs allowing them to parse into a url.URL{}
asURL, err = url.Parse(string(uri.New(element)))
}
asURL, err := url.Parse(element)
if err != nil {
return fmt.Errorf("failed to parse key as URI: %w", err)
}

var data []byte
switch asURL.Scheme {
case "file": //nolint:goconst
case "", "file": //nolint:goconst
data, err = os.ReadFile(element)
if err != nil {
return fmt.Errorf("failed to read apk key: %w", err)
Expand Down
12 changes: 10 additions & 2 deletions pkg/apk/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ type indexCache struct {
}

func (i *indexCache) get(ctx context.Context, u string, keys map[string][]byte, arch string, opts *indexOpts) (*APKIndex, error) {
if strings.HasPrefix(u, "https://") {
asURL, err := url.Parse(u)
if err != nil {
return nil, fmt.Errorf("failed to parse key as URI: %w", err)
}

switch asURL.Scheme {
case "https":
// We don't want remote indexes to change while we're running.
once, _ := i.onces.LoadOrStore(u, &sync.Once{})
once.(*sync.Once).Do(func() {
Expand All @@ -76,7 +82,7 @@ func (i *indexCache) get(ctx context.Context, u string, keys map[string][]byte,
err: err,
})
})
} else {
case "", "file":
i.Lock()
defer i.Unlock()

Expand All @@ -97,6 +103,8 @@ func (i *indexCache) get(ctx context.Context, u string, keys map[string][]byte,
})
i.modtimes[u] = mod
}
default:
return nil, fmt.Errorf("scheme %s not supported", asURL.Scheme)
}

v, ok := i.indexes.Load(u)
Expand Down

0 comments on commit ff303f2

Please sign in to comment.