Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
30 lines
686 B
Go
30 lines
686 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package packages
|
|
|
|
import (
|
|
"io"
|
|
|
|
"gotea.dev/modules/util"
|
|
)
|
|
|
|
var ErrContentTooLarge = util.NewInvalidArgumentErrorf("content exceeds the size limit")
|
|
|
|
type limitedReader struct {
|
|
io.LimitedReader
|
|
}
|
|
|
|
// NewLimitedReader returns a reader that fails with ErrContentTooLarge once it reads a byte past limit
|
|
func NewLimitedReader(r io.Reader, limit int64) io.Reader {
|
|
return &limitedReader{io.LimitedReader{R: r, N: limit + 1}}
|
|
}
|
|
|
|
func (l *limitedReader) Read(p []byte) (int, error) {
|
|
n, err := l.LimitedReader.Read(p)
|
|
if l.N == 0 {
|
|
return max(n-1, 0), ErrContentTooLarge
|
|
}
|
|
return n, err
|
|
}
|