Add maxsize directive to skip oversized files when scanning - #45
Open
techjoec wants to merge 1 commit into
Open
Conversation
qgrep has no notion of text vs binary: buildAppendFile() opens every file "rb" and indexes the raw bytes. On a corpus that mixes source with firmware images, disk dumps and compressed archives, a single stray include pattern can pull gigabytes of incompressible data into the database, and there is no way to express "index this tree, but not the multi-gigabyte blobs in it" -- the cfg grammar filters on path regex alone. maxsize fills that gap. traverseDirectory already hands the callback a size, so the check costs nothing extra; explicit `file` entries are filtered against the same limit after getFileAttributes. Semantics follow the existing include/exclude directives: it applies to its group and is inherited by nested groups unless overridden, so a root limit can be relaxed or tightened per subtree. 0 (or absent) means unlimited, preserving existing behaviour for every project that does not use it. Sizes accept a plain byte count or a K/M/G suffix, with an optional trailing B (16M, 512K, 1024, 1MB). Malformed values throw during parse and are reported with the usual file(line) prefix rather than being silently ignored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
qgrep has no notion of text vs binary —
buildAppendFile()opens every file"rb"and indexes the raw bytes. That is a reasonable design, but it means the only lever for keeping huge files out of a database is the include/exclude path regexes, and those cannot express "this tree, but not the multi-gigabyte artifacts in it".I hit this on a corpus that mixes source with firmware images, disk dumps and compressed archives in the same directories. Extension patterns get you most of the way, but any tree where a large blob shares an extension with source (or has none) pulls that blob into the index byte-for-byte, and the only workaround is to generate an explicit file list outside qgrep and feed it in as a project — which then has to be regenerated whenever the tree changes.
What this adds
A
maxsizedirective for project files:K/M/Gsuffix, with an optional trailingB(16M,512K,1024,1MB).include/exclude, so a root limit can be relaxed or tightened per subtree.0or absent means unlimited, so behaviour is unchanged for every existing project.file(line):prefix rather than being silently ignored.Implementation notes
traverseDirectory()already hands its callback the file size, so the check ingetProjectGroupFilesRec()costs nothing extra. Explicitfileentries are filtered against the same limit aftergetFileAttributes().Also adds
#include <stdlib.h>toproject.cppforstrtoull— it was previously reaching it transitively;main.cppincludes it explicitly for its ownstrtoul, so this follows the existing convention and avoids depending on a transitive include on MSVC.Testing
Built with
make(gcc,-Wall -Werror, clean). Verified manually:maxsize 1M/100Kon a tree of small/medium/large files → only files at or under the limit indexedmaxsize 1Mwith a nested group overriding to100K→ each group honours its own limit1048576,1024K,1M,1m,1MBall equivalentabc/10X→ parse errors with file and lineHappy to adjust the name, the suffix handling, or the inheritance semantics if you'd prefer something different.
🤖 Generated with Claude Code