MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / write_metadata

Function write_metadata

rust/src/metadata.rs:257–277  ·  view source on GitHub ↗
(metadata: &Metadata, log: &Logger, cache_path: Option<PathBuf>)

Source from the content-addressed store, hash-verified

255}
256
257pub fn write_metadata(metadata: &Metadata, log: &Logger, cache_path: Option<PathBuf>) {
258 if let Some(cache) = cache_path {
259 let metadata_path = get_metadata_path(cache.clone());
260 log.trace(format!("Writing metadata to {}", metadata_path.display()));
261 // Several Selenium Manager processes may share one cache (e.g. parallel test
262 // workers), and writing the file in place lets them read it truncated or half
263 // written. Renaming a complete sibling file into place is atomic, so readers see
264 // either the previous or the new content.
265 let tmp_path = metadata_path.with_extension(format!("json.{}.tmp", std::process::id()));
266 fs::write(&tmp_path, serde_json::to_string_pretty(metadata).unwrap())
267 .and_then(|_| fs::rename(&tmp_path, &metadata_path))
268 .unwrap_or_else(|err| {
269 fs::remove_file(&tmp_path).ok();
270 log.warn(format!(
271 "Metadata cannot be written in cache ({}): {}",
272 cache.display(),
273 err
274 ));
275 });
276 }
277}
278
279pub fn clear_metadata(log: &Logger, path: &str) {
280 let cache_path = Path::new(path).to_path_buf();

Calls 6

get_metadata_pathFunction · 0.85
writeFunction · 0.85
remove_fileFunction · 0.85
traceMethod · 0.80
okMethod · 0.80
warnMethod · 0.45