(id_filters: Option<Vec<String>>)
| 1171 | } |
| 1172 | |
| 1173 | pub fn peers(id_filters: Option<Vec<String>>) -> Vec<(String, SystemTime, PeerConfig)> { |
| 1174 | if let Ok(peers) = Config::path(PEERS).read_dir() { |
| 1175 | if let Ok(peers) = peers |
| 1176 | .map(|res| res.map(|e| e.path())) |
| 1177 | .collect::<Result<Vec<_>, _>>() |
| 1178 | { |
| 1179 | let mut peers: Vec<_> = peers |
| 1180 | .iter() |
| 1181 | .filter(|p| { |
| 1182 | p.is_file() |
| 1183 | && p.extension().map(|p| p.to_str().unwrap_or("")) == Some("toml") |
| 1184 | }) |
| 1185 | .map(|p| { |
| 1186 | let id = p |
| 1187 | .file_stem() |
| 1188 | .map(|p| p.to_str().unwrap_or("")) |
| 1189 | .unwrap_or("") |
| 1190 | .to_owned(); |
| 1191 | |
| 1192 | let id_decoded_string = if id.starts_with("base64_") && id.len() != 7 { |
| 1193 | let id_decoded = base64::decode(&id[7..], base64::Variant::Original) |
| 1194 | .unwrap_or_default(); |
| 1195 | String::from_utf8_lossy(&id_decoded).as_ref().to_owned() |
| 1196 | } else { |
| 1197 | id |
| 1198 | }; |
| 1199 | (id_decoded_string, p) |
| 1200 | }) |
| 1201 | .filter(|(id, _)| { |
| 1202 | let Some(filters) = &id_filters else { |
| 1203 | return true; |
| 1204 | }; |
| 1205 | filters.contains(id) |
| 1206 | }) |
| 1207 | .map(|(id, p)| { |
| 1208 | let t = crate::get_modified_time(p); |
| 1209 | let c = PeerConfig::load(&id); |
| 1210 | if c.info.platform.is_empty() { |
| 1211 | fs::remove_file(p).ok(); |
| 1212 | } |
| 1213 | (id, t, c) |
| 1214 | }) |
| 1215 | .filter(|p| !p.2.info.platform.is_empty()) |
| 1216 | .collect(); |
| 1217 | peers.sort_unstable_by(|a, b| b.1.cmp(&a.1)); |
| 1218 | return peers; |
| 1219 | } |
| 1220 | } |
| 1221 | Default::default() |
| 1222 | } |
| 1223 | |
| 1224 | pub fn exists(id: &str) -> bool { |
| 1225 | Self::path(id).exists() |
nothing calls this directly
no test coverage detected