Read blob sizes only for selected validation inputs
This commit is contained in:
@@ -1,21 +1,31 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/git"
|
||||
)
|
||||
|
||||
const defaultFileSizeLimit int64 = 1_000_000
|
||||
|
||||
func checkFileSize(tree *CandidateTree, settings *FileSizeSettings) error {
|
||||
func checkFileSize(ctx context.Context, tree *CandidateTree, settings *FileSizeSettings) error {
|
||||
entries := make([]git.TreeEntry, 0, len(tree.inputEntries))
|
||||
for _, entry := range tree.inputEntries {
|
||||
if entry.Type == "blob" && !excludedByPath(entry.Path, settings.Exclusions) {
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
}
|
||||
if err := git.PopulateBlobSizes(ctx, tree.repositoryDir, entries); err != nil {
|
||||
return &Failure{Check: FileSize, Cause: fmt.Errorf("inspect selected committed file sizes: %w", err)}
|
||||
}
|
||||
limit := defaultFileSizeLimit
|
||||
if settings.LimitBytes != nil {
|
||||
limit = *settings.LimitBytes
|
||||
}
|
||||
for _, entry := range tree.inputEntries {
|
||||
if entry.Type != "blob" || !entry.HasSize || excludedByPath(entry.Path, settings.Exclusions) {
|
||||
continue
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.Size > limit {
|
||||
return &Failure{
|
||||
Check: FileSize,
|
||||
|
||||
Reference in New Issue
Block a user