uh some optim from f4b3511

This commit is contained in:
lda
2025-09-28 13:34:38 +07:00 Unverified
parent 19385c4bca
commit e24598acf4
2 changed files with 13 additions and 4 deletions
+11 -2
View File
@@ -1,10 +1,19 @@
use std::collections::HashSet; use std::{collections::HashSet, fs};
pub fn get_dev() -> HashSet<String> { pub fn get_dev() -> HashSet<String> {
let mut devs: HashSet<String> = HashSet::new(); let mut devs: HashSet<String> = HashSet::new();
if let Ok(rd) = std::fs::read_dir("/sys/class/net") { if let Ok(rd) = std::fs::read_dir("/sys/class/net") {
for e in rd.flatten() { for e in rd.flatten() {
if let Ok(name) = e.file_name().into_string() if e.file_type()
.map(|ft| {
if ft.is_symlink() {
fs::metadata(e.path()).map(|m| m.is_dir()).unwrap_or(false)
} else {
ft.is_dir()
}
})
.unwrap_or(false)
&& let Ok(name) = e.file_name().into_string()
&& name != "lo" && name != "lo"
&& !name.is_empty() && !name.is_empty()
{ {
+2 -2
View File
@@ -58,12 +58,12 @@ pub async fn status_smart_redirect(q: String) -> DeviceQuery {
}; };
} }
// 5) Try DNS: if it resolves, treat as name // 5) Try DNS: if it resolves, treat as name
if tokio::net::lookup_host((s, 0)).await.is_ok() { /* if tokio::net::lookup_host((s, 0)).await.is_ok() {
return DeviceQuery { return DeviceQuery {
name: Some(s.to_string()), name: Some(s.to_string()),
..Default::default() ..Default::default()
}; };
} } */
// Default: name last // it will fail also // Default: name last // it will fail also
DeviceQuery { DeviceQuery {
name: Some(s.to_string()), name: Some(s.to_string()),