Skip to content

Commit

Permalink
Added error
Browse files Browse the repository at this point in the history
  • Loading branch information
raspi committed Aug 3, 2020
1 parent 22b13a3 commit f828aaf
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package PKGBUILD
import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"net/url"
"path"
"regexp"
"strings"
Expand Down Expand Up @@ -105,18 +107,18 @@ func GetLinesFromFile(path string) (lines []string, err error) {
// How architecture can be found from file name
var DefaultArchRegEx = regexp.MustCompile(`linux-([^\.]+)\.`)

func (t Template) DefaultChecksumFilesFunc(fpath string) (url, arch, alias string) {
func (t Template) DefaultChecksumFilesFunc(fpath string) (urlAddress, arch, alias string, err error) {
fpath = strings.TrimLeft(fpath, `.`)
fpath = strings.TrimLeft(fpath, `/`)
filename := path.Base(fpath)

if !strings.Contains(filename, `linux`) {
return ``, ``, ``
return ``, ``, ``, fmt.Errorf(`'linux' was not found in filename`)
}

match := DefaultArchRegEx.FindStringSubmatch(filename)
if len(match) == 0 {
return ``, ``, ``
return ``, ``, ``, fmt.Errorf(`filename %#s was not found in %v`, filename, DefaultArchRegEx)
}

filename = strings.Replace(filename, t.Name[0], `$pkgname`, 1)
Expand All @@ -128,9 +130,15 @@ func (t Template) DefaultChecksumFilesFunc(fpath string) (url, arch, alias strin

arch, ok := GoArchToLinuxArch[match[1]]
if !ok {
return ``, ``, ``
return ``, ``, ``, fmt.Errorf(`arch %#s was not found`, match[1])
}

url = path.Join(t.PackageURLPrefix, filename)
return url, arch, alias
u, err := url.Parse(t.PackageURLPrefix)
if err != nil {
return ``, ``, ``, fmt.Errorf(`couldn't parse url: %w`, err)
}

u.Path = path.Join(u.Path, filename)
urlAddress = u.String()
return urlAddress, arch, alias, nil
}

0 comments on commit f828aaf

Please sign in to comment.