]> source.dussan.org Git - gitea.git/commitdiff
Fix object does not exist error when checking citation file (#28314)
authoryp05327 <576951401@qq.com>
Wed, 6 Dec 2023 08:51:01 +0000 (17:51 +0900)
committerGitHub <noreply@github.com>
Wed, 6 Dec 2023 08:51:01 +0000 (16:51 +0800)
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.

routers/web/repo/view.go

index ba2ac3af115e413963c0bf769ccff255204727c9..70556185bb53bed1f204bac5ba56194c288ba3a9 100644 (file)
@@ -711,21 +711,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
-                       }
-                       defer dataRc.Close()
-                       ctx.PageData["citationFileContent"], err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
-                       if err != nil {
-                               ctx.ServerError("GetBlobContent", 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
                        }
-                       break
                }
        }
 }