Skip to main content

slopguard_core/
scanner.rs

1use std::collections::HashMap;
2use std::fs::{self, read_to_string};
3use std::path::{Path, PathBuf};
4
5use ast_grep_config::{
6    CombinedScan, GlobalRules, RuleCollection, RuleConfig, RuleConfigError, SerializableRuleConfig,
7};
8use ast_grep_core::tree_sitter::LanguageExt;
9use ast_grep_core::Language as AstLanguage;
10use ast_grep_language::SupportLang;
11use globset::{Error as GlobError, Glob, GlobSet, GlobSetBuilder};
12use ignore::WalkBuilder;
13use rayon::prelude::*;
14use serde::Serialize;
15use serde_yaml::with::singleton_map_recursive;
16use serde_yaml::{to_value, Value};
17use strum::IntoEnumIterator;
18use thiserror::Error;
19
20use crate::cache::{file_content_hash, rules_hash, CacheStore};
21use crate::config::Config;
22use crate::disable::filter_disabled;
23use crate::finding::{CacheStats, Finding, ScanResult, ScanStats};
24use crate::rule::{Language, Rule, RuleId, Severity};
25use crate::test_filter::CfgTestRanges;
26
27#[derive(Debug, Error)]
28pub enum ScanError {
29    #[error("failed to compile rule '{id}': {source}")]
30    RuleCompile {
31        id: RuleId,
32        #[source]
33        source: RuleConfigError,
34    },
35
36    #[error("invalid glob pattern: {0}")]
37    Glob(#[from] GlobError),
38}
39
40/// The subset of a slopguard rule that ast-grep understands. slopguard-only
41/// fields (`category`, `fix` as free text, `tests`) are deliberately left out.
42#[derive(Serialize)]
43pub struct AstGrepRule<'a> {
44    pub id: &'a str,
45    pub language: SupportLang,
46    pub severity: &'a Severity,
47    pub message: &'a str,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub note: Option<&'a str>,
50    pub rule: &'a Value,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub files: Option<&'a [String]>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub ignores: Option<&'a [String]>,
55}
56
57/// Rules compiled for scanning, plus a way back to the slopguard rule that
58/// produced each ast-grep config.
59struct CompiledRules<'a> {
60    collection: RuleCollection<SupportLang>,
61    by_id: HashMap<(&'a str, Language), &'a Rule>,
62}
63
64fn extension_to_lang(path: &Path) -> Option<SupportLang> {
65    SupportLang::from_path(path)
66        .filter(|lang| Language::iter().any(|l| l.ast_grep_langs().contains(lang)))
67}
68
69fn support_lang_to_language(lang: SupportLang) -> Language {
70    match lang {
71        SupportLang::Rust => Language::Rust,
72        _ => Language::TypeScript,
73    }
74}
75
76pub(crate) fn compile_ast_grep_rule(
77    rule: &AstGrepRule,
78) -> Result<RuleConfig<SupportLang>, RuleConfigError> {
79    let inner: SerializableRuleConfig<SupportLang> = to_value(rule)
80        .and_then(singleton_map_recursive::deserialize)
81        .map_err(RuleConfigError::from)?;
82    RuleConfig::try_from(inner, &GlobalRules::default())
83}
84
85fn compile_rule(rule: &Rule, lang: SupportLang) -> Result<RuleConfig<SupportLang>, ScanError> {
86    let ast_grep_rule = AstGrepRule {
87        id: rule.id.as_str(),
88        language: lang,
89        severity: &rule.severity,
90        message: &rule.message,
91        note: rule.note.as_deref(),
92        rule: &rule.rule,
93        files: rule.files.as_deref(),
94        ignores: rule.ignores.as_deref(),
95    };
96    compile_ast_grep_rule(&ast_grep_rule).map_err(|source| ScanError::RuleCompile {
97        id: rule.id.clone(),
98        source,
99    })
100}
101
102fn compile_rules(rules: &[Rule]) -> Result<CompiledRules<'_>, ScanError> {
103    let configs = rules
104        .iter()
105        .flat_map(|rule| {
106            rule.language
107                .ast_grep_langs()
108                .iter()
109                .map(move |lang| compile_rule(rule, *lang))
110        })
111        .collect::<Result<Vec<_>, _>>()?;
112    Ok(CompiledRules {
113        collection: RuleCollection::try_new(configs)?,
114        by_id: rules
115            .iter()
116            .map(|rule| ((rule.id.as_str(), rule.language.clone()), rule))
117            .collect::<HashMap<_, _>>(),
118    })
119}
120
121fn build_glob_set(patterns: &[String]) -> Result<GlobSet, GlobError> {
122    let mut builder = GlobSetBuilder::new();
123    for pattern in patterns {
124        builder.add(Glob::new(pattern)?);
125    }
126    builder.build()
127}
128
129fn scan_file(path: &Path, lang: SupportLang, rules: &CompiledRules) -> Vec<Finding> {
130    let applicable = rules.collection.get_rule_from_lang(path, lang);
131    if applicable.is_empty() {
132        return Vec::new();
133    }
134    let Ok(source) = read_to_string(path) else {
135        return Vec::new();
136    };
137
138    let root = lang.ast_grep(&source);
139    let combined = CombinedScan::new(applicable);
140    let result = combined.scan(&root, false);
141
142    let cfg_test = (lang == SupportLang::Rust && !result.matches.is_empty())
143        .then(|| CfgTestRanges::from_root(&root));
144    let cfg_test = cfg_test.as_ref();
145
146    let findings = result
147        .matches
148        .into_iter()
149        .filter_map(|(config, matches)| {
150            let rule_lang = support_lang_to_language(lang);
151            let rule = rules.by_id.get(&(config.id.as_str(), rule_lang))?;
152            Some((*rule, matches))
153        })
154        .flat_map(|(rule, matches)| {
155            let skip_test_code = rule.skip_test_code;
156            matches
157                .into_iter()
158                .map(move |node_match| {
159                    let start = node_match.start_pos();
160                    let end = node_match.end_pos();
161                    Finding {
162                        rule_id: rule.id.clone(),
163                        severity: rule.severity.clone(),
164                        category: rule.category.clone().unwrap_or_default(),
165                        message: rule.message.clone(),
166                        note: rule.note.clone(),
167                        fix: rule.fix.clone(),
168                        file: path.to_path_buf(),
169                        line: start.line() + 1,
170                        column: start.byte_point().1 + 1,
171                        end_line: end.line() + 1,
172                        end_column: end.byte_point().1 + 1,
173                        matched_text: node_match.text().to_string(),
174                    }
175                })
176                .filter(move |f| {
177                    !(skip_test_code && cfg_test.is_some_and(|r| r.contains_line(f.line)))
178                })
179        })
180        .collect();
181
182    filter_disabled(findings, &source)
183}
184
185/// Scan the given paths for rule violations.
186pub fn scan(paths: &[PathBuf], rules: &[Rule], config: &Config) -> Result<ScanResult, ScanError> {
187    let compiled = compile_rules(rules)?;
188    let ignores = build_glob_set(&config.scan.ignores)?;
189
190    let files: Vec<(PathBuf, SupportLang)> = paths
191        .iter()
192        .flat_map(|path| WalkBuilder::new(path).build().flatten())
193        .filter(|entry| entry.file_type().is_some_and(|t| t.is_file()))
194        .map(|entry| entry.into_path())
195        .filter(|path| !ignores.is_match(path))
196        .filter_map(|path| extension_to_lang(&path).map(|lang| (path, lang)))
197        .collect();
198
199    let mut findings: Vec<Finding> = files
200        .par_iter()
201        .flat_map_iter(|(path, lang)| scan_file(path, *lang, &compiled))
202        .collect();
203    findings.sort_by(|a, b| (&a.file, a.line, a.column).cmp(&(&b.file, b.line, b.column)));
204    findings.dedup_by(|a, b| {
205        a.rule_id == b.rule_id && a.file == b.file && a.line == b.line && a.column == b.column
206    });
207
208    let (errors, warnings) =
209        findings
210            .iter()
211            .fold((0, 0), |(errors, warnings), f| match f.severity {
212                Severity::Error => (errors + 1, warnings),
213                Severity::Warning => (errors, warnings + 1),
214            });
215
216    Ok(ScanResult {
217        findings,
218        stats: ScanStats {
219            errors,
220            warnings,
221            total: errors + warnings,
222            files_scanned: files.len(),
223        },
224        cache_stats: None,
225    })
226}
227
228/// Scan with file-level caching. Files whose content hash matches a cached
229/// entry (and whose rules have not changed) return cached findings without
230/// reparsing.
231///
232/// `cache_dir` is the directory where cache files are stored. When a custom
233/// cache directory is specified (via `--cache-dir`, `SLOPGUARD_CACHE_DIR`,
234/// or `scan.cache_dir` in config), pass it directly. Otherwise pass the
235/// project root and use `CacheStore::new` which appends `.slopguard-cache`.
236pub fn scan_cached(
237    paths: &[PathBuf],
238    rules: &[Rule],
239    config: &Config,
240    cache_dir: &Path,
241) -> Result<ScanResult, ScanError> {
242    let compiled = compile_rules(rules)?;
243    let ignores = build_glob_set(&config.scan.ignores)?;
244
245    let files: Vec<(PathBuf, SupportLang)> = paths
246        .iter()
247        .flat_map(|path| WalkBuilder::new(path).build().flatten())
248        .filter(|entry| entry.file_type().is_some_and(|t| t.is_file()))
249        .map(|entry| entry.into_path())
250        .filter(|path| !ignores.is_match(path))
251        .filter_map(|path| extension_to_lang(&path).map(|lang| (path, lang)))
252        .collect();
253
254    let store = CacheStore::with_dir(cache_dir.to_path_buf());
255    let current_rules_hash = rules_hash(rules);
256    let rules_changed = store
257        .check_rules_changed(&current_rules_hash)
258        .unwrap_or(true);
259
260    let file_contents: Vec<(PathBuf, SupportLang, Vec<u8>, String)> = files
261        .into_iter()
262        .filter_map(|(path, lang)| {
263            let content = fs::read(&path).ok()?;
264            let hash = file_content_hash(&content);
265            Some((path, lang, content, hash))
266        })
267        .collect();
268
269    let mut cached_count = 0usize;
270    let mut changed_count = 0usize;
271    let mut all_findings: Vec<Finding> = Vec::new();
272
273    struct FileWork {
274        path: PathBuf,
275        lang: SupportLang,
276        hash: String,
277    }
278
279    let mut to_scan: Vec<FileWork> = Vec::new();
280
281    for (path, lang, _content, hash) in file_contents.iter() {
282        if !rules_changed {
283            if let Some(cached_findings) = store.get(hash) {
284                cached_count += 1;
285                all_findings.extend(cached_findings);
286                continue;
287            }
288        }
289        changed_count += 1;
290        to_scan.push(FileWork {
291            path: path.clone(),
292            lang: *lang,
293            hash: hash.clone(),
294        });
295    }
296
297    let scanned_findings: Vec<(String, Vec<Finding>)> = to_scan
298        .par_iter()
299        .map(|work| {
300            let findings = scan_file(&work.path, work.lang, &compiled);
301            (work.hash.clone(), findings)
302        })
303        .collect();
304
305    for (hash, findings) in scanned_findings {
306        store.put(&hash, &findings).ok();
307        all_findings.extend(findings);
308    }
309
310    let current_hashes: Vec<String> = file_contents.iter().map(|(_, _, _, h)| h.clone()).collect();
311    store.cleanup(&current_hashes).ok();
312
313    all_findings.sort_by(|a, b| (&a.file, a.line, a.column).cmp(&(&b.file, b.line, b.column)));
314    all_findings.dedup_by(|a, b| {
315        a.rule_id == b.rule_id && a.file == b.file && a.line == b.line && a.column == b.column
316    });
317
318    let (errors, warnings) =
319        all_findings
320            .iter()
321            .fold((0, 0), |(errors, warnings), f| match f.severity {
322                Severity::Error => (errors + 1, warnings),
323                Severity::Warning => (errors, warnings + 1),
324            });
325
326    let files_scanned = cached_count + changed_count;
327
328    Ok(ScanResult {
329        findings: all_findings,
330        stats: ScanStats {
331            errors,
332            warnings,
333            total: errors + warnings,
334            files_scanned,
335        },
336        cache_stats: Some(CacheStats {
337            cached: cached_count,
338            changed: changed_count,
339        }),
340    })
341}
342
343#[cfg(test)]
344mod tests {
345    use std::fs::{create_dir, write};
346
347    use tempfile::tempdir;
348
349    use super::*;
350    use crate::rule::{load_builtin_rules, parse_rule, RuleId};
351
352    fn unwrap_rule() -> Rule {
353        parse_rule(
354            r#"
355id: test-unwrap
356language: rust
357severity: error
358category: correctness
359message: ".unwrap() forbidden"
360rule:
361  kind: call_expression
362  regex: '\.unwrap\(\)\s*$'
363"#,
364        )
365        .unwrap()
366    }
367
368    fn scan_dir(dir: &Path, rules: &[Rule]) -> ScanResult {
369        scan(&[dir.to_path_buf()], rules, &Config::default()).unwrap()
370    }
371
372    #[test]
373    fn scan_finds_unwrap_violation() {
374        let dir = tempdir().unwrap();
375        write(
376            dir.path().join("main.rs"),
377            "fn main() {\n    foo().unwrap();\n}\n",
378        )
379        .unwrap();
380        let result = scan_dir(dir.path(), &[unwrap_rule()]);
381        assert_eq!(result.findings.len(), 1);
382        let f = &result.findings[0];
383        assert_eq!(f.rule_id, RuleId::from("test-unwrap"));
384        assert_eq!(f.severity, Severity::Error);
385        assert_eq!(f.line, 2);
386        assert!(f.matched_text.contains("unwrap()"));
387    }
388
389    #[test]
390    fn scan_clean_file_no_findings() {
391        let dir = tempdir().unwrap();
392        write(dir.path().join("main.rs"), "fn main() { let x = foo(); }\n").unwrap();
393        let result = scan_dir(dir.path(), &[unwrap_rule()]);
394        assert_eq!(result.findings.len(), 0);
395        assert_eq!(result.stats.files_scanned, 1);
396    }
397
398    #[test]
399    fn scan_unsupported_language_ignored() {
400        let dir = tempdir().unwrap();
401        write(dir.path().join("script.py"), "x.unwrap()\n").unwrap();
402        write(dir.path().join("main.rs"), "fn main() {}\n").unwrap();
403        let result = scan_dir(dir.path(), &[unwrap_rule()]);
404        assert_eq!(result.findings.len(), 0);
405        assert_eq!(result.stats.files_scanned, 1);
406    }
407
408    #[test]
409    fn scan_explicit_file_path() {
410        let dir = tempdir().unwrap();
411        let file = dir.path().join("main.rs");
412        write(&file, "fn main() { foo().unwrap(); }\n").unwrap();
413        let result = scan(&[file], &[unwrap_rule()], &Config::default()).unwrap();
414        assert_eq!(result.findings.len(), 1);
415        assert_eq!(result.stats.files_scanned, 1);
416    }
417
418    #[test]
419    fn rule_ignores_glob_respected() {
420        let dir = tempdir().unwrap();
421        let tests_dir = dir.path().join("tests");
422        create_dir(&tests_dir).unwrap();
423        write(
424            tests_dir.join("test_main.rs"),
425            "fn t() { foo().unwrap(); }\n",
426        )
427        .unwrap();
428        write(
429            dir.path().join("main.rs"),
430            "fn main() { foo().unwrap(); }\n",
431        )
432        .unwrap();
433        let rule = parse_rule(
434            r#"
435id: ign
436language: rust
437severity: error
438category: correctness
439message: x
440rule:
441  kind: call_expression
442  regex: '\.unwrap\(\)\s*$'
443ignores:
444  - "**/tests/**"
445"#,
446        )
447        .unwrap();
448        let result = scan_dir(dir.path(), &[rule]);
449        assert_eq!(result.findings.len(), 1);
450        assert!(result.findings[0]
451            .file
452            .to_string_lossy()
453            .contains("main.rs"));
454    }
455
456    #[test]
457    fn config_ignores_respected() {
458        let dir = tempdir().unwrap();
459        let gen = dir.path().join("generated");
460        create_dir(&gen).unwrap();
461        write(gen.join("out.rs"), "fn g() { foo().unwrap(); }\n").unwrap();
462        write(
463            dir.path().join("main.rs"),
464            "fn main() { foo().unwrap(); }\n",
465        )
466        .unwrap();
467        let mut cfg = Config::default();
468        cfg.scan.ignores = vec!["**/generated/**".to_string()];
469        let result = scan(&[dir.path().to_path_buf()], &[unwrap_rule()], &cfg).unwrap();
470        assert_eq!(result.stats.files_scanned, 1);
471        assert_eq!(result.findings.len(), 1);
472    }
473
474    #[test]
475    fn config_invalid_glob_is_an_error() {
476        let dir = tempdir().unwrap();
477        let mut cfg = Config::default();
478        cfg.scan.ignores = vec!["[".to_string()];
479        let err = scan(&[dir.path().to_path_buf()], &[unwrap_rule()], &cfg).unwrap_err();
480        assert!(matches!(err, ScanError::Glob(_)), "{err:?}");
481    }
482
483    #[test]
484    fn rule_without_kind_fails_to_compile() {
485        let dir = tempdir().unwrap();
486        let rule = parse_rule(
487            r#"
488id: no-kind
489language: rust
490severity: error
491category: correctness
492message: x
493rule:
494  regex: 'unwrap'
495"#,
496        )
497        .unwrap();
498        let err = scan(&[dir.path().to_path_buf()], &[rule], &Config::default()).unwrap_err();
499        assert!(
500            matches!(&err, ScanError::RuleCompile { id, .. } if *id == RuleId::from("no-kind")),
501            "{err:?}"
502        );
503    }
504
505    #[test]
506    fn stats_counting_accurate() {
507        let dir = tempdir().unwrap();
508        write(
509            dir.path().join("a.rs"),
510            "fn f() { foo().unwrap(); bar().unwrap(); }\n",
511        )
512        .unwrap();
513        let result = scan_dir(dir.path(), &[unwrap_rule()]);
514        assert_eq!(result.stats.errors, 2);
515        assert_eq!(result.stats.warnings, 0);
516        assert_eq!(result.stats.total, 2);
517        assert_eq!(result.stats.files_scanned, 1);
518    }
519
520    #[test]
521    fn scan_empty_file() {
522        let dir = tempdir().unwrap();
523        write(dir.path().join("empty.rs"), "").unwrap();
524        let result = scan_dir(dir.path(), &[unwrap_rule()]);
525        assert_eq!(result.findings.len(), 0);
526        assert_eq!(result.stats.files_scanned, 1);
527    }
528
529    #[test]
530    fn scan_complex_rule() {
531        let rule = parse_rule(
532            r#"
533id: dbg
534language: rust
535severity: error
536category: security
537message: debug on secret
538rule:
539  kind: attribute_item
540  all:
541    - regex: 'derive\([^)]*Debug'
542    - precedes:
543        kind: struct_item
544        has:
545          kind: field_identifier
546          regex: '^(api_key|password|secret)$'
547          stopBy: end
548"#,
549        )
550        .unwrap();
551        let dir = tempdir().unwrap();
552        write(
553            dir.path().join("t.rs"),
554            "#[derive(Debug)]\nstruct Config {\n    api_key: String,\n}\n",
555        )
556        .unwrap();
557        let result = scan_dir(dir.path(), &[rule]);
558        assert_eq!(result.findings.len(), 1);
559        assert_eq!(result.findings[0].rule_id, RuleId::from("dbg"));
560    }
561
562    #[test]
563    fn typescript_rule_applies_to_tsx_files() {
564        let rule = parse_rule(
565            r#"
566id: ts-any
567language: typescript
568severity: warning
569category: slop
570message: no any
571rule:
572  kind: predefined_type
573  regex: '^any$'
574"#,
575        )
576        .unwrap();
577        let dir = tempdir().unwrap();
578        write(dir.path().join("a.ts"), "let x: any = 1;\n").unwrap();
579        write(dir.path().join("b.tsx"), "let y: any = 2;\n").unwrap();
580        let result = scan_dir(dir.path(), &[rule]);
581        assert_eq!(result.stats.files_scanned, 2);
582        assert_eq!(result.stats.warnings, 2);
583    }
584
585    #[test]
586    fn scan_with_disable_comment_filters_findings() {
587        let dir = tempdir().unwrap();
588        write(
589            dir.path().join("main.rs"),
590            "fn main() {\n    // slopguard-disable-next-line\n    foo().unwrap();\n    bar().unwrap();\n}\n",
591        )
592        .unwrap();
593        let result = scan_dir(dir.path(), &[unwrap_rule()]);
594        assert_eq!(
595            result.findings.len(),
596            1,
597            "only the non-disabled unwrap should remain"
598        );
599        assert_eq!(result.findings[0].line, 4);
600    }
601
602    #[test]
603    fn scan_with_disable_rule_id_filters_only_that_rule() {
604        let dir = tempdir().unwrap();
605        write(
606            dir.path().join("main.rs"),
607            "fn main() {\n    // slopguard-disable-next-line test-unwrap\n    foo().unwrap();\n}\n",
608        )
609        .unwrap();
610        let result = scan_dir(dir.path(), &[unwrap_rule()]);
611        assert_eq!(result.findings.len(), 0);
612    }
613
614    fn unwrap_rule_skipping_test_code() -> Rule {
615        parse_rule(
616            r#"
617id: test-unwrap
618language: rust
619severity: error
620category: correctness
621message: ".unwrap() forbidden"
622rule:
623  kind: call_expression
624  regex: '\.unwrap\(\)\s*$'
625skip_test_code: true
626"#,
627        )
628        .unwrap()
629    }
630
631    #[test]
632    fn cfg_test_block_excluded_by_post_filter() {
633        let dir = tempdir().unwrap();
634        write(
635            dir.path().join("main.rs"),
636            "fn prod() {\n    foo().unwrap();\n}\n\n#[cfg(test)]\nmod tests {\n    fn test_it() {\n        bar().unwrap();\n    }\n}\n",
637        )
638        .unwrap();
639        let result = scan_dir(dir.path(), &[unwrap_rule_skipping_test_code()]);
640        assert_eq!(
641            result.findings.len(),
642            1,
643            "should only find the prod unwrap, not the one inside #[cfg(test)]"
644        );
645        assert_eq!(result.findings[0].line, 2);
646    }
647
648    #[test]
649    fn cfg_test_kept_without_skip_test_code() {
650        let dir = tempdir().unwrap();
651        write(
652            dir.path().join("main.rs"),
653            "fn prod() {\n    foo().unwrap();\n}\n\n#[cfg(test)]\nmod tests {\n    fn test_it() {\n        bar().unwrap();\n    }\n}\n",
654        )
655        .unwrap();
656        let result = scan_dir(dir.path(), &[unwrap_rule()]);
657        assert_eq!(
658            result.findings.len(),
659            2,
660            "rule without skip_test_code should find both"
661        );
662    }
663
664    #[test]
665    fn all_builtin_rules_compile() {
666        let rules = load_builtin_rules().unwrap();
667        assert!(
668            rules.len() >= 55,
669            "expected at least 55 rules, got {}",
670            rules.len()
671        );
672        let compiled = compile_rules(&rules).expect("all builtin rules should compile");
673        assert_eq!(compiled.by_id.len(), rules.len());
674    }
675
676    #[test]
677    fn scan_with_cache() {
678        let src_dir = tempdir().unwrap();
679        let cache_dir = tempdir().unwrap();
680        let cache_path = cache_dir.path().join("cache");
681        write(
682            src_dir.path().join("main.rs"),
683            "fn main() {\n    foo().unwrap();\n}\n",
684        )
685        .unwrap();
686
687        let rules = [unwrap_rule()];
688        let config = Config::default();
689
690        let result1 = scan_cached(
691            &[src_dir.path().to_path_buf()],
692            &rules,
693            &config,
694            &cache_path,
695        )
696        .unwrap();
697
698        assert_eq!(result1.findings.len(), 1);
699        let cache_stats1 = result1.cache_stats.as_ref().unwrap();
700        assert_eq!(cache_stats1.cached, 0, "first scan: nothing cached");
701        assert_eq!(cache_stats1.changed, 1, "first scan: one file scanned");
702
703        let result2 = scan_cached(
704            &[src_dir.path().to_path_buf()],
705            &rules,
706            &config,
707            &cache_path,
708        )
709        .unwrap();
710
711        assert_eq!(result2.findings.len(), 1);
712        let cache_stats2 = result2.cache_stats.as_ref().unwrap();
713        assert_eq!(cache_stats2.cached, 1, "second scan: one file from cache");
714        assert_eq!(cache_stats2.changed, 0, "second scan: nothing changed");
715    }
716}