MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / write_if_different

Function write_if_different

crates/test/src/lib.rs:1332–1346  ·  view source on GitHub ↗

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]>)

Source from the content-addressed store, hash-verified

1330/// Returns `true` if the file was written, or `false` if the file is the same
1331/// as it was already on disk.
1332fn 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
1348impl Component {
1349 /// Helper to convert `RuntimeTestConfig` to a `RuntimeTestConfig<T>` and

Callers 9

prepareMethod · 0.85
verifyMethod · 0.85
prepareFunction · 0.85
runtime_testMethod · 0.85
prepareMethod · 0.85
prepareMethod · 0.85
replace_bindings_go_modFunction · 0.85
compileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected