|
| 1 | +#[allow(clippy::disallowed_types)] |
| 2 | +use std::fs::{File, FileTimes}; |
| 3 | +use std::io::Write; |
1 | 4 | use std::path::PathBuf; |
2 | 5 | use std::{env, fs}; |
3 | 6 |
|
@@ -36,16 +39,37 @@ fn main() { |
36 | 39 |
|
37 | 40 | let json_data: serde_json::Value = serde_json::from_str( |
38 | 41 | #[allow(clippy::disallowed_methods)] |
39 | | - &fs::read_to_string(version_metadata).expect("Failed to read download-metadata.json"), |
| 42 | + &fs::read_to_string(&version_metadata).expect("Failed to read download-metadata.json"), |
40 | 43 | ) |
41 | 44 | .expect("Failed to parse JSON"); |
42 | 45 |
|
43 | 46 | let filtered_data = process_json(&json_data); |
44 | 47 |
|
| 48 | + #[allow(clippy::disallowed_types)] |
| 49 | + let mut out_file = File::create(version_metadata_minified) |
| 50 | + .expect("failed to open download-metadata-minified.json"); |
| 51 | + |
45 | 52 | #[allow(clippy::disallowed_methods)] |
46 | | - fs::write( |
47 | | - version_metadata_minified, |
48 | | - serde_json::to_string(&filtered_data).expect("Failed to serialize JSON"), |
49 | | - ) |
50 | | - .expect("Failed to write minified JSON"); |
| 53 | + out_file |
| 54 | + .write_all( |
| 55 | + serde_json::to_string(&filtered_data) |
| 56 | + .expect("Failed to serialize JSON") |
| 57 | + .as_bytes(), |
| 58 | + ) |
| 59 | + .expect("Failed to write minified JSON"); |
| 60 | + |
| 61 | + // Cargo uses the modified times of the paths specified in |
| 62 | + // `rerun-if-changed`, so fetch the current file times and set them the same |
| 63 | + // on the output file. |
| 64 | + #[allow(clippy::disallowed_methods)] |
| 65 | + let meta = |
| 66 | + fs::metadata(version_metadata).expect("failed to read metadata for download-metadata.json"); |
| 67 | + |
| 68 | + out_file |
| 69 | + .set_times( |
| 70 | + FileTimes::new() |
| 71 | + .set_accessed(meta.accessed().unwrap()) |
| 72 | + .set_modified(meta.modified().unwrap()), |
| 73 | + ) |
| 74 | + .expect("failed to write file times to download-metadata-minified.json"); |
51 | 75 | } |
0 commit comments