Skip to content

Commit 8f6f7a5

Browse files
committed
bugfix: generated js and css filenames were incorrect
The resource hashes were computed before closing the resource files themselves, creating invalid hashes That, in turn, caused incorrect file caching, and prevented resource updates in browsers
1 parent 28cbb70 commit 8f6f7a5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

build.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ fn inline_dependencies(path_in: &str, path_out: &Path) {
2121
// the URL in the generated file.
2222
println!("cargo:rerun-if-changed={}", path_in);
2323
let original = File::open(path_in).unwrap();
24+
process_input_file(path_out, original);
25+
std::fs::write(
26+
format!("{}.filename.txt", path_out.display()),
27+
hashed_filename(path_out),
28+
)
29+
.unwrap();
30+
}
31+
32+
fn process_input_file(path_out: &Path, original: File) {
2433
let mut outfile = BufWriter::new(File::create(path_out).unwrap());
2534
for l in BufReader::new(original).lines() {
2635
let line = l.unwrap();
@@ -36,19 +45,17 @@ fn inline_dependencies(path_in: &str, path_out: &Path) {
3645
writeln!(outfile, "{}", line).unwrap();
3746
}
3847
}
39-
std::fs::write(
40-
format!("{}.filename.txt", path_out.display()),
41-
hashed_filename(path_out),
42-
)
43-
.unwrap();
4448
}
4549

4650
// Given a filename, creates a new unique filename based on the file contents
4751
fn hashed_filename(path: &Path) -> String {
4852
let mut file = File::open(path).unwrap();
4953
let mut buf = [0u8; 4096];
5054
let mut hasher = DefaultHasher::new();
51-
while let Ok(bytes_read) = file.read(&mut buf) {
55+
loop {
56+
let bytes_read = file
57+
.read(&mut buf)
58+
.expect(&format!("error reading {}", path.display()));
5259
if bytes_read == 0 {
5360
break;
5461
}

0 commit comments

Comments
 (0)