added more error checking, log to journal

This commit is contained in:
Giovanni Harting 2021-06-12 17:57:32 +02:00
parent d474df0590
commit b6dd6f5947
3 changed files with 21 additions and 5 deletions

2
go.mod
View File

@ -5,7 +5,9 @@ go 1.16
require (
github.com/Jguer/go-alpm/v2 v2.0.5
github.com/Morganamilo/go-srcinfo v1.0.0
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/sirupsen/logrus v1.8.1
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3
github.com/yargevad/filepathx v1.0.0
gopkg.in/yaml.v2 v2.4.0
)

4
go.sum
View File

@ -2,6 +2,8 @@ github.com/Jguer/go-alpm/v2 v2.0.5 h1:1TZxkvCIfTOhjhxGy/Z1FNSeuY9DXBKF5qxUoj0IZ0
github.com/Jguer/go-alpm/v2 v2.0.5/go.mod h1:zU4iKCtNkDARfj5BrKJXYAQ5nIjtZbySfa0paboSmTQ=
github.com/Morganamilo/go-srcinfo v1.0.0 h1:Wh4nEF+HJWo+29hnxM18Q2hi+DUf0GejS13+Wg+dzmI=
github.com/Morganamilo/go-srcinfo v1.0.0/go.mod h1:MP6VGY1NNpVUmYIEgoM9acix95KQqIRyqQ0hCLsyYUY=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -10,6 +12,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3 h1:shC1HB1UogxN5Ech3Yqaaxj1X/P656PPCB4RbojIJqc=
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=

20
main.go
View File

@ -7,6 +7,7 @@ import (
"github.com/Jguer/go-alpm/v2"
"github.com/Morganamilo/go-srcinfo"
log "github.com/sirupsen/logrus"
"github.com/wercker/journalhook"
"github.com/yargevad/filepathx"
"gopkg.in/yaml.v2"
"io"
@ -112,13 +113,17 @@ func copyFile(src, dst string) (int64, error) {
if err != nil {
return 0, err
}
defer source.Close()
defer func(source *os.File) {
check(source.Close())
}(source)
destination, err := os.Create(dst)
if err != nil {
return 0, err
}
defer destination.Close()
defer func(destination *os.File) {
check(destination.Close())
}(destination)
nBytes, err := io.Copy(destination, source)
return nBytes, err
}
@ -195,7 +200,9 @@ func importKeys(pkg *BuildPackage) {
func increasePkgRel(pkg *BuildPackage) {
f, err := os.OpenFile(pkg.Pkgbuild, os.O_RDWR, os.ModePerm)
check(err)
defer f.Close()
defer func(f *os.File) {
check(f.Close())
}(f)
fStr, err := io.ReadAll(f)
check(err)
@ -258,7 +265,7 @@ func (b *BuildManager) buildWorker(id int) {
_, err := f.WriteString(fmt.Sprintf("%s==%s-%s\n", pkg.Pkgbase, pkg.Srcinfo.Pkgver, pkg.Srcinfo.Pkgrel))
check(err)
}
f.Close()
check(f.Close())
b.failedMutex.Unlock()
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, "logs"), os.ModePerm))
@ -410,7 +417,9 @@ func isPkgFailed(pkg *BuildPackage) bool {
file, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, pkg.FullRepo+"_failed.txt"), os.O_RDWR|os.O_CREATE, os.ModePerm)
check(err)
defer file.Close()
defer func(file *os.File) {
check(file.Close())
}(file)
failed := false
var newContent []string
@ -609,6 +618,7 @@ func main() {
lvl, err := log.ParseLevel(conf.Logging.Level)
check(err)
log.SetLevel(lvl)
journalhook.Enable()
err = os.MkdirAll(conf.Basedir.Repo, os.ModePerm)
check(err)