Skip to content

Commit bd02218

Browse files
committed
use blobOrLfsSize instead of fileSize
1 parent f23beb0 commit bd02218

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

routers/web/repo/editor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,14 @@ func EditFile(ctx *context.Context) {
295295
}
296296
defer dataRc.Close()
297297

298-
ctx.Data["FileSize"] = fInfo.fileSize
298+
ctx.Data["FileSize"] = fInfo.blobOrLfsSize
299299

300300
// Only some file types are editable online as text.
301301
if fInfo.isLFSFile() {
302302
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
303303
} else if !fInfo.st.IsRepresentableAsText() {
304304
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
305-
} else if fInfo.fileSize >= setting.UI.MaxDisplayFileSize {
305+
} else if fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize {
306306
ctx.Data["NotEditableReason"] = ctx.Tr("repo.editor.cannot_edit_too_large_file")
307307
}
308308

routers/web/repo/view.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ const (
6060
)
6161

6262
type fileInfo struct {
63-
fileSize int64
64-
lfsMeta *lfs.Pointer
65-
st typesniffer.SniffedType
63+
blobOrLfsSize int64
64+
lfsMeta *lfs.Pointer
65+
st typesniffer.SniffedType
6666
}
6767

6868
func (fi *fileInfo) isLFSFile() bool {
@@ -81,7 +81,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) (buf []b
8181
n, _ := util.ReadAtMost(dataRc, buf)
8282
buf = buf[:n]
8383

84-
fi = &fileInfo{fileSize: blob.Size(), st: typesniffer.DetectContentType(buf)}
84+
fi = &fileInfo{blobOrLfsSize: blob.Size(), st: typesniffer.DetectContentType(buf)}
8585

8686
// FIXME: what happens when README file is an image?
8787
if !fi.st.IsText() || !setting.LFS.StartServer {
@@ -114,7 +114,7 @@ func getFileReader(ctx gocontext.Context, repoID int64, blob *git.Blob) (buf []b
114114
}
115115
buf = buf[:n]
116116
fi.st = typesniffer.DetectContentType(buf)
117-
fi.fileSize = meta.Pointer.Size
117+
fi.blobOrLfsSize = meta.Pointer.Size
118118
fi.lfsMeta = &meta.Pointer
119119
return buf, dataRc, fi, nil
120120
}

routers/web/repo/view_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
226226
}
227227

228228
ctx.Data["IsLFSFile"] = fInfo.isLFSFile()
229-
ctx.Data["FileSize"] = fInfo.fileSize
229+
ctx.Data["FileSize"] = fInfo.blobOrLfsSize
230230
ctx.Data["IsRepresentableAsText"] = fInfo.st.IsRepresentableAsText()
231231
ctx.Data["IsExecutable"] = entry.IsExecutable()
232232
ctx.Data["CanCopyContent"] = fInfo.st.IsRepresentableAsText() || fInfo.st.IsImage()
@@ -243,7 +243,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
243243

244244
utf8Reader := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
245245
switch {
246-
case fInfo.fileSize >= setting.UI.MaxDisplayFileSize:
246+
case fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize:
247247
ctx.Data["IsFileTooLarge"] = true
248248
case handleFileViewRenderMarkup(ctx, entry.Name(), fInfo.st, buf, utf8Reader):
249249
// it also sets ctx.Data["FileContent"] and more

routers/web/repo/view_readme.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
170170

171171
ctx.Data["FileIsText"] = fInfo.st.IsText()
172172
ctx.Data["FileTreePath"] = readmeFullPath
173-
ctx.Data["FileSize"] = fInfo.fileSize
173+
ctx.Data["FileSize"] = fInfo.blobOrLfsSize
174174
ctx.Data["IsLFSFile"] = fInfo.isLFSFile()
175175

176176
if fInfo.isLFSFile() {
@@ -182,7 +182,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
182182
return
183183
}
184184

185-
if fInfo.fileSize >= setting.UI.MaxDisplayFileSize {
185+
if fInfo.blobOrLfsSize >= setting.UI.MaxDisplayFileSize {
186186
// Pretend that this is a normal text file to display 'This file is too large to be shown'
187187
ctx.Data["IsFileTooLarge"] = true
188188
return

0 commit comments

Comments
 (0)