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

Function get_metadata

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

Source from the content-addressed store, hash-verified

94}
95
96pub fn get_metadata(log: &Logger, cache_path: &Option<PathBuf>) -> Metadata {
97 if let Some(cache) = cache_path {
98 let metadata_path = get_metadata_path(cache.clone());
99 log.trace(format!("Reading metadata from {}", metadata_path.display()));
100
101 if metadata_path.exists() {
102 // The metadata file is only a cache of TTL'd version lookups, so any failure to
103 // read it costs one round of re-discovery. Degrade to an empty cache instead of
104 // stopping Selenium Manager.
105 let metadata_file = match File::open(&metadata_path) {
106 Ok(file) => file,
107 Err(err) => {
108 log.warn(format!(
109 "Metadata file {} cannot be opened: {err}. Using empty metadata",
110 metadata_path.display()
111 ));
112 return new_metadata(log);
113 }
114 };
115 let metadata: Metadata = match serde_json::from_reader(&metadata_file) {
116 Ok::<Metadata, serde_json::Error>(mut meta) => {
117 let now = now_unix_timestamp();
118 meta.browsers.retain(|b| b.browser_ttl > now);
119 meta.drivers.retain(|d| d.driver_ttl > now);
120 meta.stats.retain(|s| s.stats_ttl > now);
121 meta
122 }
123 Err(err) => {
124 log.warn(format!(
125 "Metadata file {} cannot be parsed: {err}. Using empty metadata",
126 metadata_path.display()
127 ));
128 new_metadata(log)
129 }
130 };
131 return metadata;
132 }
133 }
134 new_metadata(log) // Empty metadata
135}
136
137pub fn get_browser_version_from_metadata(
138 browsers_metadata: &[Browser],

Calls 6

get_metadata_pathFunction · 0.85
new_metadataFunction · 0.85
now_unix_timestampFunction · 0.85
traceMethod · 0.80
existsMethod · 0.80
warnMethod · 0.45