mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-01-26 11:34:03 +00:00
* chore(ci): update go to 1.25, add permissions and envs * fix(ci): update pr-lint.yml * chore: update go, fix linting * fix: tests and linting * fix(lint): lint fixes, renovate should now pass * fix: updates, security upgrades * chore: workflow updates, lint * fix: more lint, checkmake, and other fixes * fix: more lint, convert scripts to POSIX compliant * fix: simplify codeql workflow * tests: increase test coverage, fix found issues * fix(lint): editorconfig checking, add to linters * fix(lint): shellcheck, add to linters * fix(lint): apply cr comment suggestions * fix(ci): remove step-security/harden-runner * fix(lint): remove duplication, apply cr fixes * fix(ci): tests in CI/CD pipeline * chore(lint): deduplication of strings * fix(lint): apply cr comment suggestions * fix(ci): actionlint * fix(lint): apply cr comment suggestions * chore: lint, add deps management
87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/ivuorinen/gibidify/config"
|
|
"github.com/ivuorinen/gibidify/fileproc"
|
|
"github.com/ivuorinen/gibidify/gibidiutils"
|
|
)
|
|
|
|
// collectFiles collects all files to be processed.
|
|
func (p *Processor) collectFiles() ([]string, error) {
|
|
files, err := fileproc.CollectFiles(p.flags.SourceDir)
|
|
if err != nil {
|
|
return nil, gibidiutils.WrapError(
|
|
err,
|
|
gibidiutils.ErrorTypeProcessing,
|
|
gibidiutils.CodeProcessingCollection,
|
|
"error collecting files",
|
|
)
|
|
}
|
|
logrus.Infof("Found %d files to process", len(files))
|
|
return files, nil
|
|
}
|
|
|
|
// validateFileCollection validates the collected files against resource limits.
|
|
func (p *Processor) validateFileCollection(files []string) error {
|
|
if !config.GetResourceLimitsEnabled() {
|
|
return nil
|
|
}
|
|
|
|
// Check file count limit
|
|
maxFiles := config.GetMaxFiles()
|
|
if len(files) > maxFiles {
|
|
return gibidiutils.NewStructuredError(
|
|
gibidiutils.ErrorTypeValidation,
|
|
gibidiutils.CodeResourceLimitFiles,
|
|
fmt.Sprintf("file count (%d) exceeds maximum limit (%d)", len(files), maxFiles),
|
|
"",
|
|
map[string]interface{}{
|
|
"file_count": len(files),
|
|
"max_files": maxFiles,
|
|
},
|
|
)
|
|
}
|
|
|
|
// Check total size limit (estimate)
|
|
maxTotalSize := config.GetMaxTotalSize()
|
|
totalSize := int64(0)
|
|
oversizedFiles := 0
|
|
|
|
for _, filePath := range files {
|
|
if fileInfo, err := os.Stat(filePath); err == nil {
|
|
totalSize += fileInfo.Size()
|
|
if totalSize > maxTotalSize {
|
|
return gibidiutils.NewStructuredError(
|
|
gibidiutils.ErrorTypeValidation,
|
|
gibidiutils.CodeResourceLimitTotalSize,
|
|
fmt.Sprintf(
|
|
"total file size (%d bytes) would exceed maximum limit (%d bytes)",
|
|
totalSize,
|
|
maxTotalSize,
|
|
),
|
|
"",
|
|
map[string]interface{}{
|
|
"total_size": totalSize,
|
|
"max_total_size": maxTotalSize,
|
|
"files_checked": len(files),
|
|
},
|
|
)
|
|
}
|
|
} else {
|
|
oversizedFiles++
|
|
}
|
|
}
|
|
|
|
if oversizedFiles > 0 {
|
|
logrus.Warnf("Could not stat %d files during pre-validation", oversizedFiles)
|
|
}
|
|
|
|
logrus.Infof("Pre-validation passed: %d files, %d MB total", len(files), totalSize/1024/1024)
|
|
return nil
|
|
}
|