From d8d119b0b3a4d557b3c1e1fd6cecb6efc5289901 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 11 Feb 2023 00:31:56 +0000 Subject: [PATCH] Fix Cache Bug (#178) error io.EOF is gracefully end of file read. so we don't need to cancel cache saving Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/178 --- cmd/main.go | 4 ++-- server/gitea/cache.go | 2 +- server/upstream/domains.go | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index af4d2ce..4f0c019 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -44,7 +44,7 @@ func Serve(ctx *cli.Context) error { } log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel) - giteaRoot := strings.TrimSuffix(ctx.String("gitea-root"), "/") + giteaRoot := ctx.String("gitea-root") giteaAPIToken := ctx.String("gitea-api-token") rawDomain := ctx.String("raw-domain") mainDomainSuffix := ctx.String("pages-domain") @@ -68,7 +68,7 @@ func Serve(ctx *cli.Context) error { allowedCorsDomains = append(allowedCorsDomains, rawDomain) } - // Make sure MainDomain has a trailing dot, and GiteaRoot has no trailing slash + // Make sure MainDomain has a trailing dot if !strings.HasPrefix(mainDomainSuffix, ".") { mainDomainSuffix = "." + mainDomainSuffix } diff --git a/server/gitea/cache.go b/server/gitea/cache.go index 85cbcde..af61edf 100644 --- a/server/gitea/cache.go +++ b/server/gitea/cache.go @@ -80,7 +80,7 @@ type writeCacheReader struct { func (t *writeCacheReader) Read(p []byte) (n int, err error) { n, err = t.originalReader.Read(p) - if err != nil { + if err != nil && err != io.EOF { log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey) t.hasError = true } else if n > 0 { diff --git a/server/upstream/domains.go b/server/upstream/domains.go index 5b274b6..bb4b57a 100644 --- a/server/upstream/domains.go +++ b/server/upstream/domains.go @@ -1,6 +1,7 @@ package upstream import ( + "errors" "strings" "time" @@ -30,8 +31,8 @@ func (o *Options) CheckCanonicalDomain(giteaClient *gitea.Client, actualDomain, } body, err := giteaClient.GiteaRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, canonicalDomainConfig) - if err == nil || err == gitea.ErrorNotFound { - log.Info().Err(err).Msgf("could not read %s of %s/%s", canonicalDomainConfig, o.TargetOwner, o.TargetRepo) + if err != nil && !errors.Is(err, gitea.ErrorNotFound) { + log.Error().Err(err).Msgf("could not read %s of %s/%s", canonicalDomainConfig, o.TargetOwner, o.TargetRepo) } var domains []string