Skip to content

Commit ada6c10

Browse files
committed
Whitelist files in build.rs
build.rs would add every file in frontend/dist to asset.in. This would cause hard to debug errors when files were unintentionally placed in frontend/dist. Fixes steveklabnik#58
1 parent ad68c79 commit ada6c10

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

Cargo.lock

Lines changed: 7 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ serde_json = "1.0.2"
2626
error-chain = "=0.11.0-rc.2"
2727
quote = "0.3"
2828
syn = "0.11"
29-
walkdir = "1.0.7"
29+
glob = "0.2.11"
3030

3131
[dev-dependencies]
3232
error-chain = "=0.11.0-rc.2"

build.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate error_chain;
55
#[macro_use]
66
extern crate quote;
77
extern crate syn;
8-
extern crate walkdir;
8+
extern crate glob;
99

1010
use std::env;
1111
use std::fmt;
@@ -17,12 +17,13 @@ use std::process::exit;
1717
use std::thread;
1818

1919
use quote::Ident;
20-
use walkdir::WalkDir;
20+
use glob::glob;
2121

2222
error_chain! {
2323
foreign_links {
2424
Io(::std::io::Error);
25-
WalkDir(::walkdir::Error);
25+
PatternError(::glob::PatternError);
26+
GlobError(::glob::GlobError);
2627
}
2728
}
2829

@@ -65,14 +66,23 @@ fn main() {
6566
/// Start the recursion from the top level of the frontend's dist folder
6667
fn acquire_assets() -> Result<Vec<Asset>> {
6768
let mut output: Vec<Asset> = Vec::new();
68-
69-
for entry in WalkDir::new(DIST).into_iter() {
70-
let entry = entry?;
71-
if entry.metadata()?.is_file() {
72-
output.push(Asset {
73-
// If the directory isn't valid this wouldn't have worked.
74-
path: String::from(entry.path().to_str().unwrap()).replace("\\", "/"),
75-
});
69+
let whitelist = vec![
70+
"assets/**",
71+
"crossdomain.xml",
72+
"ember-fetch/**",
73+
"index.html",
74+
"robots.txt",
75+
];
76+
77+
for w in whitelist {
78+
for entry in glob(&format!("{}{}", DIST, w))? {
79+
let path = entry?;
80+
if path.is_file() {
81+
output.push(Asset {
82+
// If the directory isn't valid this wouldn't have worked.
83+
path: String::from(path.to_str().unwrap()).replace("\\", "/"),
84+
});
85+
}
7686
}
7787
}
7888

0 commit comments

Comments
 (0)