From 1ce155c5a695f07a9252b4ffc8c9ae7d48ebf7ec Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 7 Dec 2023 06:06:51 +0800 Subject: [PATCH] Fix object does not exist error when checking citation file (#28314) (#28369) Backport #28314 by @yp05327 Fix #28264 `DataAsync()` will be called twice. Caused by https://github.com/go-gitea/gitea/pull/27958. I'm sorry, I didn't completely remove all unnecessary codes. Co-authored-by: yp05327 <576951401@qq.com> (cherry picked from commit c5c44d095114901af745ef6a24f827c4cfe73ec4) --- routers/web/repo/view.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 5734a4e5fc..e2518f5dd7 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -702,21 +702,14 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { } for _, entry := range allEntries { if entry.Name() == "CITATION.cff" || entry.Name() == "CITATION.bib" { - ctx.Data["CitiationExist"] = true // Read Citation file contents - blob := entry.Blob() - dataRc, err := blob.DataAsync() - if err != nil { - ctx.ServerError("DataAsync", err) - return + if content, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil { + log.Error("checkCitationFile: GetBlobContent: %v", err) + } else { + ctx.Data["CitiationExist"] = true + ctx.PageData["citationFileContent"] = content + break } - defer dataRc.Close() - ctx.PageData["citationFileContent"], err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize) - if err != nil { - ctx.ServerError("GetBlobContent", err) - return - } - break } } }