mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-12 19:18:24 +02:00
Fix a bug with handling --ignore-file.
Namely, passing a directory to --ignore-file caused ripgrep to allocate memory without bound. The issue was that I got a bit overzealous with partial error reporting. Namely, when processing a gitignore file, we should try to use every pattern even if some patterns are invalid globs (e.g., a**b). In the process, I applied the same logic to I/O errors. In this case, it manifest by attempting to read lines from a directory, which appears to yield Results forever, where each Result is an error of the form "you can't read from a directory silly." Since I treated it as a partial error, ripgrep was just spinning and accruing each error in memory, which caused the OOM killer to kick in. Fixes #228
This commit is contained in:
parent
2e5c3c05e8
commit
2dce0dc0df
@ -311,7 +311,7 @@ impl GitignoreBuilder {
|
|||||||
Ok(line) => line,
|
Ok(line) => line,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
errs.push(Error::Io(err).tagged(path, lineno));
|
errs.push(Error::Io(err).tagged(path, lineno));
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(err) = self.add_line(Some(path.to_path_buf()), &line) {
|
if let Err(err) = self.add_line(Some(path.to_path_buf()), &line) {
|
||||||
|
@ -451,7 +451,7 @@ impl WalkBuilder {
|
|||||||
pub fn add_ignore<P: AsRef<Path>>(&mut self, path: P) -> Option<Error> {
|
pub fn add_ignore<P: AsRef<Path>>(&mut self, path: P) -> Option<Error> {
|
||||||
let mut builder = GitignoreBuilder::new("");
|
let mut builder = GitignoreBuilder::new("");
|
||||||
let mut errs = PartialErrorBuilder::default();
|
let mut errs = PartialErrorBuilder::default();
|
||||||
errs.maybe_push_ignore_io(builder.add(path));
|
errs.maybe_push(builder.add(path));
|
||||||
match builder.build() {
|
match builder.build() {
|
||||||
Ok(gi) => { self.ig_builder.add_ignore(gi); }
|
Ok(gi) => { self.ig_builder.add_ignore(gi); }
|
||||||
Err(err) => { errs.push(err); }
|
Err(err) => { errs.push(err); }
|
||||||
|
@ -893,6 +893,13 @@ clean!(regression_206, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
assert_eq!(lines, format!("{}:test\n", path("foo/bar.txt")));
|
assert_eq!(lines, format!("{}:test\n", path("foo/bar.txt")));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// See: https://github.com/BurntSushi/ripgrep/issues/228
|
||||||
|
clean!(regression_228, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
||||||
|
wd.create_dir("foo");
|
||||||
|
cmd.arg("--ignore-file").arg("foo");
|
||||||
|
wd.assert_err(&mut cmd);
|
||||||
|
});
|
||||||
|
|
||||||
// See: https://github.com/BurntSushi/ripgrep/issues/20
|
// See: https://github.com/BurntSushi/ripgrep/issues/20
|
||||||
sherlock!(feature_20_no_filename, "Sherlock", ".",
|
sherlock!(feature_20_no_filename, "Sherlock", ".",
|
||||||
|wd: WorkDir, mut cmd: Command| {
|
|wd: WorkDir, mut cmd: Command| {
|
||||||
|
Loading…
Reference in New Issue
Block a user