cleanup: remove dead code and duplicate docs
- Remove session-ses_2f27.md (161KB raw session log) - Remove 49 ROOT_* duplicate files across REFERENCE/ - Remove 14 duplicate files between REFERENCE/ root and history/ - Remove asr_legacy.rs (dead code, replaced by asr.rs) - Remove src/core/worker/ (duplicate JobWorker) - Remove src/core/layers/ (empty directory) - Remove 4 .bak files in src/ - Remove 7 dead private methods in worker/processor.rs - Remove backup directory from git tracking
This commit is contained in:
@@ -54,22 +54,81 @@ pub fn compute_uuid_from_relative_path(relative_path: &str) -> String {
|
||||
compute_uuid(&username, &filepath)
|
||||
}
|
||||
|
||||
/// Get MAC address of primary network interface
|
||||
/// 取得本機內建網路介面的 MAC 位址(不可拆、非外接)。
|
||||
/// 優先順序:en0 (Wi-Fi) > en1 > 其他非 USB/Thunderbolt 介面。
|
||||
/// 若都找不到則回傳 fallback。
|
||||
/// Returns MAC address in format: a1:b2:c3:d4:e5:f6
|
||||
pub fn get_mac_address() -> String {
|
||||
use mac_address::get_mac_address;
|
||||
// 使用 ifconfig 列出所有介面
|
||||
let output = std::process::Command::new("ifconfig")
|
||||
.args(["-a"])
|
||||
.output()
|
||||
.ok()
|
||||
.and_then(|o| {
|
||||
if o.status.success() {
|
||||
Some(String::from_utf8_lossy(&o.stdout).to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
match get_mac_address() {
|
||||
Ok(Some(mac)) => {
|
||||
let bytes = mac.bytes();
|
||||
format!(
|
||||
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
|
||||
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5]
|
||||
)
|
||||
// 解析 ifconfig,找到介面名稱與 MAC
|
||||
let mut current_iface = String::new();
|
||||
let mut candidates: Vec<(u32, String)> = Vec::new();
|
||||
|
||||
for line in output.lines() {
|
||||
let trimmed = line.trim();
|
||||
// 介面名稱行,如 "en0: flags=..."
|
||||
if !trimmed.starts_with('\t') && trimmed.contains(": flags=") {
|
||||
current_iface = trimmed.split(':').next().unwrap_or("").to_string();
|
||||
}
|
||||
|
||||
// macOS: "ether a1:b2:c3:d4:e5:f6"
|
||||
if let Some(mac_str) = trimmed.strip_prefix("ether ") {
|
||||
let mac = mac_str.trim();
|
||||
if mac.len() == 17 && mac.chars().filter(|&c| c == ':').count() == 5 {
|
||||
if mac == "00:00:00:00:00:00" || mac == "ff:ff:ff:ff:ff:ff" {
|
||||
continue;
|
||||
}
|
||||
// 優先級:en0=0, en1=1, en2=2, 其他=100
|
||||
let priority = match current_iface.as_str() {
|
||||
"en0" => 0,
|
||||
"en1" => 1,
|
||||
"en2" => 2,
|
||||
_ if current_iface.starts_with("en") => 3,
|
||||
_ => 100,
|
||||
};
|
||||
candidates.push((priority, mac.to_string()));
|
||||
}
|
||||
}
|
||||
// macOS: "lladdr a1:b2:c3:d4:e5:f6"
|
||||
if let Some(mac_str) = trimmed.strip_prefix("lladdr ") {
|
||||
let mac = mac_str.trim();
|
||||
if mac.len() == 17 && mac.chars().filter(|&c| c == ':').count() == 5 {
|
||||
if mac == "00:00:00:00:00:00" || mac == "ff:ff:ff:ff:ff:ff" {
|
||||
continue;
|
||||
}
|
||||
let priority = match current_iface.as_str() {
|
||||
"en0" => 0,
|
||||
"en1" => 1,
|
||||
"en2" => 2,
|
||||
_ if current_iface.starts_with("en") => 3,
|
||||
_ => 100,
|
||||
};
|
||||
candidates.push((priority, mac.to_string()));
|
||||
}
|
||||
}
|
||||
Ok(None) => "00:00:00:00:00:00".to_string(),
|
||||
Err(_) => "00:00:00:00:00:00".to_string(),
|
||||
}
|
||||
|
||||
// 按優先級排序(en0 > en1 > en2 > 其他)
|
||||
candidates.sort_by_key(|k| k.0);
|
||||
if let Some(mac) = candidates.first().map(|c| c.1.clone()) {
|
||||
return mac;
|
||||
}
|
||||
|
||||
// fallback
|
||||
"00:00:00:00:00:00".to_string()
|
||||
}
|
||||
|
||||
/// Compute Birth UUID (Stable Identity with Location)
|
||||
|
||||
Reference in New Issue
Block a user