Returns `true` if the file was written, or `false` if the file is the same as it was already on disk.
(path: &Path, contents: impl AsRef<[u8]>)
| 1330 | /// Returns `true` if the file was written, or `false` if the file is the same |
| 1331 | /// as it was already on disk. |
| 1332 | fn write_if_different(path: &Path, contents: impl AsRef<[u8]>) -> Result<bool> { |
| 1333 | let contents = contents.as_ref(); |
| 1334 | if let Ok(prev) = fs::read(path) { |
| 1335 | if prev == contents { |
| 1336 | return Ok(false); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | if let Some(parent) = path.parent() { |
| 1341 | fs::create_dir_all(parent) |
| 1342 | .with_context(|| format!("failed to create directory {parent:?}"))?; |
| 1343 | } |
| 1344 | fs::write(path, contents).with_context(|| format!("failed to write {path:?}"))?; |
| 1345 | Ok(true) |
| 1346 | } |
| 1347 | |
| 1348 | impl Component { |
| 1349 | /// Helper to convert `RuntimeTestConfig` to a `RuntimeTestConfig<T>` and |
no outgoing calls
no test coverage detected