Skip to content

Commit 65323d0

Browse files
committed
ignore binary extensions, but not folders
We generate a glob to ignore binary extensions that looks like this: ``` *.{mp4,pages,exe,…} ``` However, if you have a folder that happens to end in `.pages` for example, then this folder will be ignored in its entirety. To solve this, we will instead generate the following globs: ``` *.{mp4,pages,exe,…} !*.{mp4,pages,exe,…}/ ``` This way, the `/` indicates that we are dealing with a folder and that these should _not_ be ignored.
1 parent 72ef4b7 commit 65323d0

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

crates/oxide/src/scanner/auto_source_detection.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ pub static RULES: sync::LazyLock<Gitignore> = sync::LazyLock::new(|| {
1515

1616
builder.add_line(None, &IGNORED_CONTENT_DIRS_GLOB).unwrap();
1717
builder.add_line(None, &IGNORED_EXTENSIONS_GLOB).unwrap();
18-
builder.add_line(None, &BINARY_EXTENSIONS_GLOB).unwrap();
18+
for glob in BINARY_EXTENSIONS_GLOB.clone() {
19+
builder.add_line(None, &glob).unwrap();
20+
}
1921
builder.add_line(None, &IGNORED_FILES_GLOB).unwrap();
2022

2123
builder.build().unwrap()
@@ -42,15 +44,27 @@ static IGNORED_EXTENSIONS_GLOB: sync::LazyLock<String> = sync::LazyLock::new(||
4244
)
4345
});
4446

45-
pub static BINARY_EXTENSIONS_GLOB: sync::LazyLock<String> = sync::LazyLock::new(|| {
46-
format!(
47-
"*.{{{}}}",
48-
include_str!("fixtures/binary-extensions.txt")
49-
.trim()
50-
.lines()
51-
.collect::<Vec<&str>>()
52-
.join(",")
53-
)
47+
pub static BINARY_EXTENSIONS_GLOB: sync::LazyLock<Vec<String>> = sync::LazyLock::new(|| {
48+
vec![
49+
// Ignore the extensions
50+
format!(
51+
"*.{{{}}}",
52+
include_str!("fixtures/binary-extensions.txt")
53+
.trim()
54+
.lines()
55+
.collect::<Vec<&str>>()
56+
.join(","),
57+
),
58+
// Do not ignore folders that happen to end with a binary extension
59+
format!(
60+
"!*.{{{}}}/",
61+
include_str!("fixtures/binary-extensions.txt")
62+
.trim()
63+
.lines()
64+
.collect::<Vec<&str>>()
65+
.join(","),
66+
),
67+
]
5468
});
5569

5670
static IGNORED_FILES_GLOB: sync::LazyLock<String> = sync::LazyLock::new(|| {

crates/oxide/src/scanner/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,9 @@ fn create_walker(sources: Sources) -> Option<WalkBuilder> {
564564
.insert(format!("!{}", "/**/*"));
565565

566566
// External sources should still disallow binary extensions:
567-
ignores
568-
.entry(base)
569-
.or_default()
570-
.insert(BINARY_EXTENSIONS_GLOB.clone());
567+
for glob in BINARY_EXTENSIONS_GLOB.clone() {
568+
ignores.entry(base).or_default().insert(glob);
569+
}
571570
}
572571
}
573572
}

0 commit comments

Comments
 (0)