Skip to content

Commit b3f5196

Browse files
GiteaBotbytedream
andauthored
Fix LFS files being editable in web UI (#34356) (#34362)
Backport #34356 by @bytedream It's possible to edit "raw" lfs files in the web UI when accessing the path manually. ![image](https://github.com/user-attachments/assets/62610e9e-24db-45ec-ad04-28062073164c) Co-authored-by: bytedream <[email protected]>
1 parent 6c5f0af commit b3f5196

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

routers/web/repo/editor.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"code.gitea.io/gitea/modules/markup"
2121
"code.gitea.io/gitea/modules/setting"
2222
"code.gitea.io/gitea/modules/templates"
23-
"code.gitea.io/gitea/modules/typesniffer"
2423
"code.gitea.io/gitea/modules/util"
2524
"code.gitea.io/gitea/modules/web"
2625
"code.gitea.io/gitea/routers/utils"
@@ -151,22 +150,22 @@ func editFile(ctx *context.Context, isNewFile bool) {
151150
return
152151
}
153152

154-
dataRc, err := blob.DataAsync()
153+
buf, dataRc, fInfo, err := getFileReader(ctx, ctx.Repo.Repository.ID, blob)
155154
if err != nil {
156-
ctx.NotFound(err)
155+
if git.IsErrNotExist(err) {
156+
ctx.NotFound(err)
157+
} else {
158+
ctx.ServerError("getFileReader", err)
159+
}
157160
return
158161
}
159162

160163
defer dataRc.Close()
161164

162165
ctx.Data["FileSize"] = blob.Size()
163166

164-
buf := make([]byte, 1024)
165-
n, _ := util.ReadAtMost(dataRc, buf)
166-
buf = buf[:n]
167-
168167
// Only some file types are editable online as text.
169-
if !typesniffer.DetectContentType(buf).IsRepresentableAsText() {
168+
if !fInfo.isTextFile || fInfo.isLFSFile {
170169
ctx.NotFound(nil)
171170
return
172171
}

0 commit comments

Comments
 (0)