1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0
//! Walk limits and file filters shared by `ctx_search` and the search index,
//! so both see the same searchable universe. Moved down from
//! `tools/ctx_search/implementation.rs`.
use std::path::Path;
/// Size cap for a file met during a directory walk.
pub const MAX_FILE_SIZE: u64 = 512_000;
/// Maximum directory depth of a search walk.
pub const MAX_WALK_DEPTH: usize = 20;
pub fn is_binary_ext(path: &Path) -> bool {
let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("");
matches!(
ext,
"png"
| "jpg"
| "jpeg"
| "gif"
| "webp"
| "ico"
| "svg"
| "woff"
| "woff2"
| "ttf"
| "eot"
| "pdf"
| "zip"
| "tar"
| "gz"
| "br"
| "zst"
| "bz2"
| "xz"
| "mp3"
| "mp4"
| "webm"
| "ogg"
| "wasm"
| "so"
| "dylib"
| "dll"
| "exe"
| "lock"
| "map"
| "snap"
| "patch"
| "db"
| "sqlite"
| "parquet"
| "arrow"
| "bin"
| "o"
| "a"
| "class"
| "pyc"
| "pyo"
)
}
pub fn is_generated_file(path: &Path) -> bool {
let name = path.file_name().and_then(|n| n.to_str()).unwrap_or("");
name.ends_with(".min.js")
|| name.ends_with(".min.css")
|| name.ends_with(".bundle.js")
|| name.ends_with(".chunk.js")
|| name.ends_with(".d.ts")
|| name.ends_with(".js.map")
|| name.ends_with(".css.map")
}