From 0da6d6c047b28bd77bbe6992177ff45da5c3e7a5 Mon Sep 17 00:00:00 2001 From: bytedream Date: Sat, 3 May 2025 04:31:29 +0200 Subject: [PATCH] Fix LFS file being editable in web UI --- routers/web/repo/editor.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index c925b6115147a..514eb0ebfe024 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -20,7 +20,6 @@ import ( "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/templates" - "code.gitea.io/gitea/modules/typesniffer" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/routers/utils" @@ -151,9 +150,13 @@ func editFile(ctx *context.Context, isNewFile bool) { return } - dataRc, err := blob.DataAsync() + buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob) if err != nil { - ctx.NotFound(err) + if git.IsErrNotExist(err) { + ctx.NotFound(err) + } else { + ctx.ServerError("getFileReader", err) + } return } @@ -161,12 +164,8 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.Data["FileSize"] = blob.Size() - buf := make([]byte, 1024) - n, _ := util.ReadAtMost(dataRc, buf) - buf = buf[:n] - // Only some file types are editable online as text. - if !typesniffer.DetectContentType(buf).IsRepresentableAsText() { + if !fInfo.isTextFile || fInfo.isLFSFile { ctx.NotFound(nil) return }