Skip to content

Commit

Permalink
Update manifest.go
Browse files Browse the repository at this point in the history
Address PR comments:
* Elimintate isValidURL, just use net/url's Parse()
* Do not wrap error for the sake of wrapping the error.

Co-authored-by: Philip Potter <[email protected]>
  • Loading branch information
tempusfrangit and philandstuff committed Feb 21, 2024
1 parent 74d8b80 commit 51d0799
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions cmd/multifile/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,41 @@ func parseManifest(file io.Reader) (pget.Manifest, error) {
if line == "" {
continue
}
urlString, dest, err := parseLine(line)
url, dest, err := parseLine(line)
if err != nil {
return nil, err
}

if _, err := netUrl.Parse(url); err != nil {
return nil, err

}

// THIS IS A BODGE - FIX ME MOVE THESE THINGS TO PGET
// and make the consumer responsible for knowing if this
// is allowed/not allowed/etc
consumer := viper.GetString(config.OptOutputConsumer)
if consumer != config.ConsumerNull {
err = checkSeenDestinations(seenDestinations, dest, urlString)
err = checkSeenDestinations(seenDestinations, dest, url)
if err != nil {
if errors.Is(err, errDupeURLDestCombo) {
logger.Warn().
Str("url", urlString).
Str("url", url).
Str("destination", dest).
Msg("Parse Manifest: Skip Duplicate URL/Destination")
continue
}
return nil, err
}
seenDestinations[dest] = urlString
seenDestinations[dest] = url

err = cli.EnsureDestinationNotExist(dest)
if err != nil {
return nil, err
}
}
if valid, err := validURL(urlString); !valid {
return nil, fmt.Errorf("error parsing manifest invalid URL: %s: %w", urlString, err)

}
manifest = manifest.AddEntry(urlString, dest)
manifest = manifest.AddEntry(url, dest)
}

return manifest, nil
}

func validURL(s string) (bool, error) {
_, err := netUrl.Parse(s)
return err == nil, err
}

0 comments on commit 51d0799

Please sign in to comment.